From c225e5821ba04429fbce5f06b35c12ebc19a4666 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sun, 28 Apr 2019 15:09:42 +0530 Subject: [PATCH 1/4] Patch bug in Pafy when fetching audiostreams with latest youtube-dl --- spotdl/patcher.py | 21 +++++++++++++++++---- spotdl/youtube_tools.py | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/spotdl/patcher.py b/spotdl/patcher.py index 1b1b744b3..dde2fa376 100644 --- a/spotdl/patcher.py +++ b/spotdl/patcher.py @@ -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 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(): From a9477c7873d0228ef50c8da0b4856c39985ff840 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sun, 28 Apr 2019 15:26:18 +0530 Subject: [PATCH 2/4] Fix tests --- spotdl/patcher.py | 7 ++++--- test/test_patcher.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spotdl/patcher.py b/spotdl/patcher.py index dde2fa376..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 @@ -26,7 +27,7 @@ def _process_streams(self): 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) + return backend_youtube_dl.YtdlPafy._old_process_streams(self) @classmethod def _content_available(cls, url): @@ -40,5 +41,5 @@ def patch_getbestthumb(self): 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 + backend_youtube_dl.YtdlPafy._old_process_streams = backend_youtube_dl.YtdlPafy._process_streams + backend_youtube_dl.YtdlPafy._process_streams = _process_streams 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 From bb385a3bfd5baffdebd7e4ba364a5054f9f719b4 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sun, 28 Apr 2019 15:31:43 +0530 Subject: [PATCH 3/4] Skip avconv tests as it is no longer provided in later distros --- test/test_download_with_metadata.py | 1 + 1 file changed, 1 insertion(+) 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( From dfd48f75ce8068ebf39fda04617d78e03be6fd42 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sun, 28 Apr 2019 16:46:30 +0530 Subject: [PATCH 4/4] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)