我正在尝试将Apple播客的剧集id映射到RSS提要中的特定播客条目。假设我有一个带有以下链接的插曲,所以https://podcasts.apple.com/us/podcast/the-numberphile-podcast/id1441474794?i=1000475383420 podcast_id=1441474794和episode_id=1000475383420。现在我可以通过下面的代码获得带有podcast id的RSS提要:
from urllib.request import urlopen
import json
import xmltodict
podcast_id = "1441474794"
ITUNES_URL = 'https://itunes.apple.com/lookup?id='
with urlopen(ITUNES_URL + podcast_id) as response:
res = json.load(response)
feedUrl = res['results'][0]['feedUrl']
print(feedUrl)
with urlopen(feedUrl) as response:
res = xmltodict.parse(response)
with open('res.json', "w") as f:
f.write(json.dumps(res))这为我提供了一个JSON,其中包含一些关于播客的一般信息,以及一个包含所有剧集的数组。对于特定的一集,结果如下所示:
"item": [
{
"title": "The Parker Quiz - with Matt Parker",
"dc:creator": "Brady Haran",
"pubDate": "Thu, 21 May 2020 16:59:08 +0000",
"link": "https://www.numberphile.com/podcast/matt-parker-quiz",
"guid": {
"@isPermaLink": "false",
"#text": "5b2cf993266c07b1ca7a812f:5bd2f1a04785d353e1b39d76:5ec683354f70a700f9f04555"
},
"description": "some description here...",
"itunes:author": "Numberphile Podcast",
"itunes:subtitle": "Matt Parker takes a quiz prepared by Brady. The YouTube version of this quiz contains a few visuals at https://youtu.be/hMwQwppzrys",
"itunes:explicit": "no",
"itunes:duration": "00:55:34",
"itunes:image": {
"@href": "https://images.squarespace-cdn.com/content/5b2cf993266c07b1ca7a812f/1541821254439-PW3116VHYDC1Y3V7GI0A/podcast_square2_2000x2000.jpg?format=1500w&content-type=image%2Fjpeg"
},
"itunes:title": "The Parker Quiz - with Matt Parker",
"enclosure": {
"@url": "https://traffic.libsyn.com/secure/numberphile/numberphile_parker_quiz.mp3",
"@type": "audio/mpeg"
},
"media:content": {
"@url": "https://traffic.libsyn.com/secure/numberphile/numberphile_parker_quiz.mp3",
"@type": "audio/mpeg",
"@isDefault": "true",
"@medium": "audio",
"media:title": {
"@type": "plain",
"#text": "The Parker Quiz - with Matt Parker"
}
}
},
...]episode_id=1000475383420不会出现在RSS feed响应中的任何地方,因此无法找到与此id对应的剧集。有没有一种干净的方法可以通过id找到这一集?例如,一个带有剧集id的Apple api调用将为我提供关于剧集的信息,然后我可以将该信息与RSS提要条目进行匹配。
发布于 2020-05-29 19:18:47
用于唯一标识播客RSS提要中的一集的元素/标记为:
<guid>
这里有一些来自Apple Podcasts Connect Guide to RSS的相关信息,可能会有所帮助。
如果你能获得<guid>,那么你就可以从提要中访问这一集。
一个不太可靠的选择是尝试剧集的<link>标记。在您提供的URL上,有一个指向页面末尾的链接,名为“Episode”

这也可能让你在RSS提要中获得这一集的唯一关键字。但它可能并不是在所有情况下都能像您预期的那样工作。也就是说,播客RSS的创建者/发布者只是在每集中简单地放入相同的URL,而不是每集唯一的URL。
发布于 2021-05-11 04:44:33
是的,第二个回应是一个通用的播客rss源,独立于苹果或其他来源。我从来没有期望它会有苹果/播客播放器特定的结果。
我能做的最好的事情就是在页面上做一个基于json-ld元数据的标题匹配。json-ld数据是语义数据(vs表示),所以不太可能发生变化。我使用extruct库似乎是希望提取有意义的元数据,使用jsonpath_rw解析json文本(神奇的库)
import extruct
from jsonpath_rw import parse
metadata = extruct.extract(itunes_podcast_episode_html, uniform=True)
title_pattern = "[json-ld][*]['name']"
expr = parse(title_pattern)
title = [match.value for match in expr.find(metadata)][0]
print(f"itunes podcast episode name = '{title}'")https://stackoverflow.com/questions/62055108
复制相似问题