api - 将 Apple 播客剧集 id 映射到 rss 提要元素
问题描述
我正在尝试将 Apple 播客的剧集 ID 映射到 RSS 提要中的特定播客条目。假设我有带有以下链接的剧集https://podcasts.apple.com/us/podcast/the-numberphile-podcast/id1441474794?i=1000475383420所以podcast_id=1441474794
和episode_id=1000475383420
. 现在我可以通过以下代码获取带有播客 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 提要响应中的任何位置,因此无法找到与此 ID 对应的剧集。有没有一种干净的方法可以通过 id 找到剧集?例如,带有剧集 id 的 Apple api 调用将为我提供有关剧集的信息,然后我可以将信息与 RSS 提要条目进行匹配。
解决方案
应该在播客 RSS 提要中唯一标识一集的元素/标签是:
<guid>
以下是Apple Podcasts Connect Guide to RSS中的一些相关信息,可能会有所帮助。
如果您可以掌握,<guid>
那么您可以从提要中访问该剧集。
一个不太可靠的选择是尝试<link>
剧集的标签。在您提供的那个 URL 上,有一个指向页面末尾的链接,名为“剧集网站”
这也可能让您在 RSS 提要中获得该剧集的唯一键。但它可能不会在所有情况下都像您期望的那样工作。也就是说,播客 RSS 的创建者/发布者只是在每一集中放置相同的 URL,而不是每集的唯一 URL。
推荐阅读
- javascript - axios数据中的等号导致axios没有发送正确的数据对象
- python - Python读取CSV在数据中添加反斜杠
- ftp - 如何从 Windows 客户端使用 -s 模式从文件 sftp
- r - 如何有效地使用 tidyverse 来延长我的数据集,以便根据存储在列中的范围每个值有一行?
- c# - 如何在 C# 中创建一个简单的字符串索引数组的字符串索引数组?
- r - 根据两个变量计算唯一观察值的计数和比例
- javascript - 节点 JS。Uncaught (in promise) ReferenceError: require is not defined
- python - 无法防止斐波那契“for”循环迭代中的“列表索引超出范围”错误
- reactjs - 从 React 将令牌传递给 axios 的正确方法是什么?
- kotlin - Kotlin MutableList.take 到位了吗?