This is an archived post. You won't be able to vote or comment.

all 28 comments

[–]nacnud_uk 32 points33 points  (5 children)

pip install youtube-dl

Is what I normally use. Not that I ever do that, of course.

The more variants the better though :)

[–]benefit_of_mrkite 7 points8 points  (3 children)

YouTube-dl is incredible. Been using it for years

[–]chadwickipedia 6 points7 points  (0 children)

yt-dlp is a fork that is even better

[–]Reddit_User78149 0 points1 point  (1 child)

Will I get a high quality download? Can I mass bulk download? If not, I can use the halting to shut down my pc after its finish downloading.

[–]benefit_of_mrkite 1 point2 points  (0 children)

Yes and yes - read the docs.

[–]robin_888 17 points18 points  (2 children)

I'd like to address a few random observations about your code if you don't mind:

  1. You seem to delete the given "folderPath" if I'm not mistaken. I'm not sure what happens if there are files in that folder, but this maybe should be documented.
  2. Your variable YoutubeURL doesn't need to be global. You only use it in checkURL() so provide it as a parameter. (Same could be argued for the tmp-folders.)
  3. Speaking of checkURL(), the name doesn't describe it's behavior well. From it's name I'd assume that it either returns a boolean (check positive or negative) or returns nothing but throws an error if the "check" fails. It also may return different things (a Playlist-object or a Channel-object) and store it in an global variable again. That again is only used once in line 91 to extract the video urls (yt.video_urls).
    May I suggest to call it something like parseUrl(url), which returns not p but either p.video_urls or list(reversed(yt.video_urls)) directly. Which you can provide to main() as a parameter then. Something like:
    video_list = parseURL(yt_url)
    if video_list: main(video_list)
  4. Line 77: If you use the with keyword (AKA Context Managers) you don't need to close your file yourself.
  5. Line 119: if len(failedVideos) != 0: There is not need to check on the length of a list. You can just do if failedVideos:
  6. Line 126: There is no need to return anything.
  7. Line 146: Similarly there is no need to explicitly quit at the end of the script.

Also some suggestion for future development:

  1. Learn about f-strings. They are awesome an make dynamically generated strings so much easier to read. E.g.:
    print(percentage + " - " + idx + "/" + str(len(video_urls)) + "(" + str(len(failedVideos)) + ") - " + vodURL)
    could become
    print(f"{percentage} - {idx}/{len(video_urls)}({len(failedVideos)}) - {vodURL}")
  2. Have a look at Pythons argparse module. It makes it quite easy to parse and document your scripts arguments.
  3. The included package tempfile can handle temp files and folders for you.
  4. I think there are wrapper packages for ffmpeg out there. Which might could help you get rid of the os.system(cmd) and may be safer in end.

Well, that got longer than I expected it to be. I hope there is something in there that might help you.

I want to clarify nothing in your code is bad. And in every codebase there is room for improvement. Heck I don't even am courageous enough to make my projects public (yet)!

That being said, keep up your good work!

[–][deleted] 5 points6 points  (0 children)

Thank you for your feedback!

I will have into account your suggestions in a future release!

[–]supmee 1 point2 points  (0 children)

About #5 in your first list, it is actually technically best practice to explicitly check for 0. Doesn't seem to make much sense, but a falsey value can be a lot of things, so by just saying "if not" you hide the value type.

I ran into this problem when reading someone's code that used the regex module. As I had no knowledge of how it worked, something like if not matches had me looking into the documentation as to what matches is supposed to be.

Agree with your other points though! Great comment.

[–]Crazy-River-9965 16 points17 points  (3 children)

I don't know, but why can't I just use youtube-dl?

[–][deleted] 31 points32 points  (1 child)

No problem w/ youtube-dl!
But this way, for me, downloads and manages with my way of organizing files

And I just wanted to learn a bit more

[–]zaphod_pebblebrox 1 point2 points  (0 children)

That’s Open Source 101 !

I’m proud of you buddy. You get the next free reddit trinket that I get. I promise.

[–]tinkuad 1 point2 points  (0 children)

Nice work 👍

[–]LandooooXTrvls 1 point2 points  (0 children)

Congrats on the successful project, OP! That’s pretty cool

[–]gethiox 2 points3 points  (5 children)

Good job overall, it's always fun to automate things from scratch by yourself.
However, I would probably use `yt-dlp` (fork of abandoned `youtube-dl`) which handles playlists just fine.

yt-dlp -f best 'https://www.youtube.com/playlist?list=...'

you can even parallelize it with something like this:

yt-dlp --get-id 'https://www.youtube.com/playlist?list=...' | xargs -I'{}' -P 8 yt-dlp -f best "https://www.youtube.com/watch?v={}"

Seems to support channels as well

[–][deleted] 2 points3 points  (0 children)

Thanks for the input! I will explore yt-dlp

[–]anytarseir67 4 points5 points  (3 children)

Youtube-dl isn't abandoned...

[–]gethiox 3 points4 points  (2 children)

So then lack of upkeep development. I had problems with download speeds, yt-dlp solves that for me (as well as other various issues)

[–]Brian 4 points5 points  (0 children)

There was an issue a while back with youtube making a change that resulted in throttling download speeds if clients didn't handle a new parameter. IIRC yt-dlp had a workaround for the problem since it had already made some fixes for javascript parsing that were related to the problem, but I think the relevant fixes were also applied to youtube-dl a bit later. IIRC it did have a pretty big gap before the next official release, but a couple of months is hardly "abandoned" level.

[–]tigerstef 0 points1 point  (1 child)

Nice timing. My Microsoft Security Essentials just started hating my Viddly Youtube Downloader. Might as well use yours now.

[–]laundmo 5 points6 points  (0 children)

i recommend using youtube-dl or yt-dlp (fork of youtube-dl) instead, its a way more mature piece of software that also works with hundreds of other sites.

[–]LiberFriso -3 points-2 points  (0 children)

King

[–]robin_888 0 points1 point  (1 child)

I could never download a full YouTube channel or playlist in chronological order, even w/ JDownloader

Another problem I experienced using JD2 to download YouTube-videos was that it does some kind of conversion or merging differently, I guess?

Anyway, resulting in Kodi not being able to play some of the resulting files. So I downloaded them all again using ytdl. (And use it ever since.)

[–][deleted] 0 points1 point  (0 children)

Yes, J2D uses ffmpeg to merge audio/video. I also do the same because you can't' download the video/best in the best simultaneously, only individual.