diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..3d9e57b --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python elektricity/server.py diff --git a/README.md b/README.md index 0fe2030..6bcc1c1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ -# Repod +# Elektricity A server designed to make it easy to re-broadcast existing content -as a podcast. +as a podcast. Named after [London Elektricity][1] who, among other +things, hosts the [Hospital Podcast][2]. --- -The purpose of Repod is to take content that exists on the web already, +The purpose of Elektricity is to take content that exists on the web already, and turn it into a podcast to consume whenever you want. Specifically, I'm a huge Drum & Bass head that wanted an easy way to access [the Bassdrive archives](http://archives.bassdrivearchive.com/) since @@ -19,3 +20,6 @@ Future ideas: Turn your mixcloud feed into a podcast? Repod is currently very bare-bones, but the Requirements file should be enough to get up and running. + +[1]: https://www.youtube.com/watch?v=6IRiuLy0IW4 +[2]: https://www.hospitalrecords.com/podcast/ diff --git a/default_conf.yaml b/default_conf.yaml new file mode 100644 index 0000000..bcf7512 --- /dev/null +++ b/default_conf.yaml @@ -0,0 +1,20 @@ +# 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/ + logo: http://www.bassdrive.com/img/radio_schedule_entries/image/original/subfactory-web-add-56.jpg + +electronic-warfare: + package: bassdrive + class: BassdriveFeed + args: + url: http://archives.bassdrivearchive.com/6%20-%20Saturday/Electronic%20Warfare%20-%20The%20Overfiend/ + logo: http://bassdrive.com/img/radio_schedule_entries/image/original/front-page-intro-box-200x200-115.jpg diff --git a/elektricity/.server.py.swp b/elektricity/.server.py.swp new file mode 100644 index 0000000..ce33a28 Binary files /dev/null and b/elektricity/.server.py.swp differ diff --git a/src/__init__.py b/elektricity/__init__.py similarity index 100% rename from src/__init__.py rename to elektricity/__init__.py diff --git a/elektricity/conf_parser.py b/elektricity/conf_parser.py new file mode 100755 index 0000000..37d6e20 --- /dev/null +++ b/elektricity/conf_parser.py @@ -0,0 +1,30 @@ +""" +Given a configuration file, set up everything needed to kick +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 podcasters + + +def build_configuration(conf=None) -> Configurator: + if conf is None: + conf = join(expanduser('~'), '.repodrc') + + server_conf = Configurator() + with open(conf) as conf_file: + conf_dict = yaml.load(conf_file) + for mountpoint, feed in conf_dict.items(): + feed_package = import_module('podcasters.' + feed['package']) + feed_class = getattr(feed_package, feed['class']) + feed_instance = feed_class(**feed['args']) + + server_conf.add_route(mountpoint, '/' + mountpoint + '/') + server_conf.add_view(feed_instance.view, route_name=mountpoint) + + return server_conf diff --git a/src/podcasters/__init__.py b/elektricity/podcasters/__init__.py similarity index 100% rename from src/podcasters/__init__.py rename to elektricity/podcasters/__init__.py diff --git a/src/podcasters/base.py b/elektricity/podcasters/base.py similarity index 100% rename from src/podcasters/base.py rename to elektricity/podcasters/base.py diff --git a/src/podcasters/bassdrive.py b/elektricity/podcasters/bassdrive.py similarity index 100% rename from src/podcasters/bassdrive.py rename to elektricity/podcasters/bassdrive.py diff --git a/src/server.py b/elektricity/server.py similarity index 74% rename from src/server.py rename to elektricity/server.py index 94f44ac..6f38e7e 100644 --- a/src/server.py +++ b/elektricity/server.py @@ -1,6 +1,6 @@ import argparse import traceback -from os.path import expanduser, join +from os.path import expanduser, join, dirname, realpath from wsgiref.simple_server import make_server from pyramid.config import Configurator @@ -12,14 +12,15 @@ from conf_parser import build_configuration def start_server(server_conf: dict, configurator: Configurator) -> None: app = configurator.make_wsgi_app() - port = server_conf['port'] if 'port' in server_conf else cmd_args.port - host = server_conf['host'] if 'host' in server_conf else cmd_args.host + port = server_conf['port'] + host = server_conf['host'] server = make_server(host, port, app) server.serve_forever() if __name__ == '__main__': - default_rc = join(expanduser('~'), '.repodrc') + # default_rc = join(expanduser('~'), '.repodrc') + default_rc = join(dirname(realpath(__file__)), '../default_conf.yaml') parser = argparse.ArgumentParser() parser.add_argument('--verbose', action='store_true', help='Run server in verbose mode') @@ -32,7 +33,11 @@ if __name__ == '__main__': cmd_args = parser.parse_args() try: - server_conf, configurator = build_configuration(cmd_args.configuration) + configurator = build_configuration(cmd_args.configuration) + server_conf = { + 'host': cmd_args.host, + 'port': cmd_args.port + } start_server(server_conf, configurator) except FileNotFoundError: print("Unable to find configuration file. Does {} exist?" @@ -44,8 +49,3 @@ if __name__ == '__main__': .format(cmd_args.configuration)) if cmd_args.verbose: print(traceback.format_exc()) - except KeyError: - print('Unable to parse configuration file. Is there a `podcasts` ' - 'section?') - if cmd_args.verbose: - print(traceback.format_exc()) diff --git a/src/tests/__init__.py b/elektricity/tests/__init__.py similarity index 100% rename from src/tests/__init__.py rename to elektricity/tests/__init__.py diff --git a/example_conf.yaml b/example_conf.yaml deleted file mode 100644 index b520c75..0000000 --- a/example_conf.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Format (all args are passed to __init__ as kwargs: -# -# : -# class: -# args: -# key: value -server: - port: 10000 - -podcasts: - subfactory-show: - class: podcasters.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/requirements.txt b/requirements.txt index 5477442..2b2e8d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +python>=3.5.0 pyramid>=1.6.1 feedgen>=0.3.2 PyYAML>=3.11 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..c0354ee --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.5.2 diff --git a/src/conf_parser.py b/src/conf_parser.py deleted file mode 100644 index 9233940..0000000 --- a/src/conf_parser.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Given a configuration file, set up everything needed to kick -off the server. -""" -from importlib import import_module - -import yaml -from pyramid.config import Configurator - - -def build_configurator(podcasts: dict) -> Configurator: - server_conf = Configurator() - for mountpoint, feed in podcasts.items(): - package, class_name = feed['class'].rsplit('.', 1) - feed_package = import_module(package) - feed_class = getattr(feed_package, class_name) - feed_instance = feed_class(**feed) - - server_conf.add_route(mountpoint, '/' + mountpoint + '/') - server_conf.add_view(feed_instance.view, route_name=mountpoint) - - return server_conf - - -def build_configuration_text(file_str: str) -> (dict, Configurator): - conf_dict = yaml.load(file_str) - - server_opts = conf_dict.get('server', None) - podcasts = build_configurator(conf_dict['podcasts']) - return server_opts, podcasts - - -def build_configuration(file_name) -> (dict, Configurator): - try: - with open(file_name) as conf_file: - return build_configuration_text(conf_file.read()) - except FileNotFoundError: - print("Could not locate configuration file " + - "(does {} exist?)".format(file_name)) - raise