Patch bug in Pafy when fetching audiostreams with latest youtube-dl

This commit is contained in:
Ritiek Malhotra
2019-04-28 15:09:42 +05:30
parent d61309b0ce
commit c225e5821b
2 changed files with 20 additions and 5 deletions

View File

@@ -20,12 +20,25 @@ def _getbestthumb(self):
if self._content_available(url):
return url
def _process_streams(self):
for format_index in range(len(self._ydl_info['formats'])):
try:
self._ydl_info['formats'][format_index]['url'] = self._ydl_info['formats'][format_index]['fragment_base_url']
except KeyError:
pass
return pafy.backend_youtube_dl.YtdlPafy._old_process_streams(self)
@classmethod
def _content_available(cls, url):
return internals.content_available(url)
def patch_pafy():
pafy.backend_shared.BasePafy._bestthumb = None
pafy.backend_shared.BasePafy._content_available = _content_available
pafy.backend_shared.BasePafy.getbestthumb = _getbestthumb
class PatchPafy:
def patch_getbestthumb(self):
pafy.backend_shared.BasePafy._bestthumb = None
pafy.backend_shared.BasePafy._content_available = _content_available
pafy.backend_shared.BasePafy.getbestthumb = _getbestthumb
def patch_process_streams(self):
pafy.backend_youtube_dl.YtdlPafy._old_process_streams = pafy.backend_youtube_dl.YtdlPafy._process_streams
pafy.backend_youtube_dl.YtdlPafy._process_streams = _process_streams

View File

@@ -18,7 +18,9 @@ pafy.g.opener.addheaders.append(("Range", "bytes=0-"))
# More info: https://github.com/mps-youtube/pafy/pull/211
if pafy.__version__ <= "0.5.4":
from spotdl import patcher
patcher.patch_pafy()
pafy_patcher = patcher.PatchPafy()
pafy_patcher.patch_getbestthumb()
pafy_patcher.patch_process_streams()
def set_api_key():