ampache / ampache

A web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any internet enabled device.
http://ampache.org
GNU Affero General Public License v3.0
3.52k stars 588 forks source link

[Feature Request] Automatically rate songs #2621

Open ncot-tech opened 3 years ago

ncot-tech commented 3 years ago

It would be really cool if Ampache somehow knew what music from my collection I was enjoying, and altered the ratings accordingly. I like the star rating, I have some smart playlists to find "music I like" (stuff rated 4/5 stars) and "favourite music" (things I have pressed the heart icon next to). I also have a smart playlist of unrated music which is currently more than 2/3 of my catalogue. I'm trying to rate all my music, along with having it all nicely tagged so I can create smart playlists better. It's just a bit tedious doing it by hand - I often forget because I'm listening to the music! (or I'm in my car and the Subsonic app doesn't seem to do ratings...)

I've noticed Ampache tracks the number of plays and the number of skips for each track, and how many times an artist/album is played. Would it be possible to write a plugin that could use this data to automatically rate songs? I don't mind having a go at writing a plugin, but is it even possible for Ampache plugins to change song/artist/album ratings?

It seems somewhat sensible that if I have at least listened to a track without skipping it, I probably found it OK to listen to so it's worth a 1-2 star rating, but if I've listened to it a number of times but keep skipping it I probably don't like it very much. And if I've played a certain artist/album many times by listening to their tracks, I probably like them more than others.

lachlan-00 commented 3 years ago

I do this as a sql script from my own installation but something in the catalog update sections would be pretty simple.

A plugin would also be easier as there are plugin methods that i think would work.

You are reading my mind because i was thinking about moving this into ampache but i didn't work on it as i thought i was the only one actually interested in this.

lachlan-00 commented 3 years ago

In a library i have been rating for years and still only rate ~10% of my collection. Which i actually don't think is that bad, you can't rate everything or it will make the ratings meaningless.

The issue will be how other people use stars this is how i arrange my ratings, 1 - Ignore these, intros, silent tracks, crap 2 - don't really like what i heard 3 - Sounds good enough that i want to track 4 - played a few times really liked it when i did 5 - favourites (I always heart 5)

So what i would propose is:

The plugin would need a row for each star and heart with a list of rules.

I think we could put in a lot more but that's at least a start.

lachlan-00 commented 3 years ago

part 1 is in now. edccc262f

The rating match plugin will raise the album and artist value if it's lower than the current song you're rating. image

2020-11-26T14:16:53+10:00 [user] (rating.class) -> Setting rating for song 956909 to 3 
2020-11-26T14:16:53+10:00 [user] (rating.class) -> save_rating...RatingMatch 
2020-11-26T14:16:53+10:00 [user] (rating.class) -> Setting rating for artist 19029 to 3 
2020-11-26T14:16:53+10:00 [user] (rating.class) -> save_rating...RatingMatch 
2020-11-26T14:16:53+10:00 [user] (rating.class) -> Setting rating for 'album' 98312 to 3 
2020-11-26T14:16:53+10:00 [user] (rating.class) -> save_rating...RatingMatch

i'll probably expand on this plugin some more but the other parts of automating this might be better in the catalog processes.

lachlan-00 commented 3 years ago

extended for flags as well

lachlan-00 commented 3 years ago

@ncot-tech i think the hardest part about auto rating is the plugin settings.

I was thinking a row for each star value

Then the setting string would be a comma separated list of ($plays,$skips,$ratio) so i can explode that out.

Is that enough? i think it's okay, but this is how i would use it.

does this make sense enough for you? I think it's the easiest way to to this.

lachlan-00 commented 3 years ago

i've tested this out with a few tracks i've found and a play,skip setting is a bit easier to manage. image

Commit is cbda5585a

I've tested by running a query to see which songs would be hitting the rule and playing. if you want to test yourself here is my query (make sure you change your user)

