Skip to content

Instantly share code, notes, and snippets.

@michael-msx
Created April 17, 2018 02:56
Show Gist options
  • Select an option

  • Save michael-msx/df2f3ac0ed366b478ff22cf752fdd388 to your computer and use it in GitHub Desktop.

Select an option

Save michael-msx/df2f3ac0ed366b478ff22cf752fdd388 to your computer and use it in GitHub Desktop.
code sample for python using vlc playing youtube playlist
from flask_api import FlaskAPI
import pafy
import vlc
app = FlaskAPI(__name__)
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
#Define VLC player
player = instance.media_list_player_new()
@app.route("/play/<string:vid>")
def play(vid):
v = pafy.new(vid)
stream = v.audiostreams;
# Define VLC media
media_list = instance.media_list_new()
for s in stream:
media = instance.media_new(s.url)
media_list.add_media(media)
player.set_media_list(media_list)
player.play()
return str(media_list.count()) + " song has been added to list"
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment