diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2025-03-28 00:13:54 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2025-03-28 00:13:54 -0700 |
commit | cd3fdeebb206e050066a087b7b2eeca5ca37efb4 (patch) | |
tree | 27169eb9f0414247c67ab79e58a726c91b13caa3 /PodWeb.py | |
parent | 8fe3517b88696732c51ae2d118e88312fcc2ff5a (diff) | |
download | podweb-cd3fdeebb206e050066a087b7b2eeca5ca37efb4.tar.gz |
fix podcast numbers, add mimetype
Also added fetch, which crashes the program. From here, only the CLI needs to be implemented, as well as .m3u generation.
Diffstat (limited to 'PodWeb.py')
-rwxr-xr-x | PodWeb.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/PodWeb.py b/PodWeb.py index 3974192..954e71e 100755 --- a/PodWeb.py +++ b/PodWeb.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import json import logging +import mimetypes import os import pprint import sqlite3 @@ -141,6 +142,7 @@ class PodWeb: "website" TEXT, "season" INTEGER, "deleted" BOOL NOT NULL CHECK("deleted" in (0,1)), + "number" INTEGER NOT NULL, PRIMARY KEY("guid","podcast_url") ) """ @@ -295,6 +297,7 @@ class PodWeb: break guid_list = [] parsed["episodes"].reverse() + number = 1 for i in parsed["episodes"]: enclosure_list = sorted( i["enclosures"], key=lambda d: d["file_size"], reverse=min_size @@ -319,7 +322,8 @@ class PodWeb: :URL, :WEBSITE, :SEASON, - :DELETED + :DELETED, + :NUMBER ); """, { @@ -332,9 +336,11 @@ class PodWeb: "WEBSITE": i["link"], "SEASON": i.get("number", -1), "DELETED": False, + "NUMBER": number, }, ) self.con.commit() + number += 1 guid_list.append(i["guid"]) self.data.execute( """ @@ -369,13 +375,13 @@ class PodWeb: return None response = self.data.execute( """ - SELECT "url","podcast_url","title","rowid" + SELECT "url","podcast_url","title","number" FROM "episodes" WHERE guid = :GUID; """, {"GUID": guid}, ) - url, feedurl, title, rowid = response.fetchone() + url, feedurl, title, number = response.fetchone() if url == None: click.echo("No URL found!", err=True) return 1 @@ -390,8 +396,10 @@ class PodWeb: audio_response = urllib.request.urlopen(request_obj) audio_data = audio_response.read() mime_type = audio_response.info().get_content_type() + ext = mimetypes.guess_extension(mime_type) + ext = "mp3" if ext is None else ext podcast = next(iter([i for i in self.servers if i["url"] == feedurl])) - filename = f"{rowid:09}.{guid}.{self.safe_filename(title)}.mp3" + filename = f"{number:09}.{guid}.{self.safe_filename(title)}.{ext}" filepath = os.path.join(options["downloadlocation"], podcast["name"]) if not os.path.exists(filepath): os.makedirs(filepath) @@ -552,5 +560,12 @@ def import_opml(obj, opml_file: str): click.echo(f"imported {opml_file}") +@cli.command() +@click.pass_obj +@click.option("-i", "--index") +def fetch(obj, index: str | None): + obj.fetch(index) + + if __name__ == "__main__": cli() |