Add Apple Podcasts.

This commit is contained in:
lost 2021-07-23 00:00:00 +00:00
parent 7cca0eb4d0
commit 09e606af22
3 changed files with 41 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
supported_sites = { supported_sites = {
"apple_podcasts" : [ "podcasts.apple.com" ],
"castro_fm" : ["castro.fm"], "castro_fm" : ["castro.fm"],
"chirbit" : [ "chirbit" : [

View File

@ -0,0 +1,37 @@
#!/usr/bin/python3
from utils import *
from download_page import download
# portable code to get filename
import os
platform = os.path.basename(__file__)
if platform.endswith(".py"):
platform = platform[:(-3)]
def extract_from_page (page, verbosity):
feed_url = search (page, '"feedUrl":"', '"')
if not feed_url is None:
return feed_url
def extract (url, page=None, network=False, verbosity=3, args={}):
notify ("Unable to get feed from URL alone", verbosity, platform)
if network == True:
# the format is like
# https://podcasts.apple.com/us/podcast/the-api-academy-podcast/id1171911720
# and we want the number after domain/country/podcast/name/id
# in this example, 1171911720
podcast_id = url[url.find("/podcast/")+len("/podcast/"):]
podcast_id = podcast_id[podcast_id.find("/id")+len("/id"):]
# strip stuff from end
for symbol in ["/", "?", "&", ";"]:
if symbol in podcast_id:
podcast_id = podcast_id[:podcast_id.index(symbol)]
query_url = "https://itunes.apple.com/lookup?entity=podcast&id=" + podcast_id
# Apple API query about podcast (returns JSON object)
debug ("Querying Apple API for " + podcast_id + "...", verbosity, platform)
page = download (platform, query_url, args, verbosity)
feed = extract_from_page (page, verbosity)
if not feed is None:
return feed

2
tests/apple_podcasts.txt Normal file
View File

@ -0,0 +1,2 @@
https://podcasts.apple.com/us/podcast/the-api-academy-podcast/id1171911720 https://feeds.soundcloud.com/users/soundcloud:users:262261799/sounds.rss
https://podcasts.apple.com/us/podcast/darknet-diaries/id1296350485 https://feeds.megaphone.fm/darknetdiaries