mirror of
https://github.com/blacktwin/JBOPS.git
synced 2025-12-15 12:45:36 +00:00
Slight fixes to gmusic to plex scripts
- adds more robust playlist song retrieval from Google Play Music for when, for some reason, the get_shared_playlist_contents() method didn't return all the playlist elements; - removes unnecessary encoding of title and album that were preventing Plex searches from finding the right songs.
This commit is contained in:
parent
28879b77d4
commit
e24114ad7a
@ -57,21 +57,21 @@ def round_down(num, divisor):
|
|||||||
return num - (num%divisor)
|
return num - (num%divisor)
|
||||||
|
|
||||||
|
|
||||||
def compare(ggmusic, pmusic):
|
def compare(info, pmusic):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
ggmusic (dict): Contains Playlist data from Google Music
|
info (dict): Contains track data from Google Music
|
||||||
pmusic (object): Plex item found from search
|
pmusic (object): Plex item found from search
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
pmusic (object): Matched Plex item
|
pmusic (object): Matched Plex item
|
||||||
"""
|
"""
|
||||||
title = str(ggmusic['track']['title'].encode('ascii', 'ignore'))
|
title = str(info['title'].encode('ascii', 'ignore'))
|
||||||
album = str(ggmusic['track']['album'].encode('ascii', 'ignore'))
|
album = str(info['album'].encode('ascii', 'ignore'))
|
||||||
tracknum = int(ggmusic['track']['trackNumber'])
|
tracknum = int(info['trackNumber'])
|
||||||
duration = int(ggmusic['track']['durationMillis'])
|
duration = int(info['durationMillis'])
|
||||||
|
|
||||||
# Check if track numbers match
|
# Check if track numbers match
|
||||||
if int(pmusic.index) == int(tracknum):
|
if int(pmusic.index) == int(tracknum):
|
||||||
@ -87,6 +87,17 @@ def compare(ggmusic, pmusic):
|
|||||||
elif title == pmusic.title:
|
elif title == pmusic.title:
|
||||||
return [pmusic]
|
return [pmusic]
|
||||||
|
|
||||||
|
songs = mc.get_all_songs()
|
||||||
|
def get_songs_info(id_song):
|
||||||
|
for e in songs:
|
||||||
|
if e['id'] == id_song:
|
||||||
|
return {
|
||||||
|
"title": e['title'],
|
||||||
|
"artist": e['artist'],
|
||||||
|
"album": e['album'],
|
||||||
|
"trackNumber": e['trackNumber'],
|
||||||
|
"durationMillis": e['durationMillis']
|
||||||
|
}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for pl in mc.get_all_user_playlist_contents():
|
for pl in mc.get_all_user_playlist_contents():
|
||||||
@ -98,10 +109,11 @@ def main():
|
|||||||
playlistContent = []
|
playlistContent = []
|
||||||
shareToken = pl['shareToken']
|
shareToken = pl['shareToken']
|
||||||
# Go through tracks in Google Music Playlist
|
# Go through tracks in Google Music Playlist
|
||||||
for ggmusic in mc.get_shared_playlist_contents(shareToken):
|
for ggmusic in pl['tracks']:
|
||||||
title = str(ggmusic['track']['title'].encode('ascii', 'ignore'))
|
info = get_songs_info(ggmusic['trackId'])
|
||||||
album = str(ggmusic['track']['album'].encode('ascii', 'ignore'))
|
title = str(info['title'])
|
||||||
artist = str(ggmusic['track']['artist'])
|
album = str(info['album'])
|
||||||
|
artist = str(info['artist'])
|
||||||
# Search Plex for Album title and Track title
|
# Search Plex for Album title and Track title
|
||||||
albumTrackSearch = plex.library.section(MUSIC_LIBRARY_NAME).searchTracks(
|
albumTrackSearch = plex.library.section(MUSIC_LIBRARY_NAME).searchTracks(
|
||||||
**{'album.title': album, 'track.title': title})
|
**{'album.title': album, 'track.title': title})
|
||||||
@ -110,7 +122,7 @@ def main():
|
|||||||
playlistContent += albumTrackSearch
|
playlistContent += albumTrackSearch
|
||||||
if len(albumTrackSearch) > 1:
|
if len(albumTrackSearch) > 1:
|
||||||
for pmusic in albumTrackSearch:
|
for pmusic in albumTrackSearch:
|
||||||
albumTrackFound = compare(ggmusic, pmusic)
|
albumTrackFound = compare(info, pmusic)
|
||||||
if albumTrackFound:
|
if albumTrackFound:
|
||||||
playlistContent += albumTrackFound
|
playlistContent += albumTrackFound
|
||||||
break
|
break
|
||||||
@ -123,7 +135,7 @@ def main():
|
|||||||
playlistContent += trackSearch
|
playlistContent += trackSearch
|
||||||
if len(trackSearch) > 1:
|
if len(trackSearch) > 1:
|
||||||
for pmusic in trackSearch:
|
for pmusic in trackSearch:
|
||||||
trackFound = compare(ggmusic, pmusic)
|
trackFound = compare(info, pmusic)
|
||||||
if trackFound:
|
if trackFound:
|
||||||
playlistContent += trackFound
|
playlistContent += trackFound
|
||||||
break
|
break
|
||||||
@ -133,7 +145,7 @@ def main():
|
|||||||
artistSearch = plex.library.section(MUSIC_LIBRARY_NAME).searchTracks(
|
artistSearch = plex.library.section(MUSIC_LIBRARY_NAME).searchTracks(
|
||||||
**{'artist.title': artist})
|
**{'artist.title': artist})
|
||||||
for pmusic in artistSearch:
|
for pmusic in artistSearch:
|
||||||
artistFound = compare(ggmusic, pmusic)
|
artistFound = compare(info, pmusic)
|
||||||
if artistFound:
|
if artistFound:
|
||||||
playlistContent += artistFound
|
playlistContent += artistFound
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user