Package: automateYT
automateYTautomateYT is lightweight library for automating to download youtube videos, subtitles (if available) and playlist.InstallationautomateYT requires an installation of python 3.6 or greater andpytube, as well as pip. Pip is typically bundled with python installations, and you can find options
for how to install python athttps://python.org.To install from pypi with pip:pipinstallautomateYTClone GitHub repositorygitclonehttps://github.com/umutambyi-gad/automateYTOverviewClasses:TimingAutomateMethods:after()info()generate_watch_url_from_playlist()download()download_subtitle()download_playlist()shutdown()UsageFirst of all importAutomateclass fromautomateYTfromautomateYTimportAutomateQuick demo:let's say you want to download three videos and their subtitles after two hours and half and when it's done the computer shuts down itselffromautomateYTimportAutomatefromautomateYTimportTimingTiming().after('2h-30m')# or Automate().after('2h-30m') since Automate extends TimingAutomate(['https://www.youtube.com/watch?v=XqZsoesa55w','https://www.youtube.com/watch?v=F4tHL8reNCs','https://www.youtube.com/watch?v=F4tHL8reNCs']).download(subtitle=True,location='C:/Users/GentleMan/videos',shutdown=True)The above script will download all given videos and output them onC:/Users/GentleMan/videosbut if you didn't specifylocationby default will in theDownloadsand also script will pick thehighest resolutionavailable
but what if you want to customize the videos' resolution just see the following example.Automate(url_with_res={'https://www.youtube.com/watch?v=XqZsoesa55w':'720p','https://www.youtube.com/watch?v=F4tHL8reNCs':'1080p','https://www.youtube.com/watch?v=F4tHL8reNCs':'144p'}).download(subtitle=True,shutdown=True)Watch closely before passingdictwherekeysare valid watch urls andvaluesare valid resolution I passed an argument calledurl_with_resit's an obligation to pass argument before thedictotherwise it will raise an error but cool thing is that you don't have to memorize thisurl_with_resyou can simply rename it to whatever you want without any further configurations just like.Automate(watchUrls_with_their_resolution={'https://www.youtube.com/watch?v=XqZsoesa55w':'720p',...})...Now you saw how to download them but we have passed watch url on inAutomateclass likeAutomate('https://www.youtube.com/watch?v=XqZsoesa55w')so what makes you think it's the true watch url
here is how you can view major information about the watch url.info=Automate('https://www.youtube.com/watch?v=XqZsoesa55w').info()print(info)Output will be something like -[{"watch_url":"https://www.youtube.com/watch?v=XqZsoesa55w","video_id":"XqZsoesa55w","title":"Baby Shark Dance | #babyshark Most Viewed Video | Animal Songs | PINKFONG Songs for Children","thumbnail_url":"https://i.ytimg.com/vi/XqZsoesa55w/maxresdefault.jpg","author":"Pinkfong! Kids' Songs & Stories","publish_date":"2016-06-17","type":"video/mp4","filesize":"11.4MiB","available_resolution":["144p","240p","360p","480p","720p","1080p"],"highest_resolution":"1080p","lowest_resolution":"360p","views":"8,350,191,773","rating":3.7,"age_restricted":false}]As you can see the output above is injsonformat but what if you preferyamlformat thanjsonjust pass keyword stringyamlas an argument in theinfolike -info=Automate(('https://www.youtube.com/watch?v=XqZsoesa55w',)).info('yaml')print(info)Output will be inyamlformat --age_restricted:falseauthor:Pinkfong! Kids' Songs & Storiesavailable_resolution:-144p-240p-360p-480p-720p-1080pfilesize:11.4MiBhighest_resolution:1080plowest_resolution:360ppublish_date:'2016-06-17'rating:3.7thumbnail_url:https://i.ytimg.com/vi/XqZsoesa55w/maxresdefault.jpgtitle:'BabySharkDance|#babysharkMostViewedVideo|AnimalSongs|PINKFONGSongsforChildren'type:video/mp4video_id:XqZsoesa55wviews:8,350,191,773watch_url:https://www.youtube.com/watch?v=XqZsoesa55wAnd we all know that youtube can have playlist which contains couple of videos, the following is how you can generate watch urls of every single video from the playlist.frompprintimportpprintwatchUrls=Automate("https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n").generate_watch_url_from_playlist()pprint(watchUrls)An output will be something like -['https://www.youtube.com/watch?v=F9TZb0XBow0','https://www.youtube.com/watch?v=26VtIlzEcmU','https://www.youtube.com/watch?v=41qgdwd3zAg',...]So not only you can generate watch urls from playlist url but also you can download them all or provide an integerlimitargument to limit videos to be downloaded from the playlist.Automate("https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n").download_playlist(limit=10)Remember if you don't specifylocationby default will be inDownloadsdon't worry about on what platform you are on. and also you can download their subtitles to by passing thissubtitle=Trueargument.DocumentationTimingclass for converting string time looks like (2h:30m,2h30m, or2h-30m) into seconds and delay timeAutomateClass with methods for automating to download youtube videos as either videos or audios, subtitles (if available) and generating watch urls from youtube playlist.Automate(*urls:tupleorlist,**urls_with_res:dict):param:list or tuple urls:valid list or tuple of YouTube watch URLs.:param:dict urls_with_res:dict where keys are valid YouTube watch URLs and values are valid video resolutions.afterMethod for delaying time which are in format of human readable time (2h:30m)Timing().after('20m:15s'):param:str timestring time for delaying which written in human readable format - ex.2h:30mor2h-30mor30swhereh->hours,m->minutesands->secondinfoMethod for giving some useful information about the youtube videos in easy and readable format.Automate('https://www.youtube.com/watch?v=XqZsoesa55w').info()-- or --Automate('https://www.youtube.com/watch?v=XqZsoesa55w').info('yaml'):param:str fmtString ftm (format) controls the return type by default isjsonand other available format isyaml:rtype:yaml or jsongenerate_watch_url_from_playlistMethod for generating valid youtube watch urls from the youtube playlistAutomate('https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n').generate_watch_url_from_playlist():rtype:listdownloadMethod for downloading of custom resolution YouTube videos as videos or audio and also subtitles (if available)Automate('https://www.youtube.com/watch?v=XqZsoesa55w',).download(subtitle=True,location='C:/Users/GentleMan/videos',only_audio=True,shutdown=True):param:str locationlocation path on your computer to save the downloads, by default is in Downloads:param:bool highest_resif highest_res is True the script gets the highest resolution available:param:bool lowest_resif lowest_res is True the script gets the lowest resolution available:param:bool subtitleif subtitle is True english version or english auto generated subtitle is downloaded within its video:param:bool shutdownif shutdown is True the computer shuts down after downloads is completely done:param:bool only_audioif only_audio is True audio only is downloadeddownload_subtitleMethod for downloading YouTube video's subtitles (if available) or auto generated one in whatever languageAutomate('https://www.youtube.com/watch?v=XqZsoesa55w',).download(location='C:/Users/GentleMan/videos',lang_code='en',auto_generated=False,shutdown=True):param:str lang_codelanguage code of the subtitle to automate its downloading notice that the default is 'en' (English).:param:str auto_generatedby default True, this downloads auto generated version of the same language code in absence of offical one.:param:str locationlocation on your computer to save the downloads, by default is in Downloads.:param:bool shutdownif shutdown is True the computer shuts down after downloads is completely done.download_playlistMethod for downloading youtube playlist till the limit given is reachedAutomate("https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n").download_playlist(limit=30):param:str locationlocation on your computer to save the downloads, by default is in Downloads.:param:bool highest_resif highest_res is True the script gets the highest resolution available.:param:bool lowest_resif lowest_res is True the script gets the lowest resolution available.:param:int limitinteger limit limits the number of the videos to be downloaded.:param:bool subtitleif subtitle is True english version or english auto generated subtitle is downloaded within its video.:param:bool shutdownif shutdown is True the computer shuts down after downloads is completely done.LicenseThis project is under theMITlicense