45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
#!/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):
|
|
return search (page, '•<a class="blatant" href="', '">Feed</a></div>')
|
|
|
|
def extract (url, page=None, network=False, verbosity=3, args={}):
|
|
# cannot get feed from URL alone
|
|
if not network:
|
|
return None
|
|
|
|
if not "player.fm/series/" in url:
|
|
# it might be a page that redirects to /series/something
|
|
page = download (platform, url, args, verbosity, follow_location=False)
|
|
redirect_link = search (page, '<html><body>You are being <a href="', '">redirected</a>.</body></html>')
|
|
if not redirect_link is None:
|
|
url = redirect_link
|
|
else:
|
|
return None
|
|
|
|
# if it's in the form player.fm/series/series-name then get that page
|
|
index = url.find("player.fm/series/")
|
|
series = url[index + len("player.fm/series/"):]
|
|
|
|
# if it's player.fm/series/series-name/episode-name truncate to
|
|
# player.fm/series/series-name
|
|
index2 = series.find("/")
|
|
if index2 >= 0:
|
|
series = series[:index2]
|
|
|
|
page_to_download = "https://player.fm/series/" + series
|
|
|
|
page = download (platform, page_to_download, args, verbosity)
|
|
feed = extract_from_page (page, verbosity)
|
|
if not feed is None:
|
|
return feed
|