Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to get python to download YouTube videos in the background?
#1
I am looking to create a small project. The idea is that you input a youtube video link and it downloads it onto your computer. I was thinking about using Selenium - it opens the browser, goes to MP3 video converter and pastes the link, downloads it. But is there a way of doing it without any visible actions (opening the browser). In other words how can I hide that the browser has opened. It would just open the py program, you input the link and after a while the video has been downloaded.
Quote
#2
There are several packages that download youtube, see: https://pypi.org/search/?q=youtube
Quote
#3
youtube-dl is big Python project with 48,454 stars on GitHub.
Can be used in many ways command-line,GUI or web-app.
I made solution's that to use myself with Flask,to get MP3 from a youtube link where youtube-dl dos the background work.
İmage
Quote
#4
im not sure if this is still accurate in the process, but if so you can replicate it in python.
https://www.computing.dcu.ie/~humphrys/N...utube.html
Quote
#5
(Mar-24-2019, 11:43 AM)metulburr Wrote: im not sure if this is still accurate in the process, but if so you can replicate it in python.
https://www.computing.dcu.ie/~humphrys/N...utube.html
Hmm why try an old method that for sure will not work now,youtube-dl is always updated as a lot people work on it.
Also support a lot of other video sites youtube-dl supported sites.

Basic usage is simple youtube-dl url_link
Example get video:
λ youtube-dl https://www.youtube.com/watch?v=d8OI9FllKfg
[youtube] d8OI9FllKfg: Downloading webpage
[youtube] d8OI9FllKfg: Downloading video info webpage
[youtube] d8OI9FllKfg: Downloading js player vflGPko2h
[download] Destination: Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.f248.webm
[download] 100% of 30.32MiB in 00:16
[download] Destination: Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.f251.webm
[download] 100% of 4.14MiB in 00:02
[ffmpeg] Merging formats into "Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.webm"
Deleting original file Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.f248.webm (pass -k to keep)
Deleting original file Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.f251.webm (pass -k to keep
Example get MP3 in highest quality:
λ youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 https://www.youtube.com/watch?v=d8OI9FllKfg
[youtube] d8OI9FllKfg: Downloading webpage
[youtube] d8OI9FllKfg: Downloading video info webpage
[youtube] d8OI9FllKfg: Downloading js player vflGPko2h
[download] Destination: Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.webm
[download] 100% of 4.14MiB in 00:02
[ffmpeg] Destination: Komodo - (I Just) Died In Your Arms-d8OI9FllKfg.mp3
Quote
#6
I use youtube-dl also. The problem is they do not support all sites. youtube-dl doesnt even support sites like.... speedvid.net, vidlox.tv, vidoza.net, clipwatching.com, vidtodo.com, etc. And some of the sits they do say they support, often have trouble working. The other problem with youtube is if they think you are pirating they wont answer your issue and just not give you helpful info. They wont help if they know the site is pirating, but they have how many sites listed as supported? The only alternative is to build your own. I have thought about this, but not had the desire to devote the time to do it.

Plus if the concept is to create your own method of downloading, using youtube-dl is not a fix. It does not teach you how to download from different sites via programming.

Quote:But is there a way of doing it without any visible actions (opening the browser).
Yes there is a way to hide the browser. You can use it in headless mode by giving it the argument --headless
Quote:
options.add_argument("--headless")
https://python-forum.io/Thread-Web-scrap...7#pid60787
Quote
#7
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
Output:
Youtube address: https://www.youtube.com/watch?v=zPMr0lEMqpo
Thanks, and cheers
Quote
#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)
Quote
#9
I have one on github (using PyQt5)

I use it in Linux.

İmage
Larz60+ likes this post
Quote
#10
Thanks a lot, snippsat, for your kind answer.
Further info needs. Which command I've to add to download one single file .mp4 coming from this choice?
Output:
22 mp4 1280x720 hd720 347k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)
# -------- YT.py -----------
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=zPMr0lEMqpo'])

