跳转到主要内容

Mopidy的YouTube扩展

项目描述


Mopidy-YouTube


.. image:: https://img.shields.io/pypi/v/Mopidy-YouTube :target: https://pypi.ac.cn/project/Mopidy-YouTube/ :alt: 最新PyPI版本

.. image:: https://img.shields.io/circleci/build/gh/natumbri/mopidy-youtube :target: https://circleci.com/gh/natumbri/mopidy-youtube :alt: CircleCI构建状态

.. 图像:: https://img.shields.io/codecov/c/gh/natumbri/mopidy-youtube :目标: https://codecov.io/gh/natumbri/mopidy-youtube :alt: 测试覆盖率

Mopidy 扩展,用于播放 YouTube 中的声音。

安装

以下安装说明适用于类 Unix 系统。可能可以在其他系统上使用其他命令进行安装。在安装 mopidy-youtube 之前,您应该有一个可工作的 mopidy 安装。

根据您的类 Unix 系统配置,您可能需要以超级用户身份安装(例如,使用 sudo)。

通过运行以下命令从 PyPI 安装:

python3 -m pip install Mopidy-Youtube

通过运行以下命令从 github 安装:

python3 -m pip install https://github.com/natumbri/mopidy-youtube/archive/develop.zip

通过运行以下命令从 PyPI 安装 youtube-dl(或兼容的包):

python3 -m pip install --upgrade youtube-dl

有关 youtube-dl 的更多信息,请参阅 https://github.com/ytdl-org/youtube-dl 其他兼容(可能更更新)的库可能包括 yt-dlp(《https://github.com/yt-dlp/yt-dlp》)和 youtube-dlc

如果您希望使用其他 youtube-dl 库,请在配置文件中将 youtube_dl_package 选项设置为替代包的名称:

[youtube]
youtube_dl_package = [name] : package name of an alternative package 
				  to replace "youtube_dl", for example 
			  "yt_dlp"

确保您已经安装了 GStreamer 插件,特别是“坏”插件集合。例如,在 Debian/Ubuntu 上,您可以通过运行以下命令来安装它:

sudo apt-get install gstreamer1.0-plugins-bad

配置

在启动 Mopidy 之前,您必须将 Mopidy-YouTube 的配置添加到您的 Mopidy 配置文件中:

[youtube]
enabled = true

如果您想缓存文件,请将 allow_cache 设置为 true。缓存目录将是 mopidy [核心] 配置中指定的 cache_dir:

allow_cache = true

只有添加到 Mopidy 轨迹列表的曲目(及其相关元数据和图像)才会被缓存。搜索结果不会被缓存。如果您想使用缓存的图像,则必须启用并正确配置 mopidy-HTTP。它包含在 Mopidy 中,并默认启用。

如果您希望 mopidy-youtube 使用 YouTube API,在启动 Mopidy 之前,您必须将您的 Google API 密钥添加到您的 Mopidy 配置文件中,并设置 api_enabled = true:

youtube_api_key = <api key you got from Google>
api_enabled = true

如果您希望 mopidy-youtube 使用 YouTube 音乐而不是常规 YouTube,请设置 musicapi_enabled = true:

musicapi_enabled = true  

音乐 API 可以与或没有 YouTube API 一起使用。

要使用 YouTube 音乐 API,您还需要安装一个额外的 Python 包(ytmusicapi >= 0.19)。例如,通过运行以下命令从 PyPI 安装 ytmusicapi

python3 -m pip install --upgrade ytmusicapi   

如果您想在 Mopidy 库中查看频道的 YouTube 播单,您需要将频道 ID 包含在您的配置文件中:

channel_id = <channel id>

如果您想在 Mopidy 库中查看您自己的频道的私有 YouTube 音乐播单,您需要:

- set channel_id to the id for your own channel
- enable the music api and 
- set a musicapi_cookie OR a musicapi_cookiefile  

如果您想使用 cookie(而不是 cookiefile),您可以通过以下过程获取 cookie:在 ytmusicapi readme <https://ytmusicapi.readthedocs.io/en/latest/setup.html#copy-authentication-headers>_ 中提到的过程。您只需要在网络标签中查找 Cookie,而不是所有标题,并在配置文件中将它包含为 musicapi_cookie:

musicapi_cookie = <cookie>  

或者,您可以设置 musicapi_cookiefile。这是启用 YouTube Premium 高质量流媒体所必需的。(您还需要使用 yt-dlp 而不是 youtube_dl。(有关如何配置它,请参阅 youtube_dl_package 文档。)注意:使用已弃用的 musicapi_cookie 配置选项设置 cookie 将无法用于高质量音频!

设置包含 YouTube cookie 的 cookies.txt(Netscape HTTP Cookie 文件)

mopidy-youtube 可以在播放队列中的最后一首歌播放完毕后,自动播放“相关”曲目。如果您想使 mopidy-youtube 自动播放相关视频,请将 autoplay_enabled 设置为 true:

[youtube]
autoplay_enabled = true

如果启用了自动播放,还有以下选项:

strict_autoplay = [true/false]
max_autoplay_length = [maximum length of track in seconds or None]  : defaults to 600s
max_degrees_of_separation = [defaults to 3]

如果设置了 strict_autoplay 选项,则忽略当前曲目列表,之后自动播放最相关的视频。

max_autoplay_length 选项设置自动播放器播放的曲目最大长度。任何整数值都是可接受的;默认值为 600 秒。如果您不希望有最大长度,请在 mopidy.conf 中包含以下内容:

    max_autoplay_length =

最大分离度控制自动播放的曲目与触发自动播放的曲目(种子曲目)的相关程度。例如,将值设置为默认的 3,则第一个自动播放的曲目将与种子曲目相关(一个分离度)。第二个自动播放的曲目将与第一个自动播放的曲目相关(两个分离度)。第三个自动播放的曲目将与第二个自动播放的曲目相关(三个分离度,最大)。第四个自动播放的曲目将与种子曲目相关(回到一个分离度)。

其他配置选项包括:

[youtube]
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

用法

只需在您的 MPD 客户端中搜索文件名,或将 YouTube 网址或 URI 添加到以 yt:youtube: 为前缀的播放列表中。

示例视频:

[yt|youtube]:<url to youtube video>
[yt|youtube]:video:<id>
[yt|youtube]:video/<title>.<id>

示例播放列表:

[yt|youtube]:<url to youtube playlist>
[yt|youtube]:playlist:<id>
[yt|youtube]:playlist/<title>.<id>

故障排除

如果扩展程序运行缓慢,请尝试为 threads_max、search_results 和 playlist_max_videos 设置较低的值。

如果 URI 解析停止工作,请始终首先尝试更新 youtube-dl 库。

项目资源

  • 源代码 <https://github.com/natumbri/mopidy-youtube>_
  • 问题跟踪器 <https://github.com/natumbri/mopidy-youtube/issues>_
  • 变更日志 <https://github.com/natumbri/mopidy-youtube/blob/master/CHANGELOG.rst>_

致谢

  • 原作者: Janez Troha <https://github.com/dz0ny>_
  • 当前维护者: Nikolas Tumbri <https://github.com/natumbri>_
  • 贡献者 <https://github.com/natumbri/mopidy-youtube/graphs/contributors>_

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解有关 安装软件包 的更多信息。

源代码分发

Mopidy-YouTube-3.7.tar.gz (12.7 MB 查看散列)

上传时间 源代码

构建分发

Mopidy_YouTube-3.7-py3-none-any.whl (49.9 kB 查看散列)

上传时间 Python 3

由以下支持