bskit
bskit

Reputation: 1

Trying to livestream youtube through python

I am trying to stream youtube through python bypassing the download part. However i am getting an error from my current solution. The code is :

import pafy, vlc
url = str(raw_input())
video = pafy.new(str(url))
best = video.getbest()
playurl = best.url()
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(playurl)
Media.get_mrl()  
player.set_media(Media)
player.play()

the error i get is :

  File "musicdownplay.py", line 5, in <module>
  playurl = best.url()
  TypeError: 'unicode' object is not callable

i have declared as a string so i cant find the error

Upvotes: 0

Views: 258

Answers (1)

Mike Scotty
Mike Scotty

Reputation: 10782

According to the API, video.getbest() returns a Stream object.

And a Stream object has an attribute Stream.url, not a function Stream.url().

From the docs:

Stream.url

The direct access URL of the stream. This can be used to stream the media in mplayer or vlc, or for downloading with wget or curl. To download directly, use the Stream.download() method.

TL;DR: Change playurl = best.url() to playurl = best.url

Upvotes: 1

Related Questions