Git Product home page Git Product logo

Comments (2)

bardisty avatar bardisty commented on July 30, 2024 2

If you need rclone to upload the files to a remote but you also want to keep them locally, you can change the rclone_command option from move to copy.

If you don't need rclone at all and just want to download videos, you can use youtube-dl to get the same functionality this script provides. Something like this:

1. Create a directory to store the required files and downloaded videos (you can save videos elsewhere if you want, just modify the --output flag in the config example below):

mkdir ~/youtube

2. Start a shell or bash instance for steps 3 and 4:

sh

3. Create a youtube-dl configuration file (~/youtube/config.conf) by pasting the following in your terminal:

cat > ~/youtube/config.conf << "EOF"
# File containing URLs to download, one URL per line. Lines starting with
# '#' or ';' or ']' are considered as comments and ignored.
--batch-file "~/youtube/urls.txt"

# Force resume of partially downloaded files. By default, youtube-dl will
# resume downloads if possible.
--continue

# Download only videos not listed in the archive file. Record the IDs of
# all downloaded videos in it.
--download-archive "~/youtube/archive.txt"

# Make all connections via IPv4
--force-ipv4

# Video format code
--format "bestvideo+bestaudio/best"

# Continue on download errors, for example to skip unavailable videos in a
# playlist.
--ignore-errors

# Do not overwrite files
--no-overwrites

# Output file template
--output "~/youtube/downloads/%(uploader)s/%(uploader)s.%(upload_date)s.%(title)s.%(resolution)s.%(id)s.%(ext)s"

# Restrict filenames to only ASCII characters, and avoid "&" and spaces
--restrict-filenames

# Subtitle format
--sub-format "srt/best"

# Subtitle language
--sub-lang "en"

# Write video description to a .description file
--write-description

# Write video metadata to a .info.json file
--write-info-json

# Write thumbnail image to disk
--write-thumbnail

# Write subtitle file
--write-sub

# Write automatically generated subtitle file (YouTube only)
--write-auto-sub

# Print various debugging information
#--verbose
EOF

4. Create the ~/youtube/urls.txt file (I added Keyboard Cat as a small test video):

cat > ~/youtube/urls.txt << "EOF"
# Examples:
# ytuser:username
# https://www.youtube.com/user/username
# https://www.youtube.com/playlist?list=PLK9Sc5q_4K6aNajVLKtkaAB1JGmKyccf2
https://www.youtube.com/watch?v=J---aiyznGQ
EOF

5. Exit the shell or bash instance:

exit

6. Test it:

youtube-dl --config-location ~/youtube/config.conf

If nothing went wrong, your ~/youtube directory should look like this:

youtube
├── archive.txt
├── config.conf
├── downloads
│   └── Keyboard_Cat
│       ├── Keyboard_Cat.20070607.Charlie_Schmidt_s_Keyboard_Cat_-_THE_ORIGINAL.320x240.J---aiyznGQ.description
│       ├── Keyboard_Cat.20070607.Charlie_Schmidt_s_Keyboard_Cat_-_THE_ORIGINAL.320x240.J---aiyznGQ.info.json
│       ├── Keyboard_Cat.20070607.Charlie_Schmidt_s_Keyboard_Cat_-_THE_ORIGINAL.320x240.J---aiyznGQ.jpg
│       └── Keyboard_Cat.20070607.Charlie_Schmidt_s_Keyboard_Cat_-_THE_ORIGINAL.320x240.J---aiyznGQ.mp4
└── urls.txt

And the ~/youtube/archive.txt file should contain Keyboard Cat's video ID:

youtube J---aiyznGQ

If you run youtube-dl --config-location ~/youtube/config.conf again, it should skip the Keyboard Cat video as it's already been processed.

7. Everything look good? You're all done, unless you want to set up a cron job:

# Every 6 hours
30 */6 * * * flock --nonblock /tmp/youtubedl.lock --command "youtube-dl --config-location ~/youtube/config.conf"

Append > /dev/null 2>&1 if you don't want youtube-dl to send any output to your syslog:

# Every 6 hours; don't send output to syslog
30 */6 * * * flock --nonblock /tmp/youtubedl.lock --command "youtube-dl --config-location ~/youtube/config.conf" > /dev/null 2>&1

The flock command is used to prevent youtube-dl from running more than once at a time. If you're on Mac OS X you can use this cross-platform version: https://github.com/discoteq/flock

Note:

If you plan to download playlists that contain videos from different users, you may want to modify the --output flag in ~/youtube/config.conf and change %(uploader)s to %(playlist_title)s so those videos are grouped in the same parent folder:

- --output "~/youtube/downloads/%(uploader)s/%(uploader)s.%(upload_date)s.%(title)s.%(resolution)s.%(id)s.%(ext)s"
+ --output "~/youtube/downloads/%(playlist_title)s/%(uploader)s.%(upload_date)s.%(title)s.%(resolution)s.%(id)s.%(ext)s"

Using uploader will result in a folder hierarchy such as:

~/youtube/downloads/Some_User/Some_User.{date}.{title}...
~/youtube/downloads/Some_Other_User/Some_Other_User.{date}.{title}...
~/youtube/downloads/Another_User/Another_User.{date}.{title}...

Using playlist_title:

~/youtube/downloads/Some_Playlist_Title/Some_User.{date}.{title}...
~/youtube/downloads/Some_Playlist_Title/Some_Other_User.{date}.{title}...
~/youtube/downloads/Some_Playlist_Title/Another_User.{date}.{title}...

One downside to using playlist_title is videos downloaded from a single user (e.g., ytuser:username) are saved in a folder called Uploads_From_Username:

~/youtube/downloads/Uploads_From_Some_User/Some_User.{date}.{title}...

And videos downloaded from a direct URL (https://www.youtube.com/watch?v=ID) are saved in a folder called NA.

Recap:

  • ~/youtube/config.conf - youtube-dl configuration
  • ~/youtube/urls.txt - List of URLs to download
    • See --batch-file flag in ~/youtube/config.conf to modify
  • ~/youtube/archive.txt - List of downloaded video ID's
    • See --download-archive flag in ~/youtube/config.conf to modify
  • ~/youtube/downloads/{downloaded files} - Download directory
    • See --output flag in ~/youtube/config.conf to modify

from ytdlrc.

ufo56 avatar ufo56 commented on July 30, 2024

Good info. Thank you!

from ytdlrc.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.