SELECT * FROM song
LEFT JOIN (SELECT object_id, COUNT(*) AS stream_count FROM object_count WHERE object_type = 'song' AND `count_type` = 'stream' AND user = 2 GROUP BY object_id) AS stream on stream.object_id = song.id
LEFT JOIN (SELECT object_id, COUNT(*) AS skip_count FROM object_count WHERE object_type = 'song' AND `count_type` = 'skip' AND user = 2 GROUP BY object_id) AS skip on skip.object_id = song.id
WHERE song.id in (SELECT object_id from object_count WHERE user = 2 and object_type = 'song' AND object_id not in (SELECT object_id from rating WHERE user = 2 and object_type = 'song')) AND
      (stream.stream_count > 0 OR skip.skip_count > 0)
ORDER BY stream.stream_count DESC
ncot-tech commented 3 years ago

Yeah that looks pretty cool. I would have replied earlier but I've only just realised github doesn't send notifications... But that does also mean this plugin has made it into the latest release.

I've got it set like this at the moment. The numbers are completely made up but feel reasonable maybe.

If I've understood this right, listening to something twice should give it a 1star rating, 5 times gives it a 2star rating?

Will it upgrade a track based on these settings? So if I have a 1star rated track that I've listened to 4 times, then I listen to it again it'll get changed to being a 2star track?

Changing a rating up should be OK, but changing them down might not be a good idea thinking about it. It feels like trying to get the system to change the ratings and the user being able to do them could cause confusing conflicts. However having it as an automatic suggestion seems good. If I add some new music and play it quite a lot, it might get enough listens to earn it a 3 or 4 star rating, I will then notice it appearing in playlists and can fine tune it later by hand.

For the junk tracks I either delete them entirely if I really don't like them, or click the "do not play" button next to them so they just go away.

image

lachlan-00 commented 3 years ago

Rating match does run each play. I'll confirm that the rating is raised (but it should be)

Moving down def doesn't happen, rating match only raises

Jieiku commented 3 years ago

I had the same problem of wanting to get things rated, but jamming out enjoying the music so much that i forget to rate.... here was my idea: https://github.com/ampache/ampache/issues/2735

Will definitely checkout the plugin, thanks!

Jieiku commented 3 years ago

so the play count will raise the rating based on the number of complete plays of the song?

at first I was not sure what the skip part of the value was even for. but based on @lachlan-00 example for Match rule for 2 stars of 1,10 I am going to assume it means if a song is played all the way through atleast once AND has 10 skips, AND is not currently rated or rated as 1 star then set the rating to 2?

If I am understanding the logic correctly then I could set Match rule for 1 star to something like 0,30? so that if I have never played it through all the way but have skipped it 30 times then it should be rated 1 star....

i can also think that maybe you accidently listed to the song atleast once.... because you were preoccupied..... so maybe the feature could allow a range for the play count?

for example Match rule for 1 Star instead of 0,30 you could do 1-3,30 which would allow 1 to 3 plays and 30+ skips and rate it 1 star.

Jieiku commented 3 years ago

Also I am not sure if I like that this plugin also sets the Artist and Album to the very highest rated star value whenever you rate a song.

For instance there are some albums and even artists that have like 100 songs across 7 albums, and I have rated 2 of their one hit wonder songs as 5 star, but most of the rest of their songs I have rated 1 or 2 stars.....

I think I would rather it average the ratings set for their songs and set the artist and album based on the average, possibly even round up, so if the average is 3.6 then set the rating to 4, etc, you could even go to the next whole integer regardless of rounding which would bias it towards voting up, so that even an average of 3.1 would be rated 4 star....

For now I have disabled the plugin because I do not want "one hit wonder" artist and albums getting rated at 5 star....

lachlan-00 commented 3 years ago

Also I am not sure if I like that this plugin also sets the Artist and Album to the very highest rated star value whenever you rate a song.

For instance there are some albums and even artists that have like 100 songs across 7 albums, and I have rated 2 of their one hit wonder songs as 5 star, but most of the rest of their songs I have rated 1 or 2 stars.....

