Named after the Library of Babel website. This started as an experiment in randomness but now hosts a bunch of experimental programs. I got help from chatGPT, Claude AI, and whatever Google calls its AI these days to write some of them.
- Setup
- Run
- Other programs
- Wordplay
- Games
- YouTube downloaders
- Twitter/x.com videos
- Instagram stories
- Kick
- More
For initial setup, create a virtual environment & run it:
python -m venv venv
. venv/bin/activate
Then install requirements:
pip install -r requirements.txt
After the initial setup & requirements, you only have to run the second venv line to activate the virtual environment when running in the future.
If necessary you may need to upgrade yt-dlp
.
Check version.
yt-dlp --version
Install upgrade.
pip install yt-dlp --upgrade
Or
pip install -U yt-dlp
To run experiments, type python
and the file name. For example, try this one:
cd ytdownload
python youtube_downloader.py
business_assumptions.py
- calculate breakeven cost and amount of drivers needed for a hypothetical future business idea.gnews_scraper.py
- Scrape the latest 5 Google News headlines based onh4
top stories.lat_long.py
- find latitude & longitude.moviesearch.py
- prints number of movies released in a range of years.news_scraper.py
- BBC and NY Times headline scraper. Adapted Indently's BBC News Headline scraper to scrape BBC news and New York Times headlines.repeated_multiplication.py
- repeatedly multiply numbers.retirement_calc.py
- calculate retirement.wiki_articles.py
- Display the 10 most recently-updated articles.write_key.py
- asks for a key and value and adds it to a dictionary. If the dictionary doesn't exist, creates it.
count_letters.py
- Count letters in a word.define_word.py
- Define a word.entername.py
- Enter your name and get greeted with the current time.gen_pass.py
- Generate passphrase. Uses thehttps://random-word-api.herokuapp.com/word
API endpoint to generate a passphrase.gensen_worddict.py
- Expandedrandom_sentence.py
. Pulls random words from thehttps://random-word-api.herokuapp.com/word
API endpoint and strings them together to create a sentence, then verifies the sentence against thelanguage_tool_python
API.givename.py
- Runsentername.py
and passes in a hardcoded name.random_phrase.py
- (Buggy) Generate random phrase.random_sentence_save.py
- Same asrandom_sentence.py
except saves to file.word_or_phrase.py
- Asks if you want to generate a random phrase or define a word.
dice_game.py
- experimental treasure hunt game.dice_roll_anysided
- Roll a die with the number of sides specified by the user.dice_rolls.py
- Rolls 2 6-sided dice.die_roll_games.py
- 3 games- Choose the number of sides for the die and roll it.
- Add to game 1 & see how many rolls it takes to roll the number again.
- Play game 2 a number of times.
die_roll_probability.py
- guess how many rolls it will take for game 2 (work in progress)die-roll-histogram
- roll a die and generate a histogram of the values.squid_game.py
- red light green light sim.
ytdownload/analyze_chat.py
- Analyze a youtube live chat CSV output byyoutube_downloader.py
.ytdownload/extract_functions.py
- Extract functions used byyoutube_downloader.py
.ytdownload/youtube_downloader.py
- Updated downloader using classes to download video, description, transcript, comments, and live chat and convert comments & live chat to CSV.
These use the yt_dlp
YoutubeDL
Python class or embedded CLI to download videos. You may want to install ffmpeg
to handle some video conversion. Easiest way on macOS is through homebrew: brew install ffmpeg
.
https://superuser.com/questions/1409426/how-to-pass-input-to-a-script-from-terminal
The following will start the program and begin downloading the VIDEO_ID
provided in the link.
printf '%s\n' "https://www.youtube.com/watch?v=VIDEO_ID" | python youtube_downloader.py
To save live video and chat:
-
Copy the VIDEO_ID, which is the final segment in a YouTube URL, for example,
ABC123
inhttps://www.youtube.com/watch?v=ABC123
. -
Run the following to download the live chat:
python youtube-live-chat-fetcher.py
-
Enter the VIDEO_ID in the input field.
-
Copy the code to download the live video from the start and run it in a new terminal:
yt-dlp --live-from-start -- VIDEO_ID
If you get the error:
ERROR: [youtube] URL: Sign in to confirm you’re not a bot. Use --cookies-from-browser or --cookies for the authentication. See https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp for how to manually pass cookies. Also see https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies for tips on effectively exporting YouTube cookies
Sign in with firefox then try:
yt-dlp --cookies-from-browser firefox --live-from-start -- URL
To download using a guest token, use yt-dlp X_URL
.
If you get the error "file name too long", use the following:
yt-dlp -o "%(id)s.%(ext)s" X_URL
See more here, here, and here.
See Using yt-dlp cookies if you need to log in to download
Use yt-dlp --cookies-from-browser firefox URL
.
See yt-dlp/yt-dlp#8290 (comment).
how-to-download-your-kick-replays
- Open your browser and press F12
- Click the "Network" tab
- Load the replay in your browser
- In the network tab, search for m3u8
- Right Click the file master.m3u8 and select Copy URL
- Open your command line / terminal
- If on Windows, go to the directory where the yt-dlp file has been installed
- Run the following Command:
yt-dlp <kick_replay_url>
Merge downloaded fragments with ffmpeg’s concat demuxer.
- Create a file named filelist.txt with the files listed in order.
file 'filename.f137.mp4.part'
file 'filename.f140.mp4.part'
- Run the ffmpeg command to merge them:
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4
This will merge the fragments into output.mp4.
# other options
ydl_opts = {
'listformats': True, # list available formats
}
ydl_opts = {
'format' : '00' # enter format ID
'merge_output_format': 'mp4', # Ensure the final output is in mp4 format
}
ydl_opts = {
'format': 'bestvideo[height<=720]+bestaudio/best[height<=720]', # download up to 720p video
'merge_output_format': 'mp4', # Ensure the final output is in mp4 format
}
List formats
yt-dlp -F "https://www.youtube.com/watch?v=VIDEO_ID"
Download best video and audio at the highest resolution
yt-dlp -f "bestvideo+bestaudio/best" "https://www.youtube.com/watch?v=VIDEO_ID"
ytdownload/youtube-live-chat-fetcher.py
- Fetch live chat during a live stream. Requires API key.- Sign up to develop with the Google Cloud Platform, create a project, and activate the YouTube Data API v3.
- Create an
.env
file withYOUTUBE_API_KEY=yourapikey
andMAPS_API_KEY=yourmapsapikey
.
See Programming notes.