Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # config
- poll=300
- video_id=`echo "${1}" | grep -o ".\{11\}$"`
- format='bestvideo[ext=webm]+bestaudio[ext=webm]'
- cookies=/path/to/cookies.txt
- cookies_chat=/path/to/cookies_chat.txt
- chat_venv=/path/to/chat-downloader/venv
- echo "`date`: Downloading ${video_id}."
- # wait for opus encoding
- echo "`date`: Polling for Opus encoding (${poll} seconds)."
- until youtube-dl -F --cookies "$cookies" "$1" | grep opus > /dev/null 2>&1 ; do
- echo "`date`: Waiting..."
- sleep $poll
- done
- # wait for VP9 encoding
- echo "`date`: Polling for VP9 encoding (${poll} seconds)."
- until youtube-dl -F --cookies "$cookies" "$1" | grep vp9 > /dev/null 2>&1 ; do
- echo "`date`: Waiting..."
- sleep $poll
- done
- # chat_downloader job
- {
- echo "`date`: Starting chat log download."
- source $chat_venv/bin/activate
- chat_downloader --cookies "$cookies_chat" --message_type all --chat_type live "https://youtube.com/watch?v=${video_id}" > "${video_id}".log &&
- echo "`date`: Chat log download completed: `wc -l ${video_id}.log`"
- } &
- # youtube-dl job
- {
- echo "`date`: Starting video and metadata download."
- youtube-dl --cookies "$cookies" --write-thumbnail --write-description -f "${format}" "$1" || {
- echo "`date`: Video download failed."
- exit 1
- }
- echo "`date`: Video and metadata download ended."
- } &
- # wait for background jobs to finish
- wait
- # cleanup
- echo "`date`: Cleaning up."
- base_filename=`echo *"${video_id}.description" | sed -e 's/\.description$//'`
- mv "${video_id}.log" "${base_filename}.log"
- [ -f "${base_filename}.jpg" ] || {
- echo "`date`: Missing JPEG thumbnail. Downloading maxresdefault.jpg."
- wget -O "${base_filename}.jpg" https://i.ytimg.com/vi/${video_id}/maxresdefault.jpg
- }
- [ -s "${base_filename}.log" ] || {
- echo "`date`: Chat log is empty. Deleting it."
- rm "${base_filename}.log"
- }
- echo "`date`: Updating file timestamps."
- touch -cr "${base_filename}".webm "${base_filename}".{log,description,jpg,webp} 2>/dev/null
- echo "`date`: Archive completed."
- # print validation info
- ls -lh "${base_filename}".*
- [ -f "${base_filename}.log" ] && {
- tail -n 5 "${base_filename}".log
- }
- ffprobe -i "${base_filename}".webm 2>&1 |grep Duration:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement