Allow the suffix for youtube searches to be configurable. Fixes #3
This commit is contained in:
parent
0df93ac758
commit
391562fd3a
3 changed files with 18 additions and 6 deletions
|
@ -83,6 +83,7 @@ Configuration is done under `sources` → `youtube` with the following settings:
|
||||||
* `tmp_dir`: YouTube videos will be downloaded before playback. This sets the directory, where YouTube videos are stored.
|
* `tmp_dir`: YouTube videos will be downloaded before playback. This sets the directory, where YouTube videos are stored.
|
||||||
* `max_res`: Maximum resolution of a video.
|
* `max_res`: Maximum resolution of a video.
|
||||||
* `start_streaming`: `true` or `false`. If `true`, videos will be streamed directly using `mpv`, if the video is not cached beforehand. Otherwise, Syng waits for the video to be downloaded.
|
* `start_streaming`: `true` or `false`. If `true`, videos will be streamed directly using `mpv`, if the video is not cached beforehand. Otherwise, Syng waits for the video to be downloaded.
|
||||||
|
* `seach_suffix`: A string that is appended to each search query. Default is "karaoke".
|
||||||
|
|
||||||
### S3
|
### S3
|
||||||
|
|
||||||
|
@ -145,6 +146,7 @@ sources:
|
||||||
start_streaming: false
|
start_streaming: false
|
||||||
max_res: 720
|
max_res: 720
|
||||||
tmp_dir: ${XDG_CACHE_DIR}/syng
|
tmp_dir: ${XDG_CACHE_DIR}/syng
|
||||||
|
search_suffix: karaoke
|
||||||
```
|
```
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
SYNG_VERSION = (2, 1, 1)
|
SYNG_VERSION = (2, 1, 1)
|
||||||
SYNG_PROTOCOL_VERSION = (2, 1, 0)
|
SYNG_PROTOCOL_VERSION = (2, 1, 1)
|
||||||
|
|
|
@ -22,7 +22,7 @@ from platformdirs import user_cache_dir
|
||||||
from ..entry import Entry
|
from ..entry import Entry
|
||||||
from ..result import Result
|
from ..result import Result
|
||||||
from .source import Source, available_sources
|
from .source import Source, available_sources
|
||||||
from ..config import BoolOption, ChoiceOption, FolderOption, ListStrOption, ConfigOption
|
from ..config import BoolOption, ChoiceOption, FolderOption, ListStrOption, ConfigOption, StrOption
|
||||||
|
|
||||||
|
|
||||||
class YouTube:
|
class YouTube:
|
||||||
|
@ -170,6 +170,8 @@ class YoutubeSource(Source):
|
||||||
- ``start_streaming``: If set to ``True``, the client starts streaming
|
- ``start_streaming``: If set to ``True``, the client starts streaming
|
||||||
the video, if buffering was not completed. Needs ``youtube-dl`` or
|
the video, if buffering was not completed. Needs ``youtube-dl`` or
|
||||||
``yt-dlp``. Default is False.
|
``yt-dlp``. Default is False.
|
||||||
|
- ``search_suffix``: A string that is appended to the search query.
|
||||||
|
Default is "karaoke".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
source_name = "youtube"
|
source_name = "youtube"
|
||||||
|
@ -191,6 +193,12 @@ class YoutubeSource(Source):
|
||||||
"Start streaming if\ndownload is not complete",
|
"Start streaming if\ndownload is not complete",
|
||||||
False,
|
False,
|
||||||
),
|
),
|
||||||
|
"search_suffix": ConfigOption(
|
||||||
|
StrOption(),
|
||||||
|
"A string that is appended to each search query",
|
||||||
|
"karaoke",
|
||||||
|
send_to_server=True,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def apply_config(self, config: dict[str, Any]) -> None:
|
def apply_config(self, config: dict[str, Any]) -> None:
|
||||||
|
@ -206,6 +214,7 @@ class YoutubeSource(Source):
|
||||||
self.formatstring = (
|
self.formatstring = (
|
||||||
f"bestvideo[height<={self.max_res}]+" f"bestaudio/best[height<={self.max_res}]"
|
f"bestvideo[height<={self.max_res}]+" f"bestaudio/best[height<={self.max_res}]"
|
||||||
)
|
)
|
||||||
|
self.search_suffix = config.get("search_suffix", "karaoke")
|
||||||
self.extra_mpv_options = {"ytdl-format": self.formatstring}
|
self.extra_mpv_options = {"ytdl-format": self.formatstring}
|
||||||
self._yt_dlp = YoutubeDL(
|
self._yt_dlp = YoutubeDL(
|
||||||
params={
|
params={
|
||||||
|
@ -279,8 +288,8 @@ class YoutubeSource(Source):
|
||||||
Search YouTube and the configured channels for the query.
|
Search YouTube and the configured channels for the query.
|
||||||
|
|
||||||
The first results are the results of the configured channels. The next
|
The first results are the results of the configured channels. The next
|
||||||
results are the results from youtube as a whole, but the term "Karaoke"
|
results are the results from youtube as a whole, a configurable suffix
|
||||||
is appended to the search query.
|
is appended to the search query (default is "karaoke").
|
||||||
|
|
||||||
All results are sorted by how good they match to the search query,
|
All results are sorted by how good they match to the search query,
|
||||||
respecting their original source (channel or YouTube as a whole).
|
respecting their original source (channel or YouTube as a whole).
|
||||||
|
@ -338,9 +347,10 @@ class YoutubeSource(Source):
|
||||||
def _yt_search(self, query: str) -> list[YouTube]:
|
def _yt_search(self, query: str) -> list[YouTube]:
|
||||||
"""Search youtube as a whole.
|
"""Search youtube as a whole.
|
||||||
|
|
||||||
Adds "karaoke" to the query.
|
Adds a configurable suffix to the query. Default is "karaoke".
|
||||||
"""
|
"""
|
||||||
return Search(f"{query} karaoke").results
|
suffix = f" {self.search_suffix}" if self.search_suffix else ""
|
||||||
|
return Search(f"{query}{suffix}").results
|
||||||
|
|
||||||
def _channel_search(self, query: str, channel: str) -> list[YouTube]:
|
def _channel_search(self, query: str, channel: str) -> list[YouTube]:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue