5 ms·
Here is the important 2 lines of code. response = urlopen('https://www.youtube.com/results?search_query=' + search) command = 'youtube-dl --extract-audio -
by nbardy 11y ago
Here is the important 2 lines of code.
response = urlopen('https://www.youtube.com/results?search_query=' + search)
command = 'youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 ' + video_link
Amazing how useful of a tool you can make with such little code. There is really some great libraries available today.
- yask123 11y agoYea! , and I also wrote a small script to embed album arts for all mp3 files. The script queries with mp3 file name in google images, picks up the first image, downloads it and embeds in mp3 file automatically. http://iyask.me/fixalbumart/ http://iyask.me/fixalbumart/
- Jerry2 11y agoI also save audio from YT occasionally. I prefer to use this command however (to get the best quality audio): youtube-dl -f bestaudio[ext=m4a] <youtube ID> PS: you can replace m4a with mp3 but that will induce trasnscoding and loss of quality. YT's AAC tracks are usually the highest bitrate ones so it's best to leave it as is.
- JoshTriplett 11y agoyoutube-dl already defaults to downloading the best quality audio; you only need that line if you want to force a particular format.
- leni536 11y agoI thought youtube-dl defaults to "best"
- JoshTriplett 11y agoyoutube-dl defaults to "best"; youtube-dl --extract-audio defaults to "bestaudio".
- Jerry2 11y agoNot quite. Sometimes "bestaudio" downloads webm files because Opus audio tracks report higher average variable bitrate. If you don't want to download video+audio and don't want to transcode or deal with Opus stuff, you need that m4a flag in there. Since nothing supports Opus and you need to transcode and remove video, webm seems like a losing proposition. And higher bit rate is deceptive since AAC is a much better encoder even at a lower bit rate.
- JoshTriplett 11y agoThat's what I mean: youtube-dl --extract-audio already downloads the best quality audio, which may be Opus (albeit typically via DASH rather than a full webm file), so you only need a line like the one you pasted if you want to specify a specific format such as m4a.
- burger_moon 11y agoI believe bestaudio[ext=m4a] should be wrapped in quotes. >"bestaudio[ext=m4a]" (First time I've ever used it but it wouldn't work for me without the quotes)
- rokhayakebe 11y agoI have a friend who sold his YT video download site for (low) mid range 6 figures.
- MKais 11y agoWhich site? (if you can tell it of course)
- rokhayakebe 11y agoI cannot, unfortunately. But it is still up & running after the acquisition (2/3 years ago). Basically it lets people search and download YT videos. Very simple, nothing else. One smart thing he did was to create a new page every time someone downloaded a video, and at some point he was getting hundreds of thousands of daily visitors (I saw the Analytics charts).
- MKais 11y agointeresting but i can't get how generating billions of pages can get him traffic
- JoshTriplett 11y agoyoutube-dl actually supports searches, as well.
- mhartl 11y agoFrom the source: # Youtube-dl is a proof that god exists.