-
Notifications
You must be signed in to change notification settings - Fork 0
cmlburnett/ydl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Wrapper for youtube-dl module https://github.com/ytdl-org/youtube-dl that simplifies calling it to download from youtube. Requires my custom libraries: mkvxmlmaker crudexml sqlitehelper ### As an executable library ### Execute the library as a script python -m ydl --help Using ydl in this manner creates a sqlite database in the current directory to store videos (ydl.db). python -m ydl --add https://www.youtube.com/user/NASAtelevision python -m ydl --sync-list NASAtelevision python -m ydl --download NASAtelevision This will add NASA to the list of channels, sync the list to check for new videos, and download videos. When downloading videos, files are saved with the video title used as the file name that is heavily modified to be filesystem friendly. You can use --ignore-old to skip downloading old videos (videos already downloaded) when called later. python -m ydl --ignore-old --download NASAtelevision To list all of the channels and playlists being tracked: python -m ydl --list and to list all the channels and playlists and their videos (this could be very long): python -m ydl --listall or just all in a single channel python -m ydl --listall NASAtelevision To get more information on the database python -m ydl --info To get information on all videos in a channel python -m ydl --info NASAtelevision TO get information on a specific video python -m ydl --info _fRSaLAEW2s When passing a YTID that begins with a dash, you must change it to an equal sign since python interprets it as an argument python -m ydl --info =A58krE7bBE If there's a video to skip because it's private, requires payment, you don't care about it, etc pass it in with --skip python -m ydl --skip _fRSaLAEW2s and --unskip to take it off the skip list. If there's a video that is not yet released, sleeping is a way to temporarily skip the video (this will skip for 10 days) python -m ydl --sleep _fRSaLAEW2s d+10 and --unsleep to take it off the sleep list. Accepted time formats are absolute time YYYY-MM-SS HH:MM:SS in UTC, or in relative format of d+N for days, h+N for hours, m+N for minutes, and s+N for seconds. Videos not yet released are automatically marked as sleeping based on the time indicated in the error message. Pass --noautosleep to disable automatically creating these sleep times. Other functions: --name Set the name for a video to something other than generated from the video title --alias Some channels are "unnamed" and this sets an alias for it --rate Sets the download rate in bits per second --update-names Renames all files for a YTID (more of a debug function) --force Force an action, which bypasses some checks to be more efficient --no-rss Skip checking RSS for a --sync-list action --notify Uses Pushover to send notifications to your phone, etc (configure with ~/.pushoverrc) when things finish --noautosleep If a video is found to be not released yet, a sleep timer is automatically set. This turns that off. --cookies Pass in a cookies file to youtube-dl --merge-playlist Merge an entire playlist into a single video using each playlist item as a chapter in the final video --chapter-edit Edit chapter information for a video (this works regardless if source video had chapters) --chapterize Take the chapter information, and add it to the video (creates a new copy with chapter info) --split Dice up a file based on chapter information (mkv, mp3, or ogg) --convert Convert file to mp3 or ogg --artist Add artist information if making mp3 or ogg --album Add album information if making mp3 or ogg --year Add year information if making mp3 or ogg --genre Add genre information if making mp3 or ogg --hook List hooks or add python library as hooks if provided --unhook Remove a python library as a hook --nochook Suspend use of hooks for this invocation ### As a regular library ### import ydl ydl.download([('dQw4w9WgXcQ', 'Rick Astley', 'Never Gonna Give You Up')]) Or if a numerous are supplied in the list: import ydl ydl.download([ ('dQw4w9WgXcQ', 'Rick Astley', 'Never Gonna Give You Up'), ('yPYZpwSpKmA', 'Rick Astley', 'Together Forever'), ]) By default, this downloads the thumbnails, metadata, annotations, descipription, and JSON info. If the vidoe file is already downloaded, then it is skipped. If there is an error if a single entry then it, by default, skips it and continues on with the remainder. Lastly, include convert_mp3=True to invoke ffmpeg to convert the downloaded file into an mp3. write_all_thumbnails=True add_metadata=True writeinfojson=True writedescription=True writeannotations=True skip_download=False skip_if_exists=True skip_if_fails=True convert_mp3=False Example: import ydl ydl.download([('dQw4w9WgXcQ', 'Rick Astley', 'Never Gonna Give You Up')], convert_mp3=True) ### Extension ### Limited facilities exist to extend the functionality through execution hooks. These currently serve more as notifications of events rather than means to alter ydl's execution. To use a hook, write a new python library and install it like usual. In your library, use the ydl.hook decorator on functions you want to hook. For example, this function will be called whenever a download is completed: from ydl import hook @hook('download') def mydownload(db, hook_name, **kwargs): ret = db.v.select('*', "`ytid`='%s'"%ytid) ret = dict(ret.fetchone()) print("Downloaded video '%s' from channel '%s'" % (ytid, ret['dname'])) A function can accept multiple hooks @hook('skip-video', 'skip-playlist', 'unskip-video', 'unskip-playlist') which is why the hook name is provided as an argument. If accepting multiple hooks, or a hook with variable arguments (eg, add) then use the **kwargs to catch the args in a dict and then test the values. @hook('add') def myadd(db, hook_name, **kwargs): if kwargs['kind'] == ch: ... elif kwargs['kind'] == 'c': ... If, for whatever reason, you want to not invoke hooks then use --nohook. Overall, hooks are intended to allow post-event actions to be taken. This could mean sneding a notification, pushing a downloaded file elsewhere, processing a downloaded file into another system, etc. No limits, really. Keep in mind these are ran inline so long executions will delay the main ydl functionality.