
Show HN: Download any song without knowing its name - yask123
http://iyask.me/Instant-Music-Downloader/
======
exogen
I have a similar function in my bashrc, which also relies on youtube-dl (which
is amazing, btw, it does a LOT more than YouTube – bandcamp, SoundCloud, etc).

`play` will instantly play any song (great for parties), and `mp3` will
download it:
[https://github.com/exogen/dotfiles/blob/730fb8e2b72b2fc3aa3d...](https://github.com/exogen/dotfiles/blob/730fb8e2b72b2fc3aa3d90b889874bb5195e1d07/.profile#L65)

~~~
Hello71
1\. "function" is non-standard useless syntax 2\. mpv now knows how to
automatically spawn youtube-dl, fetch the URL, and stream it given a YouTube
argument.

~~~
exogen
per (1), these are my dotfiles and I use Bash exclusively, ergo, I use the
syntax I consider better (because you can easily search for "function" and not
the standard syntax with no keyword).

------
nbardy
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.

~~~
Jerry2
I 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
youtube-dl already defaults to downloading the best quality audio; you only
need that line if you want to force a particular format.

~~~
Jerry2
Not 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
That'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.

------
_Marak_
Based on the comments here, it seems this tool is powered by youtube-dl.

youtube-dl is a great tool ( supports multiple websites outside of youtube as
well )

The problem is...if you use youtube-dl to rip songs from youtube you are going
to be stuck with a not so great quality bitrate.

Based on some quick research, it looks like the top quality audio bitrate you
can get currently get from youtube is 126.886 kbps. That's going to really
reduce the quality of any song you rip from the site. Most songs are digitally
released at 320kbps these days. CD quality is 192kbsp.

~~~
pla3rhat3r
This has been an age old question since Mp3s were created. However, I'm going
to disagree with you there on saying that CD quality = 192kb. I've heard 192kb
files and they sound like complete garbage. If you're looking for true "CD
quality" that would be LPCM 44100 Hz 16 bits stereo for a bitrate of 1411
kbps.

~~~
kaoD
> I've heard 192kb files and they sound like complete garbage.

I'm curious, did you blind test yourself? I blind tested a friend of mine who
kept saying so, and he did barely better than random.

~~~
aianus
It's very easy to tell the difference between 192kbps and FLAC if you have a
decent subwoofer and the song ever goes below 30hz. On run-of-the-mill
speakers and earbuds, probably not.

~~~
mrob
It's extremely rare for music to contain anything below 30Hz. Even below 40Hz
is rare. The only place you're likely to find such low frequencies is sound
effects in movie soundtracks.

~~~
peapicker
Unless you are into Bassnectar and the like... ;)

~~~
mrob
Interestingly, a lot of "bass heavy" music focuses on frequencies around 50Hz,
not the really deep sub-bass. This makes sense when you consider human
hearing. Those higher frequencies sound much louder to us, and they're still
low enough to get the tactile feeling.

------
jhgg
It looks like all this is doing is in essence just searching for the lyrics on
youtube, finding the first result and then passing it to youtube-dl.

~~~
cushychicken
Nothing wrong with that, is there?

Sure looks a lot more productive to the boss than searching for your next
track on YouTube. :)

------
DanBC
You may want to ask /r/tipofmytongue if they'll put it in their sidebar.

A few people ask for music. They could have shazaamed it, but they don't.

------
tefo-mohapi
Love it. But expect hell from Google and record labels / music artists alike.
All the best.

~~~
6stringmerc
Yeah, I'm not a big industry player but I'm not exactly enamored with this
kind of thing. One question would be does Youtube-dl still provide
compensation to the artists/label/publisher/etc in the same format as a
stream? If not, then it's genuinely circumventing the (admittedly limited)
tracking and compensation structure YouTube has set up. That...probably won't
work out very well in the long run.

~~~
JoshTriplett
Yes and no: it counts as a "view", but it doesn't show ads.

~~~
developer1
Restated: no. Monetization depends on the ads. Using such a tool is equivalent
to using an ad blocker. If you're comfortable using an ad blocker, you're not
doing much different here.

~~~
JoshTriplett
Exactly. I never see ads on YouTube when using Firefox, only when using the
Android YouTube app.

