@@ -60,16 +60,33 @@ def search(query, query_type, auth_token):
60
60
return None
61
61
else :
62
62
response = content_data [query_type + 's' ]['items' ][0 ]
63
- spotify_link = response ['external_urls' ]['spotify' ]
64
- (thumbnail , thumbnail_width , thumbnail_height ) = get_thumbnail (response )
65
- return (spotify_link , thumbnail , thumbnail_width , thumbnail_height )
63
+ return response
66
64
67
65
def is_empty_query (query ):
68
66
return True if query == '' else False
69
67
70
68
def check_no_results (results ):
71
69
return True if len (results ) == 0 else False
72
70
71
+ def build_inline_query_result_article (_type , response ):
72
+ (thumb_url , thumb_width , thumb_height ) = (None , None , None )
73
+ # use the album art of the track for the thumbnail
74
+ if _type == 'Track' :
75
+ (thumb_url , thumb_width , thumb_height ) = get_thumbnail (response ['album' ])
76
+ else :
77
+ (thumb_url , thumb_width , thumb_height ) = get_thumbnail (response )
78
+
79
+ spotify_link = response ['external_urls' ]['spotify' ]
80
+ name = response ['name' ]
81
+ query_result_article = InlineQueryResultArticle (id = uuid4 (),
82
+ title = _type + ' - ' + name ,
83
+ input_message_content = InputTextMessageContent (spotify_link ),
84
+ thumb_url = thumb_url ,
85
+ thumb_width = thumb_width ,
86
+ thumb_height = thumb_height )
87
+
88
+ return query_result_article
89
+
73
90
# main function to handle all inline queries
74
91
def inlinequery (bot , update ):
75
92
@@ -88,12 +105,7 @@ def inlinequery(bot, update):
88
105
for _type in types :
89
106
response = search (query , _type .lower (), auth_token )
90
107
if response is not None :
91
- results .append (InlineQueryResultArticle (id = uuid4 (),
92
- title = _type ,
93
- input_message_content = InputTextMessageContent (response [0 ]),
94
- thumb_url = response [1 ],
95
- thumb_width = response [2 ],
96
- thumb_height = response [3 ]))
108
+ results .append (build_inline_query_result_article (_type , response ))
97
109
98
110
# if there are no results, tell user
99
111
if check_no_results (results ):
0 commit comments