I think I would rather it average the ratings set for their songs and set the artist and album based on the average, possibly even round up, so if the average is 3.6 then set the rating to 4, etc, you could even go to the next whole integer regardless of rounding which would bias it towards voting up, so that even an average of 3.1 would be rated 4 star....

For now I have disabled the plugin because I do not want "one hit wonder" artist and albums getting rated at 5 star....

you can disable the match with Minimum star rating to match for flags you disable When you love a track, flag the album and artist

lachlan-00 commented 3 years ago

scratch this comment.

setting the 2 settings above will block updating

Jieiku commented 3 years ago

so I should set it like this?

2021-09-05_21-17

It does seem to stop it from updating the artist or album rating... but im not sure the per song rating is still working, I found a 3 second track in my library and played it 10 times in a row but it never got a rating.... going to turn on debugging and see if I can check what is happening.

EDIT: it does work, seems I just could not listen to the track over and over, but by listening to the track, then hit the home page again, then listen to the track, then hit the home page, after I did this a few times it tracked it and set a rating.

EDIT2: well I thought it was working, the track finally got rated 3 star, but im up to 20 play counts now and it is still 3 star, it has not progressed to 4 or 5 star.

Jieiku commented 3 years ago

I was thinking instead of $play,$skip

what about something like $play,$play_percent

($play_percent = $play/$skip, would need to do if skip=0 then play_percent=100 or something... )

For example lets say I have Match rule for 5 Stars: 10,0

What happens if I have listened to the track 20 times, but skipped the track 80 times? does it still consider that a 5 star track?

EDIT: I guess it would be more accurate to call it a play_ratio instead of play_percent.....

Jieiku commented 3 years ago

I had a thought about it not becoming a 4 or 5 star.... didn't you say that if it has a rating then a new rating does not get set?

lachlan-00 commented 2 years ago

I've been trying to think of a good way to set this up differently.

The hardest part is trying to fit 2 values into 1 setting.

If you say 100% plays to skip for 5star. 1 play/0 skips is 5 star.

500 play/1 skip isn't.

The current setup of play,skip isn't great but isn't the worst either it's just terrible to explain.

What if you could set a smartlist for rules instead?

It's actually more along the lines of what I do for rating and might actually make more sense.

Song title contains instrumental OR length > 1 min = rate 1

Played by me 5 times and skipped by me 0 = Rate 3

I like the idea of extending search more than extending the plugin.

The. We can have an option like (if already rated don't change) etc etc

I think this would solve a lot of issues?

Jieiku commented 2 years ago

so you could use the search feature to apply ratings? I like that idea because then its not something constantly taking place in the background, you can just run it and have the ratings applied.

One thing I will note is that with the plugin, once I had a rating of 3, I could not progress to 4 or 5. so if users want to use this to apply 3, 4, and 5 star ratings, and they have the option like (if already rated don't change) etc etc

then what they will need to do is start at the 5 ratings, and work their way down, eg:

Played by me 15 times and skipped by me 0 = Rate 5

Played by me 10 times and skipped by me 0 = Rate 4

Played by me 5 times and skipped by me 0 = Rate 3

Also, I have one more idea on this, the more you listen to these songs, you may wish to update your ratings again months later to reflect a higher rating on songs you have listened to more. but at the same time you may not want to affect ratings that you actually manually clicked on the stars to set a rating.

I am suggesting you store a boolean value for the rating, call it autorating. if the rating was set to a whole batch of songs by the new search feature then you would set the autorating value to true for any of those songs where a new rating is set. and anytime a song actually had a manual rating set you would set the autorating value to false.

This to me seems like the very safest way to make sure users dont accidentally overwrite ratings they actually set themselves that were not set by the search feature.

Then later in a few months you can use the search feature again to update songs that dont have a rating or that have a rating but also have a value of autorating=true

I think I made this clear, but sometimes when you type out an idea it can be clear in your head but not clear to others, so let me know if what i am saying is not making sense to you.