-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Readme.md): async/await support
- Loading branch information
1 parent
b59efb1
commit 7db7870
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# TYStream | ||
TYStream is A Python library for Twitch & Youtube Stream Notification. | ||
|
||
## 安裝套件 | ||
```python | ||
# Windows | ||
pip install tystream | ||
|
||
# Linux/MacOS | ||
|
||
python3 -m pip install tystream | ||
``` | ||
|
||
## 註冊API | ||
### Twitch | ||
1. 前往 [Twitch Developers](https://dev.twitch.tv/) 並登入你的帳號,接著點擊右上角的 `Your Console`。 | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/8d4137a2-fb1c-4c01-8c1a-a03ea181a1b3) | ||
1. 點選左側欄位的應用程式,再點選 `註冊您的應用程式`。 | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/06011479-aa80-4def-a34a-a5f220ad971c) | ||
3. 為你的應用程式取一個自己的名字!其餘的照圖填入並按下`建立`即可。 | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/12f4e911-abe4-4367-954f-96cacc44f30a) | ||
4. 回到第三步驟的畫面後,點選剛建立好的應用程式最右側按鈕`管理`再點選最底下的 `新密碼` 底下便會多出`用戶端ID`和`用戶端密碼`兩個欄位的金鑰。 | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/1b8a0c62-31c6-4f00-a456-96c7bf4a46b4) | ||
5. 很好,你已經完成了所有步驟!請將剛拿到的兩組金鑰記好,不要隨意外洩! | ||
### Youtube | ||
1. 前往 [Google Cloud Platform](https://console.cloud.google.com/?hl=zh-tw) 並登入你的帳號。 | ||
2. 點選最上方欄位的 `選取專案`,再點選右上角的`新增專案`。 | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/ae2bd559-6a55-4bf8-95d4-86b1e46619b8) | ||
3. 按下`建立`後,依照圖片的搜尋方法找到 `YouTube Data API v3` | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/2697cab3-3ce5-412c-85b8-64abfad8f91d) | ||
> [!WARNING] | ||
> 如果這步驟沒有正確啟用,那麼在使用套件的途中就會出現狀況。 | ||
4. 點選 `啟用` | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/8fd69240-88db-4d7e-b212-28892b142ade) | ||
|
||
5. 啟用完成後,點選左側欄位中的 `憑證`,再點選上方的 `建立憑證`,選擇 `API 金鑰` | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/47666706-c172-4301-a48c-07108e3926c8) | ||
6. 複製彈出視窗的API金鑰,並將此金鑰記下來,大功告成(ノ>ω<)ノ | ||
![image](https://github.com/Mantouisyummy/TYStream/assets/51238168/1b7c2f35-440d-475e-a2d5-ee4a5125a5ea) | ||
|
||
## 如何使用 | ||
|
||
### Twitch | ||
`client_id` 和 `client_secret` 分別為你在 <a href="#twitch">註冊API教學 (Twitch)</a> 中拿到的 `用戶端ID`和`用戶端密碼` | ||
`streamer_name` 為 `twitch.tv/...` 後的名稱 | ||
### 同步方法 | ||
```py | ||
from tystream import Twitch | ||
twitch = Twitch("client_id", "client_secret") | ||
stream = twitch.check_stream_live("streamer_name") | ||
print(stream.url) | ||
``` | ||
### 非同步方法 | ||
```py | ||
from tystream.async_api import Twitch | ||
import asyncio | ||
|
||
async def main(): | ||
twitch = Twitch("1aw3wxdp0w8bbg6q464sh96ocn4f6y", "h07eh797n7hejbct1cqd6drybaq468") | ||
stream = await twitch.check_stream_live("kannazukilubee") | ||
print(stream.url) | ||
|
||
asyncio.run(main()) | ||
``` | ||
|
||
### Youtube | ||
`api_key` 為你在 <a href="#youtube">註冊API教學 (Youtube)</a> 中拿到的 `API金鑰` | ||
`streamer_name` 為實況主頻道網址 `https://www.youtube.com/...` 後的名稱 (有無`@`都亦可) | ||
### 同步方法 | ||
```py | ||
from tystream import Youtube | ||
youtube = Youtube("api_key") | ||
stream = youtube.check_stream_live("streamer_name") | ||
print(stream.url) | ||
``` | ||
### 非同步方法 | ||
```py | ||
from tystream.async_api import Youtube | ||
import asyncio | ||
|
||
async def main(): | ||
youtube = Youtube("AIzaSyC0fyvIgZ6PWbhdRAspm0XCwaNQ3CZLLlA") | ||
stream = await youtube.check_stream_live("kannazukilubee") | ||
print(stream.url) | ||
|
||
asyncio.run(main()) | ||
``` |