store original url for nowplaying, fix ytsearch due to yt-dlp api changes

This commit is contained in:
a 2023-01-29 18:46:37 -06:00
parent 6a7ec8eef7
commit eb6ed9e784

View file

@ -46,6 +46,7 @@ class Track:
source: str,
requester: discord.User,
title: str = None,
original_url: str = None,
duration = None,
author: str = None,
author_icon: str = None,
@ -54,6 +55,7 @@ class Track:
self.source = source
self.requester = requester
self.title = title
self.original_url = original_url
self.duration = duration
self.author = author
self.data = data
@ -251,7 +253,7 @@ class Music(Cog):
# Create Track objects
tracks = []
for entry in entries:
url = entry["url"]
source = entry["url"]
title = entry["title"]
duration = None
data = entry
@ -273,9 +275,10 @@ class Music(Cog):
duration = s + 60*m + 3600*h
tracks.append(
Track(
source=url,
source=source,
requester=ctx.message.author,
title=title,
original_url=url,
duration=duration,
data=data
)
@ -367,13 +370,15 @@ class Music(Cog):
for i, result in enumerate(self.search_results['entries']):
if result['live_status'] == "is_upcoming":
result: dict
if result.get('live_status') == "is_upcoming":
continue # skip YT Premieres
title = result['title']
duration = format_time(int(result['duration']))
uploader = result['uploader']
views = "{:,}".format(result['view_count'])
title = result.get('title', '<no title found>')
duration = format_time(int(result.get('duration'))) if ('duration' in result) else '?:??'
uploader = result.get('channel', '<no uploader found>')
views = "{:,}".format(result.get('view_count')) if ('view_count' in result) else '<no view count found>'
image = result['thumbnails'][-1]['url']
height = result['thumbnails'][-1]['height']
width = result['thumbnails'][-1]['width']
@ -665,7 +670,7 @@ class Music(Cog):
source: Player = ctx.voice_client.source
embed = discord.Embed(
title=f"{self.track.title}",
url=f"{self.track.source}" if self.track.source.startswith('http') else None,
url=f"{self.track.original_url}" if self.track.original_url else None,
).add_field(
name="Progress",
value=f"{source.progress}",