Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Spotify's remix naming convention to more widely used convention #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
49 changes: 31 additions & 18 deletions spotify-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def filterPlexArray(plexItems=[], song="", artist="") -> List[Track]:
plexItems.remove(item)
continue
artistItem = item.artist()
if artistItem.title.lower() != artist.lower():
if str(item.originalTitle).lower() != artist.lower() and artistItem.title.lower() != artist.lower():
plexItems.remove(item)
continue

Expand Down Expand Up @@ -60,27 +60,40 @@ def getPlexTracks(plex: PlexServer, spotifyTracks: []) -> List[Track]:
plexTracks = []
for spotifyTrack in spotifyTracks:
track = spotifyTrack['track']
logging.info("Searching Plex for: %s by %s" % (track['name'], track['artists'][0]['name']))

try:
musicTracks = plex.search(track['name'], mediatype='track')
except:
try:
musicTracks = plex.search(track['name'], mediatype='track')
except:
logging.info("Issue making plex request")
continue

if len(musicTracks) > 0:
plexMusic = filterPlexArray(musicTracks, track['name'], track['artists'][0]['name'])
if len(plexMusic) > 0:
logging.info("Found Plex Song: %s by %s" % (track['name'], track['artists'][0]['name']))
plexTracks.append(plexMusic[0])
track_options = [track['name']]

# Parse remixes properly
mix_search = re.search('(.*) - (.*Remix|.*Mix)', track_options[0], re.IGNORECASE)
if mix_search:
track_options[0] = mix_search.group(1) + ' (' + mix_search.group(2) + ')'
# Also match the track without "Original Mix" as this is rarely specified except in Spotify
if mix_search.group(2) == "Original Mix":
track_options.append(mix_search.group(1))

logging.info("Searching Plex for: %s by %s" % (track_options[0], track['artists'][0]['name']))

for track_name in track_options:
for artist in track['artists']:
try:
musicTracks = plex.search(track_name, mediatype='track')
except:
try:
musicTracks = plex.search(track_name, mediatype='track')
except:
logging.info("Issue making plex request")
break
if len(musicTracks) > 0:
plexMusic = filterPlexArray(musicTracks, track_name, artist['name'])
if len(plexMusic) > 0:
logging.info("Found Plex Song: %s by %s" % (track_name, artist['name']))
plexTracks.append(plexMusic[0])
break

return plexTracks


def createPlaylist(plex: PlexServer, sp: spotipy.Spotify, playlist: []):
playlistName = playlist['owner']['display_name'] + " - " + playlist['name']
playlistName = playlist['owner']['id'] + " - " + playlist['name']
logging.info('Starting playlist %s' % playlistName)
plexTracks = getPlexTracks(plex, getSpotifyTracks(sp, playlist))
if len(plexTracks) > 0:
Expand Down