# ----- OUTPUT -------
#C:\Training>python YT.py
#[youtube] zPMr0lEMqpo: Downloading webpage
#[youtube] zPMr0lEMqpo: Downloading video info webpage
#[youtube] Downloading just video zPMr0lEMqpo because of --no-playlist
#[info] Available formats for zPMr0lEMqpo:
#format code  extension  resolution note
#249          webm       audio only DASH audio   49k , opus @ 50k, 1.07MiB
#250          webm       audio only DASH audio   54k , opus @ 70k, 1.21MiB
#171          webm       audio only DASH audio   88k , vorbis@128k, 2.03MiB
#251          webm       audio only DASH audio  100k , opus @160k, 2.21MiB
#140          m4a        audio only DASH audio  127k , m4a_dash container, mp4a.40.2@128k, 3.08MiB
#160          mp4        256x144    144p   38k , avc1.4d400c, 30fps, video only, 421.68KiB
#278          webm       256x144    144p   84k , webm container, vp9, 30fps, video only, 987.35KiB
#133          mp4        426x240    240p   98k , avc1.4d4015, 30fps, video only, 776.98KiB
#242          webm       426x240    240p  141k , vp9, 30fps, video only, 1.39MiB
#243          webm       640x360    360p  264k , vp9, 30fps, video only, 2.60MiB
#134          mp4        640x360    360p  264k , avc1.4d401e, 30fps, video only, 1.70MiB
#135          mp4        854x480    480p  474k , avc1.4d401f, 30fps, video only, 3.02MiB
#244          webm       854x480    480p  481k , vp9, 30fps, video only, 4.13MiB
#136          mp4        1280x720   720p  858k , avc1.4d401f, 30fps, video only, 5.35MiB
#247          webm       1280x720   720p  915k , vp9, 30fps, video only, 8.75MiB
#43           webm       640x360    medium , vp8.0, vorbis@128k, 6.16MiB
#18           mp4        640x360    medium  306k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 7.44MiB
#22           mp4        1280x720   hd720  347k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)
# ------------------------------------------------------------------------------------------------

Edit. Just solved.
Output:
C:\Training>youtube-dl -f 22 https://www.youtube.com/watch?v=zPMr0lEMqpo [youtube] zPMr0lEMqpo: Downloading webpage [youtube] zPMr0lEMqpo: Downloading video info webpage [download] Destination: How to install pip on Windows (The easy way)-zPMr0lEMqpo.mp4 [download] 100% of 8.41MiB in 00:02
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to background another process in Python? Kalet 2 184 Oct-21-2019, 05:17 AM
Last Post: newbieAuggie2019
  autostart python scripts in background (Windows10) john36 4 398 Oct-01-2019, 01:36 PM
Last Post: john36
  Python Error with youtube-dl - Any Help? abrogard 4 323 Sep-30-2019, 10:01 PM
Last Post: snippsat
  download python 3.7.0 mainbane 1 578 Aug-09-2018, 06:51 PM
Last Post: buran
  Using Subprocess.Popen to start another python script running in background on Window johnb546 0 7,262 Jun-01-2018, 01:57 PM
Last Post: johnb546
  What Version of Python I should download G70115 1 568 Apr-28-2018, 04:44 PM
Last Post: snippsat
  How to check if video has been deleted or removed in youtube using python Prince_Bhatia 3 2,331 Apr-10-2018, 06:47 PM
Last Post: Prince_Bhatia
  Download from youtube antonbison 7 1,047 Mar-25-2018, 09:25 AM
Last Post: buran
  want to use PIL on individual frames of videos tomywd 1 685 Mar-13-2018, 04:16 AM
Last Post: micseydel
  Executing external Python file in background and get output in python nakiscia 0 2,747 Feb-15-2018, 02:07 PM
Last Post: nakiscia

Forum Jump:


Users browsing this thread: 1 Guest(s)