You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

""" Wrapper to the YouTube API """
import logging
import googleapiclient.discovery
import wordfilter
import config
LOGGER = logging.getLogger(__name__)
YTAPI ='youtube', 'v3',
1 year ago
def get_videos(query):
""" Given a search query, return a list of video IDs """
1 year ago
# 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', ''))]
1 year ago
def get_details(vid):
""" Given a video ID, get the content details """
1 year ago
# pylint:disable=no-member
request = YTAPI.videos().list(part="contentDetails",
1 year ago
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"))