diff --git a/CHANGES.md b/CHANGES.md index 71cc9bdbb..170d6ccb7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/spotdl/patcher.py b/spotdl/patcher.py index 1b1b744b3..d9e8762ad 100644 --- a/spotdl/patcher.py +++ b/spotdl/patcher.py @@ -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(): - 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): + backend_youtube_dl.YtdlPafy._old_process_streams = backend_youtube_dl.YtdlPafy._process_streams + backend_youtube_dl.YtdlPafy._process_streams = _process_streams diff --git a/spotdl/youtube_tools.py b/spotdl/youtube_tools.py index 4c81c72d6..7c331caac 100644 --- a/spotdl/youtube_tools.py +++ b/spotdl/youtube_tools.py @@ -18,7 +18,9 @@ # 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(): diff --git a/test/test_download_with_metadata.py b/test/test_download_with_metadata.py index 9c376c012..15534c230 100644 --- a/test/test_download_with_metadata.py +++ b/test/test_download_with_metadata.py @@ -176,6 +176,7 @@ def test_correct_container_for_m4a(self, filename_fixture, monkeypatch): 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( diff --git a/test/test_patcher.py b/test/test_patcher.py index baddd0ec8..f0f92aa08 100644 --- a/test/test_patcher.py +++ b/test/test_patcher.py @@ -3,7 +3,8 @@ import pytest -patcher.patch_pafy() +pafy_patcher = patcher.PatchPafy() +pafy_patcher.patch_getbestthumb() class TestPafyContentAvailable: pass