YouTube脚本已停止处理搜索顺序

时间:2019-03-24 06:27:40

标签: bash youtube

加拿大渥太华时间午夜,我通过脚本将视频上传到YouTube频道。

一个小时或以后,我一直在使用脚本获取上次上传的视频的视频ID,它创建了一个iframe文件上传到我的Web服务器。几年后,它已经停止工作了

因为我不是程序员,而且很久以前我进行了设置,所以我不知道从哪里开始。我确实查看了YouTube API网页和控制台,但找不到任何内容。我知道运行脚本不会像过去几年那样返回“ videoid”。

'''
url="https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UCOUnH8qVLmUe_2mmupWzEmQ&maxResults=1&key=DEVELOPERS KEY"

lastVideoId=$(curl -s "$url" | grep videoId | awk -F'[""]' '{print $4}')

'''

出来的结果是将最后一个videoid保存为变量$ lastVideoId

1 个答案:

答案 0 :(得分:1)

这是一种无需googleapis且不需要apikey的解决方案。它使用了您频道的rss供稿,并返回找到的第一个videoid。

# Define RSS feed for your channel
URL="https://www.youtube.com/feeds/videos.xml?channel_id=UCOUnH8qVLmUe_2mmupWzEmQ"
videoid=$(curl -s $URL | grep "/watch?v=" | head -1 | sed "s/.*\?v=\([^\"]*\)\".*/\1/g")
echo $videoid

说明:

curl -s $URL         # get rss feed (curl in silent mode)
|                    # pipe output to...
grep "/watch?v="     # get only video urls
|                    # pipe output to...
head -1              # take first line with url
|                    # pipe output to...
sed "s/              # sed in substitution mode
\?v=                 # search '?v=' in url
\([^\"]*\)\"         # put everything up to next " in arg1 (\1)
.*                   # ignore rest of the line
/\1                  # print only arg1 
/g                   # global on the whole line
相关问题