diff --git a/tubesync/sync/mediaservers.py b/tubesync/sync/mediaservers.py index cfa5a52b..d07f2f21 100644 --- a/tubesync/sync/mediaservers.py +++ b/tubesync/sync/mediaservers.py @@ -5,6 +5,7 @@ from django.forms import ValidationError from urllib.parse import urlsplit, urlunsplit, urlencode from django.utils.translation import gettext_lazy as _ from common.logger import log +from django.conf import settings class MediaServerError(Exception): @@ -203,11 +204,27 @@ class JellyfinMediaServer(MediaServer): HELP = _('

To connect your TubeSync server to your Jellyfin Media Server, please enter the details below.

' '

The host can be either an IP address or a valid hostname.

' '

The port should be between 1 and 65536.

' - '

The token is required for API access. You can generate a token in your Jellyfin user profile settings.

' - '

The libraries is a comma-separated list of library IDs in Jellyfin.

') + '

The "API Key" token is required for API access. Your Jellyfin administrator can generate an "API Key" token for use with TubeSync for you.

' + '

The libraries is a comma-separated list of library IDs in Jellyfin. Leave this blank to see a list.

') def make_request(self, uri='/', headers={}, params={}): + headers.update({'Content-Type': 'application/json'}) url, kwargs = self.make_request_args(uri=uri, token_header='X-Emby-Token', headers=headers, params=params) + # From the Emby source code; + # this is the order in which the headers are tried: + # X-Emby-Authorization: ('MediaBrowser'|'Emby') 'Token'=, 'Client'=, 'Version'= + # X-Emby-Token: + # X-MediaBrowser-Token: + # Jellyfin uses 'Authorization' first, + # then optionally falls back to the 'X-Emby-Authorization' header. + # Jellyfin uses (") around values, but not keys in that header. + token = kwargs['headers'].get('X-Emby-Token', None) + if token: + kwargs['headers'].update({ + 'X-MediaBrowser-Token': token, + 'X-Emby-Authorization': f'Emby Token={token}, Client=TubeSync, Version={settings.VERSION!s}', + 'Authorization': f'MediaBrowser Token="{token}", Client="TubeSync", Version="{settings.VERSION!s}"', + }) log.debug(f'[jellyfin media server] Making HTTP GET request to: {url}') return requests.get(url, **kwargs)