mirror of
https://github.com/bspeice/elektricity
synced 2024-12-21 07:28:08 -05:00
Now working with Pocket Casts!
This commit is contained in:
parent
e4a99c0fde
commit
5853c86a2d
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -9,3 +9,4 @@ subfactory-show:
|
||||
class: BassdriveFeed
|
||||
args:
|
||||
url: http://archives.bassdrivearchive.com/1%20-%20Monday/Subfactory%20Show%20-%20DJ%20Spim/
|
||||
logo: http://www.bassdrive.com/img/radio_schedule_entries/image/original/subfactory-web-add-56.jpg
|
||||
|
@ -5,16 +5,17 @@ off the server.
|
||||
from importlib import import_module
|
||||
import yaml
|
||||
from pyramid.config import Configurator
|
||||
from os.path import expanduser, join
|
||||
|
||||
# Needed for import_module call
|
||||
# noinspection PyUnresolvedReferences
|
||||
import modules
|
||||
|
||||
# Hardcoded, need to look up from users $HOME later
|
||||
file_loc = 'example_conf.yaml'
|
||||
|
||||
def build_configuration(conf=None) -> Configurator:
|
||||
if conf is None:
|
||||
conf = join(expanduser('~'), '.repodrc')
|
||||
|
||||
def build_configuration(conf=file_loc) -> Configurator:
|
||||
with open(conf) as conf_file:
|
||||
conf_dict = yaml.load(conf_file)
|
||||
server_conf = Configurator()
|
||||
|
@ -1,11 +0,0 @@
|
||||
# Format: (all args are passed to __init__ as kwargs
|
||||
#
|
||||
# <mountpoint>:
|
||||
# class: <feed_class>
|
||||
# args:
|
||||
# key: value
|
||||
subfactory-show:
|
||||
package: bassdrive
|
||||
class: BassdriveFeed
|
||||
args:
|
||||
url: http://archives.bassdrivearchive.com/1%20-%20Monday/Subfactory%20Show%20-%20DJ%20Spim/
|
@ -8,13 +8,18 @@ import requests
|
||||
from feedgen.feed import FeedGenerator
|
||||
|
||||
from podcast import BasePodcast
|
||||
from datetime import datetime
|
||||
from pytz import UTC
|
||||
|
||||
|
||||
class BassdriveParser(HTMLParser):
|
||||
links = []
|
||||
record_link_text = False
|
||||
link_url = ''
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.links = []
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
href = ''
|
||||
for attr, val in attrs:
|
||||
@ -27,20 +32,21 @@ class BassdriveParser(HTMLParser):
|
||||
|
||||
def handle_data(self, data):
|
||||
if self.record_link_text:
|
||||
print(self.link_url)
|
||||
self.links.append((data, self.link_url))
|
||||
self.record_link_text = False
|
||||
|
||||
def get_links(self):
|
||||
# Reverse to sort in descending date order
|
||||
self.links.reverse()
|
||||
return self.links
|
||||
|
||||
def clear_links(self):
|
||||
self.links = []
|
||||
|
||||
|
||||
class BassdriveFeed(BasePodcast):
|
||||
def __init__(self, *args, **kwargs):
|
||||
print(kwargs)
|
||||
self.url = kwargs['url']
|
||||
self.logo = kwargs['logo']
|
||||
# Get the title and DJ while handling trailing slash
|
||||
url_pretty = unquote(self.url)
|
||||
elems = filter(lambda x: x, url_pretty.split('/'))
|
||||
@ -56,13 +62,14 @@ class BassdriveFeed(BasePodcast):
|
||||
|
||||
# And turn them into something usable
|
||||
fg = FeedGenerator()
|
||||
fg.load_extension('podcast')
|
||||
#fg.load_extension('podcast')
|
||||
fg.id(self.url)
|
||||
fg.title(self.title)
|
||||
fg.description(self.title)
|
||||
fg.author({'name': self.dj})
|
||||
fg.language('en')
|
||||
fg.link({'href': self.url, 'rel': 'alternate'})
|
||||
fg.logo(self.logo)
|
||||
|
||||
for link in links:
|
||||
fe = fg.add_entry()
|
||||
@ -71,4 +78,14 @@ class BassdriveFeed(BasePodcast):
|
||||
fe.description(link[0])
|
||||
fe.enclosure(self.url + link[1], 0, 'audio/mpeg')
|
||||
|
||||
# Bassdrive always uses date strings of
|
||||
# [yyyy.mm.dd] with 0 padding, so that
|
||||
# makes our lives easy
|
||||
date_start = link[0].find('[')
|
||||
date_str = link[0][date_start:date_start+12]
|
||||
published = datetime.strptime(date_str, '[%Y.%m.%d]')
|
||||
fe.pubdate(UTC.localize(published))
|
||||
fe.guid((link[0]))
|
||||
|
||||
parser.clear_links()
|
||||
return fg
|
||||
|
@ -4,7 +4,9 @@ Base skeleton for what needs to be implemented by a podcast provider
|
||||
from feedgen.feed import FeedGenerator
|
||||
from pyramid.response import Response
|
||||
|
||||
|
||||
class BasePodcast():
|
||||
|
||||
def build_feed(self) -> FeedGenerator:
|
||||
"Return a list of all episodes, in descending date order"
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user