Recently I have created a python script to play youtube videos using pafy and python-vlc.
The below code is the script:
# importing vlc module
import vlc
# importing pafy module
import pafy
# url of the video
url = "https://www.youtube.com/watchv=il_t1WVLNxk&list=PLqM7alHXFySGqCvcwfqqMrteqWukz9ZoE"
# creating pafy object of the video
video = pafy.new(url)
# getting stream at index 0
best = video.streams[0]
# creating vlc media player object
media = vlc.MediaPlayer(best.url)
# start playing video
media.play()
And after running it I get this error:
Traceback (most recent call last):
File "C:\Users\harsh\Desktop\don't.py", line 11, in <module>
video = pafy.new(url)
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\pafy.py", line 124, in new
return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\backend_youtube_dl.py", line 31, in __init__
super(YtdlPafy, self).__init__(*args, **kwargs)
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\backend_shared.py", line 97, in __init__
self._fetch_basic()
File "C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy\backend_youtube_dl.py", line 54, in _fetch_basic
self._dislikes = self._ydl_info['dislike_count']
KeyError: 'dislike_count'
Please help me with this error. If you have any questions please ask.
The dislike button on youtube has been made private, so some modification on backend_youtube_dl.py is required to run pafy.
Navigate to C:\Users\harsh\AppData\Local\Programs\Python\Python310\lib\site-
packages\pafy
Open backend_youtube_dl.py file
Comment or remove this code: self._dislikes = self._ydl_info['dislike_count']
Besides the dislike function, everything else works fine.
It worked for me and hope the same goes for everyone.
Pafy its very usefull tool if you want to extract information about youtube video like, retrieve metadata such as viewcount, duration, rating, author, thumbnail, keywords or Download video or audio at requested resolution.
But it doesnt work(at least untill now) to play a video.
If you want to play a Yt video inside your code use it:
import webbrowser
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
webbrowser.open(url)
Related
I'm trying to build a music player using Python Tkinter, but I really facing issues while I set the song path it seems some errors.
Here is my code:
song = song_box.get(ACTIVE)
song = f'C:/Users/parve/PycharmProjects/gf/songs/{song}.ogg'
pygame.mixer.music.load(song)
pygame.mixer.music.play(loops=0)
Here is the error I face:
File "C:/Users/parve/PycharmProjects/gf/music.py", line 25, in play
pygame.mixer.music.load(song)
pygame.error: Failed loading libvorbisfile-3.dll: The specified module could not be found.
I want to get the live stream from youtube, and for that, I have used opencv along with the package vidgear. But while running the code, I am getting the following error. I am sure that there is no problem with the URL.
I have tried with pafy and streamlink. Even though both have given the result but after few frames, it was getting stuck and I want sequential frames without any pause.
import cv2
from vidgear.gears import CamGear
stream = CamGear(source="https://www.youtube.com/watch?v=VIk_6OuYkSo", y_tube =True, time_delay=1, logging=True).start() # YouTube Video URL as input
while True:
frame = stream.read()
if frame is None:
break
cv2.imshow("Output Frame", frame)
key = cv2.waitKey(30)
if key == ord("q"):
break
cv2.destroyAllWindows()
stream.stop()
Error output ::
'NoneType' object has no attribute 'extension'
Traceback (most recent call last):
File "C:\Users\CamfyVision\AppData\Local\Programs\Python\Python36\lib\site-packages\vidgear\gears\camgear.py", line 120, in __init__
print('Extension: {}'.format(_source.extension))
AttributeError: 'NoneType' object has no attribute 'extension'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "DronrStream.py", line 4, in <module>
stream = CamGear(source="https://www.youtube.com/watch?v=VIk_6OuYkSo", y_tube =True, time_delay=1, logging=True).start() # YouTube Video URL as input
File "C:\Users\CamfyVision\AppData\Local\Programs\Python\Python36\lib\site-packages\vidgear\gears\camgear.py", line 125, in __init__
raise ValueError('YouTube Mode is enabled and the input YouTube Url is invalid!')
ValueError: YouTube Mode is enabled and the input YouTube Url is invalid!
#Adithya Raj I'm the author of VidGear Video Processing python library.
This error is because of a bug with YouTube live streams and is already been resolved in this commit. Kindly update vidgear as follows:
pip install -U vidgear
i was try to run your script and i got error in URL link but when i replace with other URL link then you're script works fine no error. have look pics
I'm new to Slack bots (familiar with Discord.py). I am using the Slackbot package (https://github.com/lins05/slackbot) to create my Python slack bot.
Followed the example on their page, installed the package using pip install slackbot, went to the path of the installation, created a slackbot_settings.py (with specified tags they mentioned) and run.py in the main directory and mybot.py (with example commands they showed on their page to test), but I can't initialize the bot. I tried to run the bot using python run.py but get the following error:
Traceback (most recent call last):
File "run.py", line 23, in
main()
File "run.py", line 20, in main
bot.run()
File "/Users/xxx/anaconda3/lib/python3.5/site-packages/slackbot/bot.py", line 32, in run
self._plugins.init_plugins()
File "/Users/xxx/anaconda3/lib/python3.5/site-packages/slackbot/manager.py", line 31, in init_plugins
self._load_plugins(plugin)
File "/Users/xxx/anaconda3/lib/python3.5/site-packages/slackbot/manager.py", line 47, in _load_plugins
path_name = importlib_find(plugin)
File "/Users/xxx/anaconda3/lib/python3.5/importlib/util.py", line 89, in find_spec
return _find_spec(fullname, parent.path)
AttributeError: module 'mybot' has no attribute 'path'
mybot.py has the following lines:
from slackbot.bot import respond_to
from slackbot.bot import listen_to
import re
#respond_to('hi', re.IGNORECASE)
def hi(message):
message.reply('I can understand hi or HI!')
# react with thumb up emoji
message.react('+1')
#respond_to('I love you')
def love(message):
message.reply('I love you too!')
#listen_to('Can someone help me?')
def help(message):
# Message is replied to the sender (prefixed with #user)
message.reply('Yes, I can!')
# Message is sent on the channel
message.send('I can help everybody!')
# Start a thread on the original message
message.reply("Here's a threaded reply", in_thread=True)
Where am I going wrong? I've tried asking the developer but got no answer.
The bot apparently can not find your mybot plugin. Assuming mybot.py is in the same folder than run.py change the entry in PLUGINS to 'mybot'. Then it should work.
Full example of slackbot_settings.py:
DEFAULT_REPLY = "Sorry but I didn't understand you"
PLUGINS = [
'mybot'
]
im trying to display a video on a pygame surface using the pyglet library to import, play and then convert the frames into an image. I managed to battle my way through installing avbin but now I'm hitting a type error with my code
def cutscene(window_surface, filename):
player = pyglet.media.Player()
source = pyglet.media.load(filename)
player.queue(source)
player.play()
pygame.display.flip()
while True:
window_surface.fill(0)
player.dispatch_events()
tex = player.get_texture()
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
window_surface.blit(img, (0,0))
pygame.display.flip()
when I run, i get the following error
Traceback (most recent call last):
File "dino_game.py", line 348, in <module>
main()
File "dino_game.py", line 45, in main
cutscene(window_surface, "Cutscenes/Cutscene1.mov")
File "dino_game.py", line 68, in cutscene
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
AttributeError: 'NoneType' object has no attribute 'get_image_data'
Nothing that I do seems to solve it
EDIT: So after testing both this file and the sample files provided by pyglet, it seems that I get this error no matter what filetype I use, could this be an installation error with pyglet or AVbin?
Gave up trying to use pyglet and swapped to VLC where I just have to pass the window ID for the game and it does the rest for me
VLC script: https://wiki.videolan.org/Python_bindings/
Edit: Trying to get these libraries to work in python 3.3 was clearly the wrong approach, and my problem now is entirely different so I'll just re-ask it in a new question.
I want to be able to edit ID3 tags of mp3 files with python commands, for example something like setAlbumName("folderPath\song.mp3", "albumname"). So far I've tried Mutagen, PyID3, pytagger, eyeD3, and they all seem to be outdated because the installation fails due to syntax errors. I tried to fix it in eyeD3, but I hit a dead end: http://i41.tinypic.com/o6zklv.png (second screenshot from after I had fixed all the prints and "except Error, e" and so on).
I tried the same with Mutagen, but I ran into a wall there as well when replacing "raise KeyError, key" with "raise KeyError as key" didn't work.
I didn't even know what to make of this one (pytagger): http://i41.tinypic.com/29fz7mh.png
It seems to suggest that there's something wrong with my python installation? Not getting into that.
So, would anyone like to point me to an ID3 package that works, or have a go at fixing an outdated one?
(Also, I tried both "python setup.py install" and "setup.py install" and it seemed to make no difference. I'm on windows 8.)
Edit: From the screenshot below, plus the source code (mutagen with python 2.7.5)
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.pprint()
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 5, in <module>
audio.pprint()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 138, in pprint
try: tags = self.tags.pprint()
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 190, in pprint
frames = list(map(Frame.pprint, self.values()))
TypeError: unbound method pprint() must be called with Frame instance as first a
rgument (got str instance instead)
_
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 7, in <module>
audio.save()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 132, in save
return self.tags.save(filename, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 370, in save
framedata = [self.__save_frame(frame) for (key, frame) in frames]
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 461, in __save_frame
framedata = frame._writeData()
AttributeError: 'str' object has no attribute '_writeData'
mutagen works great for me with Python 2.7.
examples:
https://code.google.com/p/mutagen/wiki/Tutorial
from mutagen.mp3 import MP3
audio = MP3("example.mp3")
audio["title"] = "An example"
audio.pprint()
audio.save()
p.s. please post code samples so people can help.. not links to screenshots.
p.p.s. it looks like you are trying to install Python2 libs into Python3.
Mutagen also has an EasyID3 tool, which handles simple tasks like changing the file's title:
from mutagen.easyid3 import EasyID3
f = EasyID3("file.mp3")
f["title"] = u"Some title"
f.save()
Works like a charm. But it has very restricted functionality.
See more examples at http://code.google.com/p/mutagen/wiki/Tutorial