No project description provided
Project description
search-youtube-url
這是一個 Python 套件,可以用來搜尋 YouTube 影片並取得其網址。
安裝
使用 pip 來安裝 search-youtube-url:
pip install search-youtube-url
使用方法
首先,你需要從 Google Cloud Platform 取得 YouTube Data API v3 的 API 金鑰,並設定為環境變數 YOUTUBE_API_KEY
。
然後,你可以使用 search_youtube_url
函數來搜尋 YouTube 影片:
from googleapiclient.discovery import build import os from dotenv import load_dotenv
def search_youtube_url(query): load_dotenv() api_key = os.getenv('YOUTUBE_API_KEY') youtube = build('youtube', 'v3', developerKey=api_key) request = youtube.search().list( part="snippet", maxResults=1, q=query ) response = request.execute() if not response['items']: return "No video found" video_id = response['items'][0]['id']['videoId'] video_url = f"https://www.youtube.com/watch?v={video_id}" return video_url
if name == "main": query = "Could an orca give a TED Talk?" print(search_youtube_url(query))
這個函數會回傳搜尋結果中的第一個影片的網址。如果找不到影片,則會回傳 "No video found"。
開發
如果你想要參與開發,請先安裝開發所需的套件:
pip install -r requirements.txt
然後,你可以使用以下命令來執行測試:
python -m unittest discover
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file search-youtube-url-1.0.3.tar.gz
.
File metadata
- Download URL: search-youtube-url-1.0.3.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcb87119c8253f0cae1e4357cc5173005e4a3065a9be74e67e8e2a0ab342d66f |
|
MD5 | 63ed45798f94efffa2bfdbd149598bd9 |
|
BLAKE2b-256 | f354e28c7680ee439d137674aa12fdf9d410032aaad33fb13e583519c1138c25 |
File details
Details for the file search_youtube_url-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: search_youtube_url-1.0.3-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c99f148e0c8639fae56a766ff71878e8415e7f724dff90fe014cb7597058402c |
|
MD5 | a3131407c6785326f260c8209d53aa27 |
|
BLAKE2b-256 | ea5718a37236b4ac7a9169f265234b1256fe3130f6d4889e871c3921b483ee23 |