Skip to main content

Mopidy extension for YouTube

Project description


Mopidy-YouTube


.. image:: https://img.shields.io/pypi/v/Mopidy-YouTube :target: https://pypi.org/project/Mopidy-YouTube/ :alt: Latest PyPI version

.. image:: https://img.shields.io/circleci/build/gh/natumbri/mopidy-youtube :target: https://circleci.com/gh/natumbri/mopidy-youtube :alt: CircleCI build status

.. image:: https://img.shields.io/codecov/c/gh/natumbri/mopidy-youtube :target: https://codecov.io/gh/natumbri/mopidy-youtube :alt: Test coverage

Mopidy extension that plays sound from YouTube.

Installation

These installation 'instructions' are for unixy systems. It may be possible to install it on other systems, using other commands. You should have a working mopidy installation before you install mopidy-youtube.

Depending on how your unixy system is configured, you may need to install as superuser (eg, using sudo).

Install from PyPI by running::

python3 -m pip install Mopidy-Youtube

Install from github by running::

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

Install youtube-dl (or a compatible package) from PyPI by running, for example::

python3 -m pip install --upgrade youtube-dl

For more information about youtube-dl, see https://github.com/ytdl-org/youtube-dl Other compatible (and possibly more up-to-date) libraries may include yt-dlp (https://github.com/yt-dlp/yt-dlp) and youtube-dlc.

If you wish to use an alternate youtube-dl library, in your configuration file you must set the youtube_dl_package option to the package name of an alternative package::

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

Make sure you already have the GStreamer plugins, especially the "bad" collection of plugins. For example, on Debian/Ubuntu you can install it by running::

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

Configuration

Before starting Mopidy, you must add configuration for Mopidy-YouTube to your Mopidy configuration file::

[youtube]
enabled = true

If you want to cache files, set allow_cache to true. The cache directory will be the one specified for cache_dir in mopidy [core] configuration::

allow_cache = true

Only tracks (and their related metadata and image) that are added to the mopidy track list will be cached. Search results are not cached. If you want to use cached images, mopidy-HTTP must be enabled and configured correctly. It is bundled with Mopidy and enabled by default.

If you want mopidy-youtube to use the YouTube API, before starting Mopidy, you must add your Google API key to your Mopidy configuration file and set api_enabled = true::

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

If you want mopidy-youtube to use YouTube Music, instead of regular YouTube, set musicapi_enabled = true::

musicapi_enabled = true  

The musicapi may be used with or without the youtube api.

To use the YouTube Music api, you will also need to install an additional python package (ytmusicapi >= 0.19). Install ytmusicapi from PyPI, for example, by running::

python3 -m pip install --upgrade ytmusicapi   

If you want to see the YouTube playlists of a channel in your mopidy library, you need to include the channel ID in your config file::

channel_id = <channel id>

If you want to see your own channel's private YouTube Music playlists in your mopidy library, you need to::

- set channel_id to the id for your own channel
- enable the music api and 
- set a musicapi_browser_authentication_file

You can obtain the musicapi browser authentication file by process mentioned in the ytmusicapi readme <https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html>_.

To enable YouTube Premium high quality streaming you must setup the musicapi_cookiefile. (You also need to use yt-dlp instead of youtube_dl. See youtube_dl_package documentation for how to configure it.)

Setup a cookies.txt (Netscape HTTP Cookie File) containing YouTube cookies:

mopidy-youtube can automatically play 'related' tracks after the last track in the play queue is played. If you want mopidy-youtube to autoplay related videos, set autoplay_enabled = true::

[youtube]
autoplay_enabled = true

If autoplay is enabled, other options are::

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]

If the option strict_autoplay is set, the current tracklist is ignored and the most related video automatically played afterwards.

The max_autoplay_length option sets the maximum length of a track that will be played by the autoplayer. Any interger value is acceptable; the default is 600s. If you don't want a maximum length, include the following in mopidy.conf::

    max_autoplay_length =

Max degrees of separation controls how distantly related to the track that triggered autoplay (the 'seed' track) the autoplayed tracks can be. For example, with the value set to the default of 3, the first track autoplayed will be related to the seed track (one degree of separation). The second track autoplayed will be related to the first track autoplayed (two degrees of separation). The third track autoplayed will be related to the second track autoplayed (three degrees of separation, the maximum). The fourth track autoplayed will be related to the seed track (back to one degree of separation).

Other configuration options are::

[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

Usage

Simply use search for filename in your MPD client or add YouTube URL or URI to playlist prefixed by yt: or youtube:.

Example video::

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

Example for playlist::

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

Troubleshooting

If the extension is slow, try setting lower values for threads_max, search_results and playlist_max_videos.

If resolving of URIs stops working, always try to update the youtube-dl library first.

Project resources

  • Source code <https://github.com/natumbri/mopidy-youtube>_
  • Issue tracker <https://github.com/natumbri/mopidy-youtube/issues>_
  • Changelog <https://github.com/natumbri/mopidy-youtube/blob/master/CHANGELOG.rst>_

Credits

  • Original author: Janez Troha <https://github.com/dz0ny>_
  • Current maintainer: Nikolas Tumbri <https://github.com/natumbri>_
  • Contributors <https://github.com/natumbri/mopidy-youtube/graphs/contributors>_

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mopidy_youtube-4.0.2.tar.gz (12.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mopidy_youtube-4.0.2-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

Details for the file mopidy_youtube-4.0.2.tar.gz.

File metadata

  • Download URL: mopidy_youtube-4.0.2.tar.gz
  • Upload date:
  • Size: 12.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mopidy_youtube-4.0.2.tar.gz
Algorithm Hash digest
SHA256 2a00fa704d7479f34fc8fd175a4a52977f3a560c3e69dece82aa3de99189b3bc
MD5 775ed0d52dcdd0ecced88f2d1899ad41
BLAKE2b-256 b18c4af7611bf8d9cbd296b9abaea9e9d87ebc0b2980c735033ae73a4f9ab142

See more details on using hashes here.

File details

Details for the file mopidy_youtube-4.0.2-py3-none-any.whl.

File metadata

  • Download URL: mopidy_youtube-4.0.2-py3-none-any.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mopidy_youtube-4.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5441be6dc54d11a4c0587d21ad69199243e5348172cb7c007ccffe2f6d886fa6
MD5 3c72549ff9fc5d987742799bbad2ce85
BLAKE2b-256 0a254b7530d0456a17c21131bd05930956fa137ebff2685b91f3c5b8aa038614

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page