Advertisement
Guest User

Untitled

a guest
Aug 17th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.18 KB | None | 0 0
  1. #!/bin/bash
  2. # config
  3. poll=300
  4. video_id=`echo "${1}" | grep -o ".\{11\}$"`
  5. format='bestvideo[ext=webm]+bestaudio[ext=webm]'
  6. cookies=/path/to/cookies.txt
  7. cookies_chat=/path/to/cookies_chat.txt
  8. chat_venv=/path/to/chat-downloader/venv
  9.  
  10. echo "`date`: Downloading ${video_id}."
  11.  
  12. # wait for opus encoding
  13. echo "`date`: Polling for Opus encoding (${poll} seconds)."
  14. until youtube-dl -F --cookies "$cookies" "$1" | grep opus > /dev/null 2>&1 ; do
  15.   echo "`date`: Waiting..."
  16.   sleep $poll
  17. done
  18.  
  19. # wait for VP9 encoding
  20. echo "`date`: Polling for VP9 encoding (${poll} seconds)."
  21. until youtube-dl -F --cookies "$cookies" "$1" | grep vp9 > /dev/null 2>&1 ; do
  22.   echo "`date`: Waiting..."
  23.   sleep $poll
  24. done
  25.  
  26. # chat_downloader job
  27. {
  28.   echo "`date`: Starting chat log download."
  29.   source $chat_venv/bin/activate
  30.   chat_downloader --cookies "$cookies_chat" --message_type all --chat_type live "https://youtube.com/watch?v=${video_id}" > "${video_id}".log &&
  31.   echo "`date`: Chat log download completed: `wc -l ${video_id}.log`"
  32. } &
  33.  
  34. # youtube-dl job
  35. {
  36.   echo "`date`: Starting video and metadata download."
  37.   youtube-dl --cookies "$cookies" --write-thumbnail --write-description -f "${format}" "$1" || {
  38.     echo "`date`: Video download failed."
  39.     exit 1
  40.   }
  41.   echo "`date`: Video and metadata download ended."
  42. } &
  43.  
  44. # wait for background jobs to finish
  45. wait
  46.  
  47. # cleanup
  48. echo "`date`: Cleaning up."
  49. base_filename=`echo *"${video_id}.description" | sed -e 's/\.description$//'`
  50. mv "${video_id}.log" "${base_filename}.log"
  51. [ -f "${base_filename}.jpg" ] || {
  52.   echo "`date`: Missing JPEG thumbnail. Downloading maxresdefault.jpg."
  53.   wget -O "${base_filename}.jpg" https://i.ytimg.com/vi/${video_id}/maxresdefault.jpg
  54. }
  55. [ -s "${base_filename}.log" ] || {
  56.   echo "`date`: Chat log is empty. Deleting it."
  57.   rm "${base_filename}.log"
  58. }
  59. echo "`date`: Updating file timestamps."
  60. touch -cr "${base_filename}".webm "${base_filename}".{log,description,jpg,webp} 2>/dev/null
  61. echo "`date`: Archive completed."
  62.  
  63. # print validation info
  64. ls -lh "${base_filename}".*
  65. [ -f "${base_filename}.log" ] && {
  66.   tail -n 5 "${base_filename}".log
  67. }
  68. ffprobe -i "${base_filename}".webm 2>&1 |grep Duration:
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement