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
|
### Fixed
|
||||||
-
|
- Patch bug in Pafy when fetching audiostreams with latest youtube-dl ([@ritiek](https://github.com/ritiek)) (#539)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Removed duplicate debug log entry from `internals.trim_song` ([@ritiek](https://github.com/ritiek)) (#519)
|
- 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
|
import pafy
|
||||||
|
|
||||||
from spotdl import internals
|
from spotdl import internals
|
||||||
@@ -20,12 +21,25 @@ def _getbestthumb(self):
|
|||||||
if self._content_available(url):
|
if self._content_available(url):
|
||||||
return 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
|
@classmethod
|
||||||
def _content_available(cls, url):
|
def _content_available(cls, url):
|
||||||
return internals.content_available(url)
|
return internals.content_available(url)
|
||||||
|
|
||||||
def patch_pafy():
|
|
||||||
pafy.backend_shared.BasePafy._bestthumb = None
|
class PatchPafy:
|
||||||
pafy.backend_shared.BasePafy._content_available = _content_available
|
def patch_getbestthumb(self):
|
||||||
pafy.backend_shared.BasePafy.getbestthumb = _getbestthumb
|
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
|
# More info: https://github.com/mps-youtube/pafy/pull/211
|
||||||
if pafy.__version__ <= "0.5.4":
|
if pafy.__version__ <= "0.5.4":
|
||||||
from spotdl import patcher
|
from spotdl import patcher
|
||||||
patcher.patch_pafy()
|
pafy_patcher = patcher.PatchPafy()
|
||||||
|
pafy_patcher.patch_getbestthumb()
|
||||||
|
pafy_patcher.patch_process_streams()
|
||||||
|
|
||||||
|
|
||||||
def set_api_key():
|
def set_api_key():
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ class TestFFmpeg:
|
|||||||
|
|
||||||
|
|
||||||
class TestAvconv:
|
class TestAvconv:
|
||||||
|
@pytest.mark.skip(reason="avconv is no longer provided with FFmpeg")
|
||||||
def test_convert_from_m4a_to_mp3(self, filename_fixture, monkeypatch):
|
def test_convert_from_m4a_to_mp3(self, filename_fixture, monkeypatch):
|
||||||
monkeypatch.setattr("os.remove", lambda x: None)
|
monkeypatch.setattr("os.remove", lambda x: None)
|
||||||
expect_command = "avconv -loglevel 0 -i {0}.m4a -ab 192k {0}.mp3 -y".format(
|
expect_command = "avconv -loglevel 0 -i {0}.m4a -ab 192k {0}.mp3 -y".format(
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import pafy
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
patcher.patch_pafy()
|
pafy_patcher = patcher.PatchPafy()
|
||||||
|
pafy_patcher.patch_getbestthumb()
|
||||||
|
|
||||||
class TestPafyContentAvailable:
|
class TestPafyContentAvailable:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user