Python Forum
How to get python to download YouTube videos in the background?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get python to download YouTube videos in the background?
#8
(Mar-24-2019, 02:56 PM)samsonite Wrote: Beside question. Is it possible to create a Python code like the one below written in PHP? Several quality options are selectable, as shown here http://imgbox.com/YciMpWyC
youtube-dl has all this eg listformats youtube-dl -F
G:\1_youtube
λ youtube-dl -F https://www.youtube.com/watch?v=d8OI9FllKfg
[youtube] d8OI9FllKfg: Downloading webpage
[youtube] d8OI9FllKfg: Downloading video info webpage
[info] Available formats for d8OI9FllKfg:
format code  extension  resolution note
249          webm       audio only DASH audio   69k , opus @ 50k, 1.58MiB
250          webm       audio only DASH audio   90k , opus @ 70k, 2.09MiB
140          m4a        audio only DASH audio  127k , m4a_dash container, mp4a.40.2@128k, 3.89MiB
171          webm       audio only DASH audio  142k , vorbis@128k, 3.82MiB
251          webm       audio only DASH audio  161k , opus @160k, 4.14MiB
394          mp4        256x144    144p   95k , av01.0.05M.08, 25fps, video only, 2.41MiB
278          webm       256x144    144p   95k , webm container, vp9, 25fps, video only, 2.79MiB
160          mp4        256x144    144p  110k , avc1.4d400c, 25fps, video only, 2.06MiB
395          mp4        426x240    240p  208k , av01.0.05M.08, 25fps, video only, 4.71MiB
242          webm       426x240    240p  220k , vp9, 25fps, video only, 5.01MiB
133          mp4        426x240    240p  295k , avc1.4d4015, 25fps, video only, 5.03MiB
396          mp4        640x360    360p  364k , av01.0.05M.08, 25fps, video only, 8.06MiB
243          webm       640x360    360p  419k , vp9, 25fps, video only, 10.14MiB
134          mp4        640x360    360p  580k , avc1.4d401e, 25fps, video only, 10.25MiB
397          mp4        854x480    480p  623k , av01.0.05M.08, 25fps, video only, 13.27MiB
244          webm       854x480    480p  767k , vp9, 25fps, video only, 16.88MiB
135          mp4        854x480    480p  832k , avc1.4d401e, 25fps, video only, 14.78MiB
398          mp4        1280x720   720p 1183k , av01.0.05M.08, 25fps, video only, 24.68MiB
136          mp4        1280x720   720p 1212k , avc1.4d401f, 25fps, video only, 20.78MiB
247          webm       1280x720   720p 1472k , vp9, 25fps, video only, 23.73MiB
137          mp4        1920x1080  1080p 1641k , avc1.640028, 25fps, video only, 30.68MiB
248          webm       1920x1080  1080p 2108k , vp9, 25fps, video only, 30.32MiB
18           mp4        640x360    medium  547k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 16.74MiB (best)
Download eg 136 mp4 1280x720 720p 1212k.
G:\1_youtube
λ youtube-dl -f 136 https://www.youtube.com/watch?v=d8OI9FllKfg
[youtube] d8OI9FllKfg: Downloading webpage
[youtube] d8OI9FllKfg: Downloading video info webpage
[download] Destination: Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.mp4
[download] 100% of 20.78MiB in 00:08
From a python script.
import youtube_dl

options = {
    'format': 'bestaudio/best',  
    'extractaudio': True,        
    'audioformat': "mp3",        
    'outtmpl': '%(id)s',         
    'noplaylist': True,          
    'listformats': True,   # print a list of the formats to stdout and exit
}

with youtube_dl.YoutubeDL(options) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=d8OI9FllKfg'])
Output:
[youtube] d8OI9FllKfg: Downloading webpage [youtube] d8OI9FllKfg: Downloading video info webpage [youtube] Downloading just video d8OI9FllKfg because of --no-playlist [info] Available formats for d8OI9FllKfg: format code extension resolution note 249 webm audio only DASH audio 69k , opus @ 50k, 1.58MiB 250 webm audio only DASH audio 90k , opus @ 70k, 2.09MiB 140 m4a audio only DASH audio 127k , m4a_dash container, mp4a.40.2@128k, 3.89MiB 171 webm audio only DASH audio 142k , vorbis@128k, 3.82MiB 251 webm audio only DASH audio 161k , opus @160k, 4.14MiB 394 mp4 256x144 144p 95k , av01.0.05M.08, 25fps, video only, 2.41MiB 278 webm 256x144 144p 95k , webm container, vp9, 25fps, video only, 2.79MiB 160 mp4 256x144 144p 110k , avc1.4d400c, 25fps, video only, 2.06MiB 395 mp4 426x240 240p 208k , av01.0.05M.08, 25fps, video only, 4.71MiB 242 webm 426x240 240p 220k , vp9, 25fps, video only, 5.01MiB 133 mp4 426x240 240p 295k , avc1.4d4015, 25fps, video only, 5.03MiB 396 mp4 640x360 360p 364k , av01.0.05M.08, 25fps, video only, 8.06MiB 243 webm 640x360 360p 419k , vp9, 25fps, video only, 10.14MiB 134 mp4 640x360 360p 580k , avc1.4d401e, 25fps, video only, 10.25MiB 397 mp4 854x480 480p 623k , av01.0.05M.08, 25fps, video only, 13.27MiB 244 webm 854x480 480p 767k , vp9, 25fps, video only, 16.88MiB 135 mp4 854x480 480p 832k , avc1.4d401e, 25fps, video only, 14.78MiB 398 mp4 1280x720 720p 1183k , av01.0.05M.08, 25fps, video only, 24.68MiB 136 mp4 1280x720 720p 1212k , avc1.4d401f, 25fps, video only, 20.78MiB 247 webm 1280x720 720p 1472k , vp9, 25fps, video only, 23.73MiB 137 mp4 1920x1080 1080p 1641k , avc1.640028, 25fps, video only, 30.68MiB 248 webm 1920x1080 1080p 2108k , vp9, 25fps, video only, 30.32MiB 18 mp4 640x360 medium 547k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 16.74MiB (best)
Reply


Messages In This Thread
RE: How to get python to download YouTube videos in the background? - by snippsat - Mar-24-2019, 03:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python multiprocessing to download sql table mg24 5 1,547 Oct-31-2022, 03:53 PM
Last Post: Larz60+
  download with internet download manager coral_raha 0 3,015 Jul-18-2021, 03:11 PM
Last Post: coral_raha
  How to make a bot in pycharm for youtube for automatically adding python comments kodek2222 1 2,113 Jan-21-2021, 12:47 PM
Last Post: Aspire2Inspire
  download pubmed PDFs using pubmed2pdf in python Wooki 8 5,621 Oct-19-2020, 03:06 PM
Last Post: jefsummers
  How can I download Python files from GitHub? bitcoin10mil 2 2,872 Aug-26-2020, 09:03 PM
Last Post: Axel_Erfurt
  win32 API: Launch Application to RDP session from background process python script rangeshgupta 0 2,190 May-28-2020, 09:41 PM
Last Post: rangeshgupta
Big Grin python download manager with progressbar (not gui) ghostblade 1 1,951 Apr-23-2020, 11:05 AM
Last Post: snippsat
  Python Download GillietheSquid 2 2,063 Mar-27-2020, 09:15 PM
Last Post: GillietheSquid
  How to check if video has been deleted or removed in youtube using python Prince_Bhatia 14 12,009 Feb-21-2020, 04:33 AM
Last Post: jehoshua
  How to background another process in Python? Kalet 2 2,528 Oct-21-2019, 05:17 AM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020