No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

54 líneas
1.5 KiB

""" Wrapper to the YouTube API """
import logging
import googleapiclient.discovery
import wordfilter
import config
LOGGER = logging.getLogger(__name__)
YTAPI ='youtube', 'v3',
def get_videos(query):
""" Given a search query, return a list of video IDs """
# pylint:disable=no-member
request =
response = request.execute()
if 'items' not in response:
LOGGER.warning("No items found")
return []
wfilter = wordfilter.Wordfilter()
return [(item["id"]["videoId"], item['snippet'])
for item in response['items']
if 'id' in item
and 'videoId' in item['id']
and not wfilter.blacklisted(
item['snippet'].get('title', '')
+ item['snippet'].get('description', ''))]
def get_details(vid):
""" Given a video ID, get the content details """
# pylint:disable=no-member
request = YTAPI.videos().list(part="contentDetails",
response = request.execute()
for item in response['items']:
if item['id'] == vid:
return item['contentDetails']
return None
if __name__ == "__main__":
print(get_videos("+lofi beats to chill and relax to"))