|
|
|
@ -101,12 +101,16 @@ class Commands(object):
|
|
|
|
|
|
|
|
|
|
def query_youtube(self, query):
|
|
|
|
|
api_key = self.config['Youtube'].get('api_key')
|
|
|
|
|
channel_id = self.config['Youtube'].get('channel_id')
|
|
|
|
|
channel_ids = self.config['Youtube'].get('channel_ids').split(',')
|
|
|
|
|
yt = Youtube(api_key)
|
|
|
|
|
try:
|
|
|
|
|
results = yt.search(channel_id, query, playlists=True, limit=1)
|
|
|
|
|
if not results:
|
|
|
|
|
for channel_id in channel_ids:
|
|
|
|
|
results = yt.search(channel_id, query, playlists=True, limit=1)
|
|
|
|
|
if results:
|
|
|
|
|
break
|
|
|
|
|
results = yt.search(channel_id, query, playlists=False, limit=1)
|
|
|
|
|
if results:
|
|
|
|
|
break
|
|
|
|
|
result = results.pop(0)
|
|
|
|
|
except (YoutubeError, IndexError):
|
|
|
|
|
raise CommandError('couldn\'t find anything on Youtube')
|
|
|
|
|