-1

I'm trying to play a random youtube video using pafy and vlc. But when I'm executing the script :

        import vlc 
        import cv2            

        url = "Youtube_URL"            
        video = pafy.new(url)
        best = video.getbest()
        playurl = best.url
        ins = vlc.Instance()
        player = ins.media_player_new()
        Media = ins.media_new(playurl)
        Media.get_mrl()
        player.set_media(Media)
        player.play()

I'm getting below error :

AttributeError: 'module' object has no attribute 'Instance'

I've tried a lot but vlc.Instance() is not working, I don't know why. I will appreciate any help/inputs.

  • "Instance = vlc.Instance()" won't work as you have to assign a variable and not a class name to a new object. Try to "instance = vlc.Instance()" instead. – Hagbard Mar 18 '19 at 10:37
  • my bad :( I have modified the code, still the same error. – Nagesh Singh Chauhan Mar 18 '19 at 10:56
  • 1
    Possible duplicate of [vlc.Instance: AttributeError("module 'vlc' has no attribute 'Instance'")](https://stackoverflow.com/questions/52405364/vlc-instance-attributeerrormodule-vlc-has-no-attribute-instance) – Hagbard Mar 18 '19 at 11:03
  • Does this answer (https://stackoverflow.com/questions/52405364/vlc-instance-attributeerrormodule-vlc-has-no-attribute-instance) help you out? – Hagbard Mar 18 '19 at 11:03
  • @Hagbard: I have already checked these answers, none are working. – Nagesh Singh Chauhan Mar 18 '19 at 12:24

1 Answers1

1

don't know if you have solved the problem already. I don't really know why this happens. I only figured out that it happens when you execute pip3 install python-vlc(or something like that).

I think they might have changed some methods and objects in more recent versions.However this works for me. Here is the oficial link where I downloaded it from:

https://pypi.org/project/python-vlc/1.1.2/#files

Get the tar.gz file, extract the content and change directory, then run: sudo python3 install setup.py

You have to uninstall first the module that you installed previously: python3 uninstall vlc and python3 uninstall python-vlc. Install the one that you downloaded and then it might ask you to install again module vlc(not python-vlc). Hope this helps!

pablo
  • 26
  • 1