This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from metabrainz/add-artist-element
Rob's Xmas present to himself: Hacking on the content resolver
- Loading branch information
Showing
26 changed files
with
1,307 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ mp3 | |
/build/ | ||
/dist/ | ||
config.py | ||
*.jspf | ||
*.m3u | ||
.eggs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
from collections import defaultdict | ||
import datetime | ||
import sys | ||
|
||
import peewee | ||
import requests | ||
|
||
from lb_content_resolver.model.database import db | ||
from lb_content_resolver.model.recording import Recording, RecordingMetadata | ||
from lb_content_resolver.utils import select_recordings_on_popularity | ||
from troi.recording_search_service import RecordingSearchByArtistService | ||
from troi.splitter import plist | ||
|
||
|
||
class LocalRecordingSearchByArtistService(RecordingSearchByArtistService): | ||
''' | ||
Given the local database, search for artists that meet given tag criteria | ||
''' | ||
|
||
def __init__(self): | ||
RecordingSearchByArtistService.__init__(self) | ||
|
||
def search(self, artist_mbids, begin_percent, end_percent, num_recordings): | ||
""" | ||
Perform an artist search. Parameters: | ||
tags - a list of artist_mbids for which to search recordings | ||
begin_percent - if many recordings match the above parameters, return only | ||
recordings that have a minimum popularity percent score | ||
of begin_percent. | ||
end_percent - if many recordings match the above parameters, return only | ||
recordings that have a maximum popularity percent score | ||
of end_percent. | ||
num_recordings - ideally return these many recordings | ||
If only few recordings match, the begin_percent and end_percent are | ||
ignored. | ||
""" | ||
|
||
query = """SELECT popularity | ||
, recording_mbid | ||
, artist_mbid | ||
, subsonic_id | ||
FROM recording | ||
JOIN recording_metadata | ||
ON recording.id = recording_metadata.recording_id | ||
LEFT JOIN recording_subsonic | ||
ON recording.id = recording_subsonic.recording_id | ||
WHERE artist_mbid in (%s) | ||
ORDER BY artist_mbid | ||
, popularity""" | ||
|
||
placeholders = ",".join(("?", ) * len(artist_mbids)) | ||
cursor = db.execute_sql(query % placeholders, params=tuple(artist_mbids)) | ||
|
||
artists = defaultdict(list) | ||
for rec in cursor.fetchall(): | ||
artists[rec[2]].append({"popularity": rec[0], "recording_mbid": rec[1], "artist_mbid": rec[2], "subsonic_id": rec[3]}) | ||
|
||
for artist in artists: | ||
artists[artist] = select_recordings_on_popularity(artists[artist], begin_percent, end_percent, num_recordings) | ||
|
||
return artists |
Oops, something went wrong.