/ytpy

Python asynchronous wrapper for youtube data api v3.

Primary LanguagePython

ytpy

CodeFactor contributions welcome Discord Badge

Python wrapper for youtube data api v3. Simple asynchronous wrapper to get youtube video or playlist data. The purpose of this project is to make it easier for developers to extract data from YouTube.

Requirements

Dependencies

  • google-api-python-client
  • google-auth
  • google-auth-httplib2
  • oauth2client
  • aiohttp
  • youtube-dl

Usage

Get Project

  • Download .zip or get project module by
git clone https://github.com/MadeYoga/ytpy.git
  • Copy ytpy folder to your project folder

  • import module.

# depends on where you put the package/module
from ytpy.youtube import AioYoutubeService

Asynchronous Youtube Service Object

Use AioYoutubeService object for asynchronous tasks. You can pass your api key on dev_key param when building the object or just set your api key on environment and AioYoutubeService object will automatically get it for you.

# will automatically search and get your api key from environment.
ayt = AioYoutubeService()

# you can also pass it on dev_key param.
ayt = AioYoutubeService(dev_key='replace me')

Asynchronous Search

params:

  • q, string. Search key. default: empty string.
  • part, string. Valid parts: snippet, contentDetails, player, statistics, status. default: snippet.
  • type, string. Valid types: video, playlist, channel.

Example Search method

  ayt = AioYoutubeService()
  # test search
  results = await ayt.search(q="kpop song", search_type="video", max_results=3)
  print(results['items'][0])

Example Asynchronous

async def main():
  ayt = AioYoutubeService()

  # test search
  results = await ayt.search(q="super junior blacksuit", search_type="video", max_results=3)
  print(results['items'][0])

  # test get_playlist
  results = await ayt.get_playlist(max_results=10, playlist_id="PL6GZjIxGO0cOBYqybD7-nNiA-vjF09wpC")
  for item in results['items']:
      print(item['snippet']['title'], item['snippet']['resourceId']['videoId'])

loop = asyncio.get_event_loop()
loop.run_until_complete(main())