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.
How to get python to download YouTube videos in the background?
How to get python to download YouTube videos in the background?
|
Mar-23-2019, 03:21 PM
There are several packages that download youtube, see: https://pypi.org/search/?q=youtube
Mar-23-2019, 04:14 PM
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. ![]()
Mar-24-2019, 11:43 AM
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
Recommended Tutorials:
(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.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 keepExample 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
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:https://python-forum.io/Thread-Web-scrap...7#pid60787options.add_argument("--headless")
Recommended Tutorials:
Mar-24-2019, 02:56 PM
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
Thanks, and cheers
Mar-24-2019, 03:48 PM
(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/YciMpWyCyoutube-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:08From 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'])
Mar-24-2019, 04:16 PM
(This post was last modified: Mar-24-2019, 04:17 PM by Axel_Erfurt.)
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?
# -------- 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.
|
|
Users browsing this thread: 2 Guest(s)