bash 使用 shell 脚本读取 RSS 提要

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8632233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:13:11  来源:igfitidea点击:

Read RSS feed using a shell script

bashunixrssfeedpodcast

提问by

Edit: Translated

编辑:翻译

I have a RSS-feed that i want to parse. It's a podcast and I want just the MP3-urls to download them with wget.

我有一个要解析的 RSS 提要。这是一个播客,我只想用 wget 下载 MP3 网址。

This is the podcast: http://feeds.feedburner.com/Film-UndKino-trailerVideopodcast

这是播客:http: //feeds.feedburner.com/Film-UndKino-trailerVideopodcast

The title should include an (de)to get just the german episodes. The publish-date should be today.

标题应包含一个(de)以获取德国剧集。发布日期应该是今天。

Would be great if someone could help me – I came this far:

如果有人能帮助我就好了——我走到了这一步:

wget -q -O- view-source:http://feeds.feedburner.com/Film-UndKino-trailerVideopodcast?format=xml| awk 'BEGIN{RS=""}
/(date +'%d %M %Y')/{
gsub(/.*|.*/,"")
print
}

But it doesn't work.

但它不起作用。

Thanks in advance, arneb3rt

提前致谢,arneb3rt

采纳答案by ZaSter

You need to drop the "view-source:" from the wget command and execute the date command (with %b to print the abbreviated month instead of %M) outside of the awk command. The following bash script uses grep instead of awk to produce the URLs of where wget can fetch the podcasts.

您需要从 wget 命令中删除“view-source:”并在 awk 命令之外执行 date 命令(使用 %b 打印缩写的月份而不是 %M)。以下 bash 脚本使用 grep 而不是 awk 来生成 wget 可以获取播客的 URL。

Note that, probably due to the holidays, there have been no podcasts since 24 Dec 2011 at the feed, so I hard-coded the date of the last podcast for testing:

请注意,可能由于假期的原因,自 2011 年 12 月 24 日以来,提要中没有播客,因此我硬编码了上次播客的日期以进行测试:

url='http://feeds.feedburner.com/Film-UndKino-trailerVideopodcast?format=xml'
d=$(date +'%d %b %Y')
d="24 Dec 2011"
echo "Checking podcasts for date: ${d}"
wget -q -O- ${url} |\
 grep -A6 "(de)" |\
 grep -A1 "${d}" |\
 egrep -o 'http[^ ]*de.mp4' |\
 sort | uniq

The output of the above bash script lists two URLs (one feedburner and the other iTunes):

上述 bash 脚本的输出列出了两个 URL(一个 feedburner 和另一个 iTunes):

Checking podcasts for date: 24 Dec 2011
http://feedproxy.google.com/~r/Film-UndKino-trailerVideopodcast/~5/pzeSvkVK-3A/trailer01_de.mp4
http://www.moviemaze-trailer.de/ipod/6841/trailer01_de.mp4

Therefore, you could wget the 24 Dec 2011 podcast from either of the above URLs.

因此,您可以从上述任一网址获取 2011 年 12 月 24 日的播客。