------
zatkin
You should replace that YouTube video with an Asciinema:
[https://asciinema.org/](https://asciinema.org/)

~~~
btown
But then you wouldn't be able to use instantmusic to download the audio for
the instantmusic demo video! Why pass up an opportunity to be meta when you
can be meta?

------
ahmacleod
This is pretty cool. I usually had to add a little more context to get the
correct result though. It would be nice to see the top ten results, maybe with
a relevance score.

It would also be great if I could pipe in the search and bypass confirmation,
e.g:

> echo hide your love away | instantmusic -f

~~~
yask123
Recently this feature was added. [https://github.com/yask123/Instant-Music-
Downloader/blob/mas...](https://github.com/yask123/Instant-Music-
Downloader/blob/master/music_downloader.py) You can install it from source if
you wish to use it now.

I haven't updated the package as yet.

------
zzleeper
BTW, on a fresh Win10 install (Py3.5) I had a bit of trouble b/c of the lack
of extension. Had to add the .py prefix and it worked then :)

~~~
yask123
I should add that in the Readme.

------
chdir
Slightly simplified & loops through all the links on the first page :

    
    
        import re, youtube_dl
        from bs4 import BeautifulSoup
        from urllib2 import urlopen
        from urllib import quote_plus
    
        ydl_opts = {}
    
        soup = BeautifulSoup(urlopen('https://www.youtube.com/results?search_query=' + quote_plus('linkin')).read())
        links = soup.find_all('a', href=re.compile(r'watch\?v='), class_='yt-uix-tile-link')
        
        for i, link in enumerate(links):
            print i+1, '-', link.text
    
        choice = int(raw_input("Select song index : "))
    
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download(['http://www.youtube.com/' + links[choice-1].get('href')])

------
shmerl
I once tried to identify a piece of instrumental music and tried AudioTag, but
it couldn't find anything. It would be useful to have a huge global music
database with some recognition algorithms for that. Is there anything like
that around?

