Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download without rclone moving #3

Closed
ufo56 opened this issue Jul 5, 2018 · 2 comments
Closed

Download without rclone moving #3

ufo56 opened this issue Jul 5, 2018 · 2 comments

Comments

@ufo56
Copy link

ufo56 commented Jul 5, 2018

Hi

Thank you for nice script.
Is there any way to remove rclone part, i just need to download youtube playlist to folder without moving anything...

@bardisty
Copy link
Owner

bardisty commented Jul 6, 2018

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

@ufo56
Copy link
Author

ufo56 commented Aug 10, 2018

Good info. Thank you!

@bardisty bardisty pinned this issue Oct 8, 2019
@bardisty bardisty closed this as completed Oct 8, 2019
@bardisty bardisty mentioned this issue Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants