Saturday 9 November 2013

Listen tracks from youtube in mpd

I don't have my collection of music in the office. Last.fm no longer offers its great radio.

Luckily, there are tons of tracks on youtube.
Luckily, I use linux and incredibly powerful mpd player, so I don't have to keep youtube open

Suppose, you want to listen to some vocal trance on youtube.

Use youtube-dl to determine what formats are available
$ youtube-dl -f http://www.youtube.com/watch?v=HS5fHWmzqIg
[youtube] Setting language
[youtube] HS5fHWmzqIg: Downloading video webpage
[youtube] HS5fHWmzqIg: Downloading video info webpage
[youtube] HS5fHWmzqIg: Extracting video information
Available formats:
22      :       mp4     [720x1280]
18      :       mp4     [360x640]
43      :       webm    [360x640]
5       :       flv     [240x400]
36      :       3gp     [240x320]
17      :       3gp     [144x176]
136     :       mp4     [720p] (DASH Video)
135     :       mp4     [480p] (DASH Video)
134     :       mp4     [360p] (DASH Video)
133     :       mp4     [240p] (DASH Video)
160     :       mp4     [192p] (DASH Video)
141     :       m4a     [256k] (DASH Audio)
172     :       webm    [256k] (DASH Audio)
140     :       m4a     [128k] (DASH Audio)
171     :       webm    [128k] (DASH Audio)
139     :       m4a     [48k] (DASH Audio)

There are 5 audio formats for this video. 141th has highest bitrate. So all we have to do, is to get real URL for this format and feed it to mpd
$ mpc add `youtube-dl -f141 -g http://www.youtube.com/watch?v=HS5fHWmzqIg`

That's all, track from youtube is already in your mpd playlist. Enjoy!

6 comments:

  1. Hi,

    I tried to add the youtube url with this line ...

    mpc add `youtube-dl -f140 -g http://www.youtube.com/watch?v=HS5fHWmzqIg`

    ... but i get this error message:

    error: unsupported URI scheme

    Do you know what happend?

    ReplyDelete
    Replies
    1. Hi,

      looks like your mpd has been compiled without libcurl support. You need one to support http streaming.



      Delete
    2. http streaming works. These links are ok for my mpd:

      http://ber.radiostream.de:36795
      http://onair.krone.at/kronehit.mp3
      ...
      and so on but youtube-dl won't

      Delete
    3. youtube-dl will return link with https scheme. Perhaps, there is some issue with https support.

      What is your mpd version? Do you compile mpd from source? If yes, what compilation flags do you use? If no, what OS do use? Libcurl version?

      Also, try running youtube-dl itself with the mentioned video, and check that link it returns is correct.
      Running mpc with -v option might also bring some light into this.

      Delete
    4. OS: Linnux Mint Mate 16 (3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux)
      MPD-Version: mpd (MPD: Music Player Daemon) 0.17.4

      I installed mpd with "sudo apt-get install mpd"
      I don't know the version of libcurl. I installed it with "sudo apt-get install libcurl3"

      when i try this ...
      mpc -v add `youtube-dl -f140 -g http://www.youtube.com/watch?v=HS5fHWmzqIg'
      ... i got this message:
      adding: https://r7---sn-bvvbax-8pxl.googlevideo.com/videoplayback?source=youtube&clen=75860417&itag=140&key=yt5&sparams=clen%2Cdur%2Cgir%2Cid%2Cip%2Cipbits%2Citag%2Clmt%2Crequiressl%2Csource%2Cupn%2Cexpire&sver=3&ipbits=0&upn=qnxfTa4uvKw&expire=1405594800&id=o-AD5H3lpzUOgN1yiC-CKpmNdJFKzcZH2i-SR2iFl4pCc5&requiressl=yes&dur=4776.460&lmt=1389150426013894&signature=CDE19C8CB6A6B0E745ABB55BE234EE3128FB52AB.E8688DF9637DFCFD4E8F504626E87B8BE87918FF&mws=yes&gir=yes&ip=80.108.164.205&ms=au&mt=1405572056&fexp=902408%2C921909%2C924213%2C924217%2C924222%2C927622%2C930008%2C934024%2C934030%2C940647%2C941415&mv=m&ratebypass=yes
      error: unsupported URI scheme

      and when i try this ...
      youtube-dl http://www.youtube.com/watch?v=HS5fHWmzqIg
      ... i got this:
      [youtube] Setting language
      [youtube] HS5fHWmzqIg: Downloading video webpage
      [youtube] HS5fHWmzqIg: Downloading video info webpage
      [youtube] HS5fHWmzqIg: Extracting video information
      [download] Destination: Best of Female Vocal Trance 2013 ❤ CHILL OUT ENERGY CHAPTER 5 ❤ by STACO-HS5fHWmzqIg.mp4
      [download] 100% of 536.53MiB in 01:25

      Delete
  2. You have made some really great points here. I hope numerous people are able to acquire access to this information. This is great quality of writing is deserving of attention. www.buyyoutubesubscribers.in

    ReplyDelete