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.
- Python 3.x
- FFmpeg
- Get Google API' Credential 'API KEY'
- google-api-python-client
- google-auth
- google-auth-httplib2
- oauth2client
- aiohttp
- youtube-dl
- 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
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')
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])
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())