@@ -49,6 +49,18 @@ def get_auth_token():
49
49
50
50
return access_token
51
51
52
+ def get_thumbnail (response ):
53
+ # check if images exist for search query
54
+ if 'images' in response and len (response ['images' ]) > 0 :
55
+ image = response ['images' ][0 ]
56
+ thumbnail = image ['url' ]
57
+ thumbnail_width = image ['width' ]
58
+ thumbnail_height = image ['height' ]
59
+ return (thumbnail , thumbnail_width , thumbnail_height )
60
+ else :
61
+ return (None , None , None )
62
+
63
+
52
64
def search (query , query_type , auth_token ):
53
65
# replace all spaces with %20 as per Spotify Web API
54
66
search_query = query .lower ().strip ().replace (" " , "%20" )
@@ -79,8 +91,11 @@ def search(query, query_type, auth_token):
79
91
80
92
if len (content_data [query_type + 's' ]['items' ]) == 0 :
81
93
return None
82
- else :
83
- return content_data [query_type + 's' ]['items' ][0 ]['external_urls' ]['spotify' ]
94
+ else :
95
+ response = content_data [query_type + 's' ]['items' ][0 ]
96
+ spotify_link = response ['external_urls' ]['spotify' ]
97
+ (thumbnail , thumbnail_width , thumbnail_height ) = get_thumbnail (response )
98
+ return (spotify_link , thumbnail , thumbnail_width , thumbnail_height )
84
99
85
100
def is_empty_query (query ):
86
101
return True if query == '' else False
@@ -108,7 +123,10 @@ def inlinequery(bot, update):
108
123
if response is not None :
109
124
results .append (InlineQueryResultArticle (id = uuid4 (),
110
125
title = _type ,
111
- input_message_content = InputTextMessageContent (response )))
126
+ input_message_content = InputTextMessageContent (response [0 ]),
127
+ thumb_url = response [1 ],
128
+ thumb_width = response [2 ],
129
+ thumb_height = response [3 ]))
112
130
113
131
# if there are no results, tell user
114
132
if check_no_results (results ):
0 commit comments