Playing youtube video

This forum is about all development around libVLC.
sidithelion
New Cone
New Cone
Posts: 2
Joined: 09 Nov 2020 15:45

Playing youtube video

Postby sidithelion » 09 Nov 2020 18:27

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! :)

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: Playing youtube video

Postby mfkl » 10 Nov 2020 04:46

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?
https://mfkl.github.io

sidithelion
New Cone
New Cone
Posts: 2
Joined: 09 Nov 2020 15:45

Re: Playing youtube video

Postby sidithelion » 12 Nov 2020 16:46

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.

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: Playing youtube video

Postby mfkl » 16 Nov 2020 04:11

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.
https://mfkl.github.io


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 22 guests