Add Radiopublic support.

This commit is contained in:
lost 2021-11-08 00:00:00 +00:00
parent 04e4bfa0eb
commit 6727ec4278
Signed by: 0x80
GPG Key ID: 00B9C3A6C02F71F6
4 changed files with 43 additions and 3 deletions

View File

@ -24,6 +24,8 @@ supported_sites = {
"pocketcasts" : ["pca.st"],
"radiopublic" : ["radiopublic.com"],
"reddit" : ["reddit.com"],
"soundcloud" : ["soundcloud.com"],

View File

@ -0,0 +1,34 @@
#!/usr/bin/python3
from utils import *
from download_page import download
from urllib.parse import unquote
# 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 = search (page, '" alt="RSS feed"/><div>', '</div>')
if not feed is None:
return feed
feed = search (page, '<a href="https://podcasters.radiopublic.com?feedUrl=', '&amp;utm_campaign=landing-page')
if not feed is None:
return unquote(feed)
feed = search (page, '\\\"feedUrl\\\":\\\"', '\\\"')
if not feed is None:
return feed
def extract (url, page=None, network=False, verbosity=3, args={}):
# cannot get feed from URL alone
if not network:
return None
page = download (platform, url, args, verbosity)
feed = extract_from_page (page, verbosity)
if not feed is None:
return feed

View File

@ -37,9 +37,11 @@ def search (content, begins_with, ends_with, index=0, reverse=False):
begins_with = ends_with[::-1]
ends_with = temp[::-1]
# escape + signs as needed
begins_with = begins_with.replace('+', "\+")
ends_with = ends_with.replace('+', "\+")
# escape symbols as needed
# note: backslashes MUST be escaped first.
for symbol in ['\\', '+', '?']:
begins_with = begins_with.replace(symbol, '\\' + symbol)
ends_with = ends_with.replace(symbol, '\\' + symbol)
# look for longest match, not shortest, if one delimeter is empty
if begins_with == '' or ends_with == '':

2
tests/radiopublic.txt Normal file
View File

@ -0,0 +1,2 @@
https://radiopublic.com/ThisAmerLife http://feed.thisamericanlife.org/talpodcast
https://radiopublic.com/ThisAmerLife/s1!7460f http://feed.thisamericanlife.org/talpodcast