mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Merge pull request #539 from ritiek/patch-audiostream-urls
Patch bug in Pafy when fetching audiostreams with latest youtube-dl
This commit is contained in:
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
-
|
||||
|
||||
### Fixed
|
||||
-
|
||||
- Patch bug in Pafy when fetching audiostreams with latest youtube-dl ([@ritiek](https://github.com/ritiek)) (#539)
|
||||
|
||||
### Changed
|
||||
- Removed duplicate debug log entry from `internals.trim_song` ([@ritiek](https://github.com/ritiek)) (#519)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from pafy import backend_youtube_dl
|
||||
import pafy
|
||||
|
||||
from spotdl import internals
|
||||
@@ -20,12 +21,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 backend_youtube_dl.YtdlPafy._old_process_streams(self)
|
||||
|
||||
@classmethod
|
||||
def _content_available(cls, url):
|
||||
return internals.content_available(url)
|
||||
|
||||
def patch_pafy():
|
||||
|
||||
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):
|
||||
backend_youtube_dl.YtdlPafy._old_process_streams = backend_youtube_dl.YtdlPafy._process_streams
|
||||
backend_youtube_dl.YtdlPafy._process_streams = _process_streams
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -176,6 +176,7 @@ class TestFFmpeg:
|
||||
|
||||
|
||||
class TestAvconv:
|
||||
@pytest.mark.skip(reason="avconv is no longer provided with FFmpeg")
|
||||
def test_convert_from_m4a_to_mp3(self, filename_fixture, monkeypatch):
|
||||
monkeypatch.setattr("os.remove", lambda x: None)
|
||||
expect_command = "avconv -loglevel 0 -i {0}.m4a -ab 192k {0}.mp3 -y".format(
|
||||
|
||||
@@ -3,7 +3,8 @@ import pafy
|
||||
|
||||
import pytest
|
||||
|
||||
patcher.patch_pafy()
|
||||
pafy_patcher = patcher.PatchPafy()
|
||||
pafy_patcher.patch_getbestthumb()
|
||||
|
||||
class TestPafyContentAvailable:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user