Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/dynamic ytdl package #211

Merged
merged 5 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Other configuration options are::
threads_max = 16 : number of parallel threads to run
search_results = 15 : maximum number of search results to return
playlist_max_videos = 20 : maximum number of videos in a playlist to return
youtube_dl_package = [name] : alternative package to replace "youtube-dl"


Usage
Expand Down
1 change: 1 addition & 0 deletions mopidy_youtube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def get_config_schema(self):
schema["strict_autoplay"] = config.Boolean(optional=True)
schema["max_autoplay_length"] = config.Integer(optional=True)
schema["max_degrees_of_separation"] = config.Integer()
schema["youtube_dl_package"] = config.String(optional=True)
return schema

def setup(self, registry):
Expand Down
1 change: 1 addition & 0 deletions mopidy_youtube/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self, config, audio):
youtube.musicapi_enabled = config["youtube"]["musicapi_enabled"]
youtube.musicapi_cookie = config["youtube"].get("musicapi_cookie", None)
youtube_music.own_channel_id = youtube.channel
youtube.youtube_dl_package = config["youtube"]["youtube_dl_package"]
self.uri_schemes = ["youtube", "yt"]
self.user_agent = "{}/{}".format(Extension.dist_name, Extension.version)

Expand Down
1 change: 1 addition & 0 deletions mopidy_youtube/ext.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ autoplay_enabled = false
strict_autoplay = false
max_autoplay_length = 600
max_degrees_of_separation = 3
youtube_dl_package = youtube_dl
10 changes: 9 additions & 1 deletion mopidy_youtube/youtube.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import importlib
import json
import os
import re
import shutil
from concurrent.futures.thread import ThreadPoolExecutor

import pykka
import youtube_dl

from cachetools import TTLCache, cached
from mopidy.models import Image, ModelJSONEncoder

Expand All @@ -15,6 +16,8 @@
api_enabled = False
channel = None
cache_location = None
youtube_dl = None
youtube_dl_package = "youtube_dl"


def async_property(func):
Expand Down Expand Up @@ -292,6 +295,11 @@ def audio_url(self):
youtube_dl.
"""

global youtube_dl
if youtube_dl is None:
logger.debug(f"using {youtube_dl_package} package for youtube_dl")
youtube_dl = importlib.import_module(youtube_dl_package)

requiresUrl = self._add_futures([self], ["audio_url"])
if requiresUrl:
ytdl_options = {
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def config(tmp_path):
"strict_autoplay": False,
"max_autoplay_length": 600,
"max_degrees_of_separation": 3,
"youtube_dl_package": "youtube_dl",
},
"proxy": {},
}
Expand Down
3,957 changes: 3,956 additions & 1 deletion tests/fixtures/music/backend_search.yaml

Large diffs are not rendered by default.