diff options
author | Jordan <me@jordan.im> | 2021-06-16 03:04:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 03:04:08 -0700 |
commit | 90e0edf9865fab9822864d1f00d36c4e28a91847 (patch) | |
tree | 2cad90e05483e1b9eeeff827739b41244266938b /lib | |
parent | 4cd0884b307e28bd9f2e531c41fb7b41600b02a4 (diff) | |
parent | e7f4b527e2ee2cbae9f7a53f2a8100fa40bc9138 (diff) | |
download | roka-90e0edf9865fab9822864d1f00d36c4e28a91847.tar.gz roka-90e0edf9865fab9822864d1f00d36c4e28a91847.zip |
Merge pull request #3 from dgarrett/static-generation
Static generation
Diffstat (limited to 'lib')
-rw-r--r-- | lib/books.py | 10 | ||||
-rw-r--r-- | lib/util.py | 7 |
2 files changed, 6 insertions, 11 deletions
diff --git a/lib/books.py b/lib/books.py index 1c4b4a5..95df374 100644 --- a/lib/books.py +++ b/lib/books.py @@ -13,10 +13,6 @@ ABS_PATH = os.path.dirname(os.path.abspath(__file__)) CACHE_PATH = os.path.join(ABS_PATH, '../', 'cache') JSON_PATH = os.path.join(CACHE_PATH, 'audiobooks.json') -# use Flask's config parser, configparser would be hacky -APP = Flask(__name__) -APP.config.from_pyfile(os.path.join(ABS_PATH, '../', 'app.cfg')) - class Books: def __init__(self): ''' @@ -86,7 +82,7 @@ class Books: now = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S") print('%s %s' % (now, msg)) - def scan_books(self): + def scan_books(self, audiobook_path=None): ''' Discover audiobooks under :root_path: and populate books object @@ -94,7 +90,7 @@ class Books: (existing content is not re-hashed) ''' ex = self._get_path_hash_dict() - dirs = self._get_dirs(APP.config['ROOT_PATH']) + dirs = self._get_dirs(audiobook_path) books = dict() for path in dirs: @@ -145,7 +141,7 @@ class Books: # previous conditions met, we've found at least one track is_book = True - self._log(f) + self._log(os.path.join(path, f)) # hash track (used as a key) and update folder hash file_hash = hashlib.md5() diff --git a/lib/util.py b/lib/util.py index 1eb6af6..4693ef1 100644 --- a/lib/util.py +++ b/lib/util.py @@ -78,9 +78,7 @@ def escape(s): return s -def generate_rss(request, books): - book = request.args.get('a') # audiobook hash - +def generate_rss(base_url, book, books, static=False): # we only make use of the itunes ns, others provided for posterity namespaces = { 'itunes':'http://www.itunes.com/dtds/podcast-1.0.dtd', @@ -156,8 +154,9 @@ def generate_rss(request, books): pub_format = '%a, %d %b %Y %H:%M:%S %z' pub_date.text = (date(2000, 12, 31) - timedelta(days=idx)).strftime( pub_format) + url_format = '{}{}/{}.mp3' if static else '{}?a={}&f={}' enc_attr = { - 'url': '{}?a={}&f={}'.format(request.base_url, book, f), + 'url': url_format.format(base_url, book, f), 'length': str(books[book]['files'][f]['size_bytes']), 'type': 'audio/mpeg' } |