Skip to content
Open
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
3 changes: 3 additions & 0 deletions mopidy_tidal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def get_config_schema(self):
schema['username'] = config.String()
schema['password'] = config.Secret()
schema['quality'] = config.String(choices=["LOSSLESS", "HIGH", "LOW"])
schema['spotify_proxy'] = config.Boolean(optional=True)
schema['spotify_client_id'] = config.String(optional=True)
schema['spotify_client_secret'] = config.String(optional=True)
return schema

def setup(self, registry):
Expand Down
5 changes: 4 additions & 1 deletion mopidy_tidal/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def __init__(self, config, audio):
backend=self)
self.library = library.TidalLibraryProvider(backend=self)
self.playlists = playlists.TidalPlaylistsProvider(backend=self)
self.uri_schemes = ['tidal']
if config['tidal']['spotify_proxy']:
self.uri_schemes = ['tidal', 'spotify']
else:
self.uri_schemes = ['tidal']

def on_start(self):
quality = self._config['tidal']['quality']
Expand Down
3 changes: 3 additions & 0 deletions mopidy_tidal/ext.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ enabled = true
username=
password=
quality=LOSSLESS
spotify_proxy = false
spotify_client_id = ""
spotify_client_secret = ""
14 changes: 13 additions & 1 deletion mopidy_tidal/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from mopidy_tidal.utils import apply_watermark

from mopidy_tidal.spotify_proxy import SpotifyProxy

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,6 +46,11 @@ def __init__(self, *args, **kwargs):
self.lru_artist_img = LruCache()
self.lru_album_img = LruCache()
self.track_cache = Cache()
self.config = kwargs["backend"]._config
if self.config["tidal"]["spotify_proxy"]:
self.spotify_proxy = SpotifyProxy(str(self.config["tidal"]["spotify_client_id"]),
str(self.config["tidal"]["spotify_client_secret"]))


def get_distinct(self, field, query=None):
logger.debug("Browsing distinct %s with query %r", field, query)
Expand Down Expand Up @@ -88,7 +94,6 @@ def browse(self, uri):
session = self.backend._session

# summaries

if uri == self.root_directory.uri:
return ref_models_mappers.create_root()

Expand Down Expand Up @@ -205,6 +210,13 @@ def lookup(self, uris=None):
tracks = []
for uri in uris:
parts = uri.split(':')
logger.info('URI: %s', uri)
if uri.startswith('spotify:track:'):
info = self.spotify_proxy.get_song_info(uri)
if info is not None:
result = self.search(query={"track_name": [info["title"] + " " + " ".join(info["artists"])]})
if len(result.tracks) > 0:
tracks.append(result.tracks[0])
if uri.startswith('tidal:track:'):
if uri in self.track_cache:
tracks.append(self.track_cache[uri])
Expand Down
23 changes: 23 additions & 0 deletions mopidy_tidal/spotify_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

class SpotifyProxy:
def __init__(self, client_id, client_secret):
self.set_credentials(client_id, client_secret)

def set_credentials(self, client_id, client_secret):
self.credentials = SpotifyClientCredentials(
client_id=client_id,
client_secret=client_secret
)

def get_song_info(self, lz_uri):
spotify = spotipy.Spotify(client_credentials_manager = self.credentials)
results = spotify.tracks([lz_uri])
if len(results['tracks']) > 0:
track = results['tracks'][-1]
title = track["name"]
artists = [a["name"] for a in track["artists"]]
return {"title": title, "artists": artists}
else:
return None
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_version(filename):
'Pykka >= 1.1',
'tidalapi >= 0.6.7,<0.7.0',
'requests >= 2.0.0',
'spotipy >= 2.16.0'
],
entry_points={
'mopidy.ext': [
Expand Down