-1

I used pafy module to get the YouTube video's audio download links in m4a and webm formats and i want to steam without simply downloading it. How can i achieve it??

for example: for this link https://www.youtube.com/watch?v=3tmd-ClpJxA [Taylor Swift - Look What You Made Me Do] , I was shown this link of best quality in m4a format ( there is another format webm but I think m4a is best , isn't it? would love to hear opinion on it)

m4a: http://r2---sn-52vaavvoapox-itql.googlevideo.com/videoplayback?id=ded99df829692710&itag=140&source=youtube&ms=au&ei=DRvmWa-kDtr9oQObxIuACw&pl=24&mv=m&initcwndbps=285000&mn=sn-52vaavvoapox-itql&mm=31&ratebypass=yes&mime=audio/mp4&gir=yes&clen=4061037&lmt=1507168899082254&dur=255.651&mt=1508252315&signature=595AD7F495FC0DA98D8332BDF2A760A3CFA727C5.5FD2DE38A2F5575E0392BA54345D405999A72AE3&key=dg_yt0&ip=103.200.41.86&ipbits=0&expire=1508274029&sparams=ip,ipbits,expire,id,itag,source,ms,ei,pl,mv,initcwndbps,mn,mm,ratebypass,mime,gir,clen,lmt,dur

so how can I stream it instead of simply downloading it.

Moreover, if you think this kind question already been asked here, please accept my apologies and let me know it

Harry
  • 33
  • 1
  • 9
  • I am new to programming and I don't know how to deal this kind of stuff. – Harry Oct 17 '17 at 15:17
  • 1
    SO is not a free coding service, nor a tutorial website. I would encourage you to attempt the problem by yourself (study, follow tutorials, read docs) and try to solve it alone. When you get stuck on a particular problem, come back here and ask a specific question, and people will attempt to help you. Do no expect anybody to just give you a full solution. Hope this helps. Thanks! – N. Ivanov Oct 17 '17 at 15:19
  • thank you very much and I don;t simply need anyone write solution for it. I need some suggestions like how to deal with this audio files,streaming .. – Harry Oct 17 '17 at 15:21
  • Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before attempting to ask more questions. **You really need to read the links on how the site works. You will get pushback and very low quality help if any if you insist on not following the sites rules on how it works and is expected to be used.** You have many questions asking for *suggestions* that is **not how the site works**, you have been told over and over in the comments of other questions as well. –  Jan 08 '18 at 07:03
  • Please read [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) before attempting to ask more questions. –  Jan 08 '18 at 07:04
  • [Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.](http://meta.stackoverflow.com/questions/254393) –  Jan 08 '18 at 07:04

2 Answers2

2

If you are simply looking to play/stream audio from specific URL , you can try vlc binding for python. More details here

It can be installed as pip install python-vlc

Here is a sample code that stream audio directly from URL. player object has added advantage of audio-player like controls like pause, resume, stop etc.

URL used is m4a url as stated in question.

Source Code

import vlc
import time
url = "http://r2---sn-q4fl6nlr.googlevideo.com/videoplayback?id=ded99df829692710&itag=140&source=youtube&ei=DRvmWa-kDtr9oQObxIuACw&pl=32&ratebypass=yes&mime=audio/mp4&gir=yes&clen=4061037&lmt=1507168899082254&dur=255.651&signature=4380D44827E745850E8034A17DD2CF71493515B2.49EE0269B463E530D2C05D79E658319E3354F4B5&key=cms1&ip=103.200.41.86&ipbits=0&expire=1508274029&sparams=clen,dur,ei,expire,gir,id,initcwndbps,ip,ipbits,ipbypass,itag,lmt,mime,mip,mm,mn,ms,mv,pl,ratebypass,source&rm=sn-52vaavvoapox-itql7l,sn-h55z7z&req_id=ac17cbf87900a3ee&redirect_counter=2&fexp=23702512&cms_redirect=yes&ipbypass=yes&mip=2605:6000:ec02:7e00:6d00:a5a1:a309:abb6&mm=30&mn=sn-q4fl6nlr&ms=nxu&mt=1508259877&mv=m"

#define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')

#Define VLC player
player=instance.media_player_new()

#Define VLC media
media=instance.media_new(url)

#Set player media
player.set_media(media)

#Play the media
player.play()

some of player controls

>>> play.pause()  #pause play back
>>> player.play() #resume play back
>>> player.stop() #stop play back
Anil_M
  • 10,893
  • 6
  • 47
  • 74
  • I tried this already but nothing happened(vlc didn't open :( ). would you guess what was the wrong with me. – Harry Oct 18 '17 at 07:40
  • Well, I tried same code again and looks like M4A url is not working anymore. It may have gotten changed. check status with `player.get_state()`. It will show `error` or `playing` etc. I tried using this url and audio works fine. url = 'http://aska.ru-hoster.com:8053/autodj'. May want to use this as baseline. – Anil_M Oct 18 '17 at 15:30
  • Whoever downvoted this solution, it will be "REALLY" helpful if you can at least comment on the reason for down-voting. Else , the down-voting does not add any value to the answer or conversation. – Anil_M Jan 09 '18 at 15:02
0

For opening the website you could have a shortcut on your desktop to the website or anywhere for that matter and from there you could use this code to open it. Hope this helps.

import pyglet
import os
os.system("start \\\\ph-fss1\Students\S39055\Desktop\\love.jpg")

music = pyglet.resource.media('\\\\ph-fss1\Students\S39055\Desktop\\love.jpg')
music.play()

pyglet.app.run()
love = True

if love == True:
    os.system("start \\\\ph-fss1\Students\S39055\Desktop\\love.jpg")

music = pyglet.resource.media('\\\\ph-fss1\Students\S39055\Desktop\\love.jpg')
music.play()

pyglet.app.run()