-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_solr_track.py
48 lines (46 loc) · 1.77 KB
/
find_solr_track.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Create a playlist manually by entering songs one at a time
and searching solr for the particular song
There is also create_playlist_from_queue.py that has you put the songs on the queue
(from a playlist or whatever) and creates a playlist from the queue
'''
from SolrClient import SolrClient
from config import ec_uri
solr = SolrClient(ec_uri+':8983/solr')
collection = 'sonos_companion'
track_title = input("\nwhat is the title of the track that you are looking for? ")
s = 'title:' + ' AND title:'.join(track_title.split())
result = solr.query(collection, {'q':s, 'rows':10, 'fl':['score', 'id', 'uri', 'title', 'artist', 'album'], 'sort':'score desc'})
tracks = result.docs
count = result.get_results_count()
if count==0:
print("Didn't find any tracks\n")
elif count==1:
track = tracks[0]
try:
print('id: ' + track['id'])
print('artist: ' + track['artist'])
print('album: ' + track['album'])
print('song: ' + track['title'])
print('uri: ' + track['uri'])
except Exception as e:
print(e)
print('------------------------------------------------------------------------------------------------')
else:
print("track count =",count)
for n,track in enumerate(tracks,1):
try:
#print('\n')
print(n)
print('id: ' + track['id'])
print('artist: ' + track['artist'])
print('album: ' + track['album'])
print('song: ' + track['title'])
print('uri: ' + track['uri'])
except Exception as e:
print(e)
print('--------------------------------------------------------------------------------------------------')
#res = input("Which track to you want (0=None)? ")
#num = int(res)
#if num:
# print(num)