Support multiple channels in Youtube search

master
Nikola Forró 6 years ago
parent a89ac4375f
commit df4be019eb

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

@ -22,8 +22,8 @@ keywords = #bellameeze,bella,teeny,kitty,cat,😹,😻,🐱,🐈
[Youtube] [Youtube]
api_key = __GOOGLE_API_KEY__ api_key = __GOOGLE_API_KEY__
# ladylilia # Lady Lilia, Lilia Live
channel_id = UC5970RJMoEcRNZl0MNp8tlQ channel_ids = UC5970RJMoEcRNZl0MNp8tlQ,UCHNjavmkFUf2n0uzWSgj16w
[Quotes] [Quotes]
api_url = https://ladylilia.com/quotes/api api_url = https://ladylilia.com/quotes/api

Loading…
Cancel
Save