在 YouTube 上搜索内容。
项目描述
yt-搜索
英语
安装
需要 Python 3.6.x 或更高版本。
安装命令:
# Linux/OS X
$ python -m pip install -U yt-search
# Windows
> py -3 -m pip install -U yt-search
例子
搜索视频
import yt_search
yt = yt_search.build("API Key")
search_result = yt.search("keyword", sMax=10, sType=["video"])
print(search_result.title)
print(search_result.videoId)
print(search_result.channelTitle)
搜索 YouTube 频道
import yt_search
yt = yt_search.build("API Key")
search_result = yt.search("keyword", sMax=10, sType=["channel"])
print(search_result.channelTitle)
print(search_result.channelId)
搜索播放列表
import yt_search
yt = yt_search.build("API Key")
search_result = yt.search("keyword", sMax=10, sType=["playlist"])
print(search_result.title)
print(search_result.playlistId)
print(search_result.channelTitle)
sType可以通过列表选择多个
import yt_search
yt = yt_search.build("API Key")
search_result = yt.search("keyword", sMax=10, sType=["video", "playlist"])
print(search_result.title)
print(search_result.videoId)
print(search_result.playlistId)
print(search_result.channelTitle)
使用 wav 下载搜索结果
需要 youtube-dl 和 ffmpeg。
import yt_search
import youtube_dl
yt = yt_search.build("API Key")
search_result = yt.search("keyword", sMax=10, sType=["video"])
options = {
'format': 'bestaudio/bestaudio',
'outtmpl': '%(title)s.%(ext)s',
'postprocessors': [
{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav'
},
{
'key': 'FFmpegMetadata'
}
]
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download(["https://www.youtube.com/watch?v=" + i
for i in search_result.videoId])
对于 youtube#video,playlistId 返回 None。对于 youtube#playlist,videoId 返回 None。对于 youtube#channel,playlistId 和 videoId 返回 None。
日本语
因斯图鲁
Python3.6.x以上が必需です。
インストールコマンド:
# Linux/OS X
$ python -m pip install -U yt-search
# Windows
> py -3 -m pip install -U yt-search
プログラムの例子
动画を検索
import yt_search
yt = yt_search.build("APIキー")
search_result = yt.search("キーワード", sMax=10, sType=["video"])
print(search_result.title)
print(search_result.videoId)
print(search_result.channelTitle)
YouTubeチャンネルを検索
import yt_search
yt = yt_search.build("APIキー")
search_result = yt.search("キーワード", sMax=10, sType=["channel"])
print(search_result.channelTitle)
print(search_result.channelId)
プレイリストを検索
import yt_search
yt = yt_search.build("APIキー")
search_result = yt.search("キーワード", sMax=10, sType=["playlist"])
print(search_result.title)
print(search_result.playlistId)
print(search_result.channelTitle)
sTypeはリストで复数选択可能です。
import yt_search
yt = yt_search.build("APIキー")
search_result = yt.search("キーワード", sMax=10, sType=["video", "playlist"])
print(search_result.title)
print(search_result.videoId)
print(search_result.playlistId)
print(search_result.channelTitle)
検索结果をwavでダウンロード
youtube-dlとffmpegが必需です。
import yt_search
import youtube_dl
yt = yt_search.build("APIキー")
search_result = yt.search("キーワード", sMax=10, sType=["video"])
options = {
'format': 'bestaudio/bestaudio',
'outtmpl': '%(title)s.%(ext)s',
'postprocessors': [
{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav'
},
{
'key': 'FFmpegMetadata'
}
]
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download(["https://www.youtube.com/watch?v=" + i
for i in search_result.videoId])
youtube#videoの场合はplaylistIdが、 youtube#playlistの场合はvideoIdが、 youtube#channelの场合はplaylistIdとvideoIdがNoneを返します。 Noneを返さない场合もあります(値があるとき)
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
yt_search-1.1.0.post1.tar.gz
(3.2 kB
查看哈希)
内置分布
yt_search-1.1.0.post1-py3-none-any.whl
(15.8 kB
查看哈希)