diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/example_conf.yaml b/example_conf.yaml index fe79036..bc9a3de 100644 --- a/example_conf.yaml +++ b/example_conf.yaml @@ -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 diff --git a/repod/conf_parser.py b/repod/conf_parser.py index 32d7102..93fc399 100644 --- a/repod/conf_parser.py +++ b/repod/conf_parser.py @@ -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() diff --git a/repod/example_conf.yaml b/repod/example_conf.yaml deleted file mode 100644 index fe79036..0000000 --- a/repod/example_conf.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# Format: (all args are passed to __init__ as kwargs -# -# : -# class: -# args: -# key: value -subfactory-show: - package: bassdrive - class: BassdriveFeed - args: - url: http://archives.bassdrivearchive.com/1%20-%20Monday/Subfactory%20Show%20-%20DJ%20Spim/ diff --git a/repod/modules/bassdrive.py b/repod/modules/bassdrive.py index 5c1f027..6bfd95d 100644 --- a/repod/modules/bassdrive.py +++ b/repod/modules/bassdrive.py @@ -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 diff --git a/repod/podcast.py b/repod/podcast.py index 0637d76..e5da250 100644 --- a/repod/podcast.py +++ b/repod/podcast.py @@ -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