Page 1 of 1

Playing youtube video

Posted: 09 Nov 2020 18:27
by sidithelion
I'm programming a music player with python, tkinter and vlc. My idea is to streem a youtube video with it's URL, which I was doing with pafy. I have downloaded youtube-dcl, since the takedown of youtube-dl, but pafy doesn't work to get the best URL. So, I'm trying to do it directly with the vlc module. I have tried the following:

Code: Select all

import vlc import time url = "https://www.youtube.com/watch?v=s5TIulzXoXo" instance = vlc.Instance() media = instance.media_new(url) player = instance.media_player_new() player.set_media(media) player.play()
I have asked in StackOverflow: https://stackoverflow.com/questions/646 ... ube-videos
The only answer says that I need to parse the media and play it's first subitem, but the code doesn't work. Instead of parse() I have used parse_with_options() and instead of first() I have tried item_at_index(0), but doesn't work anyway.... I have looked for examples or information, but I can't find much. Can you help me, please? Thanks! :)

Re: Playing youtube video

Posted: 10 Nov 2020 04:46
by mfkl
Hi,

Can you share the code you tried with the parse and play sub item advice?
Can you enable full verbose logs and share them here?

Re: Playing youtube video

Posted: 12 Nov 2020 16:46
by sidithelion
This is the code with similar methods :

Code: Select all

import vlc url = "https://www.youtube.com/watch?v=s5TIulzXoXo" instance = vlc.Instance("--verbose=2") media = instance.media_new(url) #these are the new lines, parsing and getting 1st subitem media.parse_with_options(0, 0) sub = media.subitems() first = sub.item_at_index(0) player = instance.media_player_new() player.set_media(first) player.play()
I don't know how exactly enable verbose logs. Libvlc docs says what I have used: passing "--verbose=2" as argument when creating the object.
The output of this code is -1. If I use player.is_playing(), the result is 0, so NOT playing. And when I print type(first) says NoneType.

Re: Playing youtube video

Posted: 16 Nov 2020 04:11
by mfkl
You enabled verbose logs with --verbose=2, now you need to find them so you can share them here. Try listening to stdout or stderr.