Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/madeyoga/aio-ytpy
Browse files Browse the repository at this point in the history
  • Loading branch information
madeyoga committed Oct 25, 2020
2 parents 14a9390 + 5174852 commit 16c18a0
Showing 1 changed file with 53 additions and 14 deletions.
67 changes: 53 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The purpose of this project is to make it easier for developers to extract data

## Requirements
- Python 3.x
- [Get Google API' Credential 'API KEY'](https://developers.google.com/youtube/registering_an_application)
- [Get Google API' Credential 'API KEY'](https://developers.google.com/youtube/registering_an_application) for `YoutubeApiV3Client`

## Dependencies
- urllib
Expand All @@ -29,8 +29,8 @@ pip install --upgrade ytpy
- On project root. run command:
```python ytpy/test/test_import.py```

### Asynchronous Youtube Service Object
Use `AioYoutubeService` object for asynchronous tasks.
### Asynchronous Youtube API V3 Client
Use `AioYoutubeService` or `YoutubeApiV3Client` 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 variable named `DEVELOPER_KEY` and `AioYoutubeService` object will get it for you.
```py
import aiohttp
Expand All @@ -46,7 +46,7 @@ ayt = AioYoutubeService(session, dev_key='replace me')
session.close()
```

### Basic Usage: Search Video by `Search Key`
### Basic Usage: Search Video by `Keywords`
https://developers.google.com/youtube/v3/docs/search

params:
Expand All @@ -56,16 +56,55 @@ params:

Example `Search` method
```py
async def main():
session = aiohttp.ClientSession()

ayt = AioYoutubeService(session, dev_key='<replace-me>')

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

session.close()
import os
import asyncio
import aiohttp
from ytpy import YoutubeApiV3Client

async def main(loop):
session = aiohttp.ClientSession()

# Pass the aiohttp client session
ayt = YoutubeApiV3Client(session, dev_key=os.environ["DEVELOPER_KEY"])

# test search
results = await ayt.search(q="d&e lost",
search_type="video",
max_results=1)
print(results)

await session.close()

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

### Basic Usage: Search Video by `Keywords` (Without api key)

params:
- `q`, string. Search key. default: empty string.
- `max_results`

Example `Search` method (Without api key)
```py
from ytpy import YoutubeClient
import asyncio
import aiohttp

async def main(loop):
session = aiohttp.ClientSession()

client = YoutubeClient(session)

response = await client.search('chico love letter')
print(response)

await session.close()

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

```

### Examples
Expand Down

0 comments on commit 16c18a0

Please sign in to comment.