mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Resolving bug in downloader
This commit is contained in:
parent
e59efb0010
commit
1dc708a86b
@ -14,21 +14,18 @@ class Downloader():
|
|||||||
'playliststart': 0,
|
'playliststart': 0,
|
||||||
'extract_flat': False,
|
'extract_flat': False,
|
||||||
'playlistend': config.MAX_PLAYLIST_LENGTH,
|
'playlistend': config.MAX_PLAYLIST_LENGTH,
|
||||||
'quiet': True
|
|
||||||
}
|
}
|
||||||
__YDL_OPTIONS_EXTRACT = {'format': 'bestaudio/best',
|
__YDL_OPTIONS_EXTRACT = {'format': 'bestaudio/best',
|
||||||
'default_search': 'auto',
|
'default_search': 'auto',
|
||||||
'playliststart': 0,
|
'playliststart': 0,
|
||||||
'extract_flat': True,
|
'extract_flat': True,
|
||||||
'playlistend': config.MAX_PLAYLIST_LENGTH,
|
'playlistend': config.MAX_PLAYLIST_LENGTH,
|
||||||
'quiet': True
|
|
||||||
}
|
}
|
||||||
__YDL_OPTIONS_FORCE_EXTRACT = {'format': 'bestaudio/best',
|
__YDL_OPTIONS_FORCE_EXTRACT = {'format': 'bestaudio/best',
|
||||||
'default_search': 'auto',
|
'default_search': 'auto',
|
||||||
'playliststart': 0,
|
'playliststart': 0,
|
||||||
'extract_flat': False,
|
'extract_flat': False,
|
||||||
'playlistend': config.MAX_PLAYLIST_LENGTH,
|
'playlistend': config.MAX_PLAYLIST_LENGTH,
|
||||||
'quiet': True
|
|
||||||
}
|
}
|
||||||
__BASE_URL = 'https://www.youtube.com/watch?v={}'
|
__BASE_URL = 'https://www.youtube.com/watch?v={}'
|
||||||
|
|
||||||
@ -38,7 +35,7 @@ class Downloader():
|
|||||||
self.__not_extracted_not_keys = ['entries']
|
self.__not_extracted_not_keys = ['entries']
|
||||||
self.__playlist_keys = ['entries']
|
self.__playlist_keys = ['entries']
|
||||||
|
|
||||||
async def finish_one_song(self, song: Song) -> Song:
|
def finish_one_song(self, song: Song) -> Song:
|
||||||
"""Receives a song object, finish his download and return it"""
|
"""Receives a song object, finish his download and return it"""
|
||||||
if song.identifier == None:
|
if song.identifier == None:
|
||||||
return None
|
return None
|
||||||
@ -46,7 +43,7 @@ class Downloader():
|
|||||||
if is_url(song.identifier):
|
if is_url(song.identifier):
|
||||||
song_info = self.__download_url(song.identifier)
|
song_info = self.__download_url(song.identifier)
|
||||||
else:
|
else:
|
||||||
song_info = await self.__download_title(song.identifier)
|
song_info = self.__download_title(song.identifier)
|
||||||
|
|
||||||
song.finish_down(song_info)
|
song.finish_down(song_info)
|
||||||
return song
|
return song
|
||||||
@ -65,23 +62,16 @@ class Downloader():
|
|||||||
"""
|
"""
|
||||||
if is_url(url): # If Url
|
if is_url(url): # If Url
|
||||||
options = Downloader.__YDL_OPTIONS_EXTRACT
|
options = Downloader.__YDL_OPTIONS_EXTRACT
|
||||||
options['extract_flat'] = False
|
|
||||||
with YoutubeDL(options) as ydl:
|
with YoutubeDL(options) as ydl:
|
||||||
try:
|
try:
|
||||||
print('Normal Extraction')
|
|
||||||
print('A')
|
|
||||||
extracted_info = ydl.extract_info(url, download=False)
|
extracted_info = ydl.extract_info(url, download=False)
|
||||||
print('B')
|
|
||||||
if self.__failed_to_extract(extracted_info):
|
if self.__failed_to_extract(extracted_info):
|
||||||
print('Forcing Extraction')
|
|
||||||
extracted_info = self.__get_forced_extracted_info(url)
|
extracted_info = self.__get_forced_extracted_info(url)
|
||||||
|
|
||||||
if self.__is_music(extracted_info):
|
if self.__is_music(extracted_info):
|
||||||
print('Is Music')
|
|
||||||
return [extracted_info['original_url']]
|
return [extracted_info['original_url']]
|
||||||
|
|
||||||
elif self.__is_multiple_musics(extracted_info):
|
elif self.__is_multiple_musics(extracted_info):
|
||||||
print('Multiple Musics')
|
|
||||||
songs = []
|
songs = []
|
||||||
for song in extracted_info['entries']:
|
for song in extracted_info['entries']:
|
||||||
songs.append(self.__BASE_URL.format(song['id']))
|
songs.append(self.__BASE_URL.format(song['id']))
|
||||||
@ -92,7 +82,7 @@ class Downloader():
|
|||||||
return []
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'DEVELOPER NOTE -> Error Extracting Music: {e}')
|
print(f'DEVELOPER NOTE -> Error Extracting Music: {e}')
|
||||||
return None
|
raise
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -141,7 +131,6 @@ class Downloader():
|
|||||||
fs = {loop.run_in_executor(executor, __download_func, song)}
|
fs = {loop.run_in_executor(executor, __download_func, song)}
|
||||||
await asyncio.wait(fs=fs, return_when=asyncio.ALL_COMPLETED)
|
await asyncio.wait(fs=fs, return_when=asyncio.ALL_COMPLETED)
|
||||||
|
|
||||||
@run_async
|
|
||||||
def __download_title(self, title: str) -> dict:
|
def __download_title(self, title: str) -> dict:
|
||||||
"""Download a music full information using his name.
|
"""Download a music full information using his name.
|
||||||
|
|
||||||
|
|||||||
@ -84,9 +84,18 @@ class Player(commands.Cog):
|
|||||||
if provider == Provider.YouTube:
|
if provider == Provider.YouTube:
|
||||||
links = await self.__down.extract_info(links[0])
|
links = await self.__down.extract_info(links[0])
|
||||||
|
|
||||||
songs_quant = len(links)
|
if len(links) == 0:
|
||||||
|
embed = Embed(
|
||||||
|
title=config.ERROR_TITLE,
|
||||||
|
description="This video is unavailable",
|
||||||
|
colours=config.COLOURS['blue'])
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return None
|
||||||
|
|
||||||
|
songs_quant = 0
|
||||||
for info in links:
|
for info in links:
|
||||||
song = self.__playlist.add_song(info, requester)
|
song = self.__playlist.add_song(info, requester)
|
||||||
|
songs_quant += 1
|
||||||
|
|
||||||
songs_preload = self.__playlist.songs_to_preload
|
songs_preload = self.__playlist.songs_to_preload
|
||||||
await self.__down.preload(songs_preload)
|
await self.__down.preload(songs_preload)
|
||||||
@ -100,7 +109,7 @@ class Player(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if songs_quant == 1:
|
if songs_quant == 1:
|
||||||
song = await self.__down.finish_one_song(song)
|
song = self.__down.finish_one_song(song)
|
||||||
pos = len(self.__playlist)
|
pos = len(self.__playlist)
|
||||||
|
|
||||||
if song.problematic:
|
if song.problematic:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user