~~~
mintplant
[https://www.shazam.com/](https://www.shazam.com/)

[http://www.soundhound.com/](http://www.soundhound.com/)

[http://www.midomi.com/](http://www.midomi.com/)

[http://echoprint.me/](http://echoprint.me/)

[http://the.echonest.com/](http://the.echonest.com/)

~~~
shmerl
Thanks. I'm looking for something simple enough that doesn't require any
accounts. Looks like Shazam and Soundhound have no Web services and require
registration. Midomi has recording widget, but no sample upload (that's
somewhat weird).

Echoprint is open, I'll take a look at that. Echonest doesn't seem to have any
service on their site (not sure how it's used).

~~~
timboslice
Check out musicbrainz

~~~
shmerl
Thanks. I thought it's more for meta information (I know VLC uses it to
identify audio by meta tags). Looks like they support acoustic fingerprinting
too:
[https://en.wikipedia.org/wiki/MusicBrainz#Fingerprinting](https://en.wikipedia.org/wiki/MusicBrainz#Fingerprinting)

------
scott_karana
This is super cool. :-)

I think it'd be nice to have a SoundHound/Shazam-style audio fingerprint
downloader too: then you can either repeat lyrics, _or_ get a quick soundbyte!

~~~
tedmiston
I've wanted to build a similar thing for a while, except letting me say some
of the lyrics vs. typing them.

~~~
kenbellows
OP + a voice recognition wrapper

probably wouldn't be too hard, depending on what's available for voice
recognition libs in Python; I haven't actually looked. Anyone know?

------
cushychicken
A nice little tool. I'm a big fan of Youtube-dl as well. I've used it in
similar chain-together command line tools to feed songs from Youtube into
ffmpeg to slow them down to practice/learn songs. It can also swipe audio from
NPR so I can stream to my Sonos system, which is nice, because they tend to
make the Bonnaroo and Newport Folk content streaming-only on their portal.

------
0x4a42
Wow, what a nice hack!

My testing env : Windows 8.1, MSYS2, Python 3. It's working flawlessly even
with some obscur foreign/french lyrics/song/group.

I'm impressed. :)

~~~
yask123
All hail youtube-dl :)

~~~
0x4a42
Thank you for letting me discover these ecosystem of apps (I'm not a big user
of Youtube). And it's still a cool hack. ;)

------
nadams
I'm surprised to see this on HN. This should be called "Illegally download any
song".

I think the project is extremely cool and you have props from me - but I hate
it when people try to skate the simple fact that stuff like this is illegal.
ROMs and emulators have shown up on imgur many times as "free" \- like as if
the publishers have released the rights to the game(s).

~~~
snx
This is using youtube-dl, which downloads the youtube video and converts it to
an audio file. Not illegal. At least in my country..

~~~
bduerst
The Youtube TOS basically says you can only stream content, and pretty much
defines streaming as not downloading for offline or later consumption.

It's about as illegal as violating a TOS.

~~~
yincrash
Well, in the US, it is also considered circumvention, so it's probably liable
for civil penalties.

The EFF's interpretation of the TPP makes it also seem like for any member
country, it could also be liable for criminal penalties.

IANAL

------
navinsylvester
On a similar note. To all those who love to store movies and watch. It's
always a pain to decide what to view. I wrote a tool which helps the process -
[https://github.com/navinsylvester/cinephile](https://github.com/navinsylvester/cinephile)
. Pip install is broken so try the git one.

------
lucb1e
Pretty much the same as playbylyrics.com[1], something I made, except you run
it yourself. I really like it!

[1] (Note that the site is broken as of a few months.. it never caught on and
I'm going to let the domain expire unless someone wants to have it (for free,
just tell me what you're going to do with it).)

------
yask123
Just updated to v1.2 with many bug fixes and some additional features. Run
`pip install instantmusic --upgrade` to try.
[https://github.com/yask123/Instant-Music-
Downloader](https://github.com/yask123/Instant-Music-Downloader)

------
biturd
After a bunch of mess getting it installed on Mac OS X, I get it to find a
song, which is a bit of trouble in and of itself, and am then stuck with this
error: sh: youtube-dl: command not found

~~~
tedmiston
Are you intending to use the author's program or youtube-dl directly?

This was sufficient for me on OS X 10.10.5:

    
    
      pip install instantmusic
      brew install ffmpeg
    
      instantmusic
      > ...some lyrics...
    
      afplay foo.mp3

------
unicornporn
Cool! But I'm looking at the video and this thing seems it automatically
transcodes the audio stream to MP3. Why not just put the highest quality AAC
stream available in an M4A container?

------
xerophyte12932
I am surprised it even supports non-english songs! Though I wonder which
languages are supported other than urdu/hindi

~~~
takee
If a song is on youtube (or any other website that youtube-dl searches in),
this will download it. Language is not a constraint here.

------
loueed
Going to try make this into a alfred workshop if anyone is interested

~~~
yask123
That would be awesome, I am interested :)

~~~
loueed
I'm running el capitan and youtube-dl is complaining about current user
access!

------
IMTDb
It's a CLI version of a tool like Youtune ([http://youtune-
downloader.com](http://youtune-downloader.com)) and probably many others.

------
mlamat
How do you get it to automatically play the file?

------
curiousjorge
didn't work for me. I also expected a Tupac song.

$ instantmusic

Enter songname/ lyrics/ artist.. or whatever

> used to be a thug

Making a Query Request!

Found: The Ambassador Christology Release Party I Used to be a Thug.mpg
11-22-99

Download song (y/n)? y

Downloading...

[generic] watch?v=YfE2-T1r-jw: Requesting header

[redirect] Following redirect to

[https://www.youtube.com/watch?v=YfE2-T1r-jw](https://www.youtube.com/watch?v=YfE2-T1r-jw)

[youtube] YfE2-T1r-jw: Downloading webpage

[youtube] YfE2-T1r-jw: Downloading video info webpage

[youtube] YfE2-T1r-jw: Extracting video information

[youtube] YfE2-T1r-jw: Downloading DASH manifest

[youtube] YfE2-T1r-jw: Downloading DASH manifest

ERROR: unable to open for writing: [Errno 13] Permission denied: u'The
Ambassador Christology Release Party I Used to be a Thug.mpg 11-22-
99-YfE2-T1r-jw.m4a.part

~~~
schoen
Maybe you ran the program when your current working directory was not
writable? Like you were in /bin or /usr or something when you ran it?

