Created
April 17, 2018 02:56
-
-
Save michael-msx/df2f3ac0ed366b478ff22cf752fdd388 to your computer and use it in GitHub Desktop.
code sample for python using vlc playing youtube playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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