Closed hockeygoalie35 closed 12 months ago
I was about to add my own version of this request. Here's the information I typed up:
In Plex Web you can see two sets of Similar Artists for music artist pages: The main ones which are provided by library tags and are accessible through SimilarArtistMixin and other API calls and a second row of "Sonically Similar Artists." These aren't part of the library tags but seem to be retrieved by the web app by calling /library/metadata/#/nearest?limit=30&maxDistance=0.25&excludeParentID=-1&X-Plex-Product=Plex%20Web...
I'd like to be able to retrieve that list or make requests with different maxDistance and limit values. Even the list as shown in the web view would be helpful.
Thanks for adding this. I think people will find some great uses for it!
I took a few minutes to compare it with my own code and there seem to be some performance issues. Here's mine vs. a call to the new function. I ran it a few times on a sample of 101 records and it took 1:34 to process with the api but only 0:43 with my code (using TQDM for timing). Not complaining, but in case it helps to improve things for everyone here was the solution I wrote along with my implementation of the API.
for artist in library.search(search_string):
if sonic_similarity_urlbased:
similar_url = '{}{}/nearest?limit=50&maxDistance=0.25&excludeParentID=-1&X-Plex-Product=Plex%20API&X-Plex-Token={}'.format(plex._baseurl, artist.key, myToken)
soup = BeautifulSoup(urllib.request.urlopen(similar_url).read(),"lxml-xml")
full_item.sonically_similar = [[x['key'], x['title'], str(i)] for i,x in enumerate(soup.find_all("Directory"))]
if sonic_similarity_api:
full_item.sonically_similar = [[x.key, x.title, str(i)] for i,x in enumerate(full_item.sonicallySimilar(50))]
there seem to be some performance issues
It is bound to happen as you are directly calling the Api through urllib while the module has a lot of overhead in building the plexobjects like albums and artists, after fetching the results, 50 in this case.
This is awesome, thank you! Is there any way to dig further into what Sonic Analysis "sees"? Like the beats/tantums/bars it likely slices music up into? Similar to Spotify API? Or is all that internal?
The only other thing I've seen exposed is the percentage similarity in Plexamp.
@hockeygoalie35
Is there any way to dig further into what Sonic Analysis "sees"? Like the beats/tantums/bars it likely slices music up into?
https://essentia.upf.edu/ is used by plex to do all the sonic analysis as per my research, in theory one could build a similar feature using this software. As far as the api goes, I'm not sure if such deets are available.
@Thlayli
The only other thing I've seen exposed is the percentage similarity in Plexamp.
that is returned in the api access it as below
similar_track = track.sonicallySimilar()[0]
percent_similar = 1 - similar_track.distance
Thank you, this is exactly what I was looking for! Looks like it's all available for use.
What is your feature request?
I am unsure if Plex exposes the Sonic Analysis feature of Plex to their API. Request an investigation if it does, and if so, that the python package is update to wrap these commands. Thanks!
Are there any workarounds?
Unknown, perhaps with XML API access.
Code Snippets
N/A
Additional Context
N/A