diff --git a/python/podcast/data_migration.py b/python/podcast/data_migration.py index b278fa04cbbc93b08d517faf4ba8a7c6e51d6713..a7bcdbc55e720a2e2ef1180783b916256d1cc490 100644 --- a/python/podcast/data_migration.py +++ b/python/podcast/data_migration.py @@ -12,8 +12,10 @@ logger = logging.getLogger(__name__) def needs_migration(): target_data_version = 1 + def app_is_pristine(): return len(list(PodcastListFactory().get_podcast_list().get_podcasts())) == 0 + if get_versionnumber() >= target_data_version: return False else: @@ -23,13 +25,14 @@ def needs_migration(): else: return True + def run_migrations(): current_version = get_versionnumber() - if(current_version < 1): - logger.info("Migrating from version %d to version 1",current_version) + if (current_version < 1): + logger.info("Migrating from version %d to version 1", current_version) podcasts = list(PodcastListFactory().get_podcast_list().get_podcasts()) pyotherside.send("migrationStart", len(podcasts)) - i : int = 0 + i: int = 0 for podcast_url in podcasts: podcast = PodcastFactory().get_podcast(podcast_url) if podcast != None: @@ -42,7 +45,6 @@ def run_migrations(): pyotherside.send("migrationDone") - def get_versionnumber() -> int: versionfilepath = get_versionfile_path() if os.path.isfile(versionfilepath): @@ -61,9 +63,17 @@ def set_versionnumber(number: int): def get_versionfile_path(): return os.path.join(Factory().data_home, "dataversion") + def migrate_podpost_v0_v1(self: Podpost): - self.isaudio = False - self.save() + if hasattr(self, "entry"): + if not hasattr(self, "isaudio"): + self.isaudio = False + if not hasattr(self, "length"): + self.length = 0 + if not self.isaudio: + self.init(self.entry, self.logo_url, self.podurl) + self.save() + def migrate_podcast_v0_v1(self: Podcast): logger.info("migrating podcast '%s' to new format version 1", self.title) @@ -101,4 +111,3 @@ def migrate_podcast_v0_v1(self: Podcast): len(entry_ids_new_to_old)) except: logger.exception("error while migrating podcast %s to new format", self.title) - diff --git a/python/podcast/podpost.py b/python/podcast/podpost.py index b13c9af556b43ee3c2746a7a74a54ffec5dcba51..b858fc79eae48ad24354aa46724e0e48fdc37a3b 100644 --- a/python/podcast/podpost.py +++ b/python/podcast/podpost.py @@ -66,8 +66,6 @@ class Podpost: entry: the entry took from feedparser podcast: podcast url """ - self.version = 1 - self.isaudio = isaudio self.position = 0 self.state = STOP @@ -78,24 +76,30 @@ class Podpost: self.href = "" if isaudio: - self.title = data["title"] - self.plainpart = self.htmlpart = data["description"] - self.author = data["author"] - self.logo_url = self.logo_path = logo_url - self.file_path = podurl - self.href = podurl - self.duration = int(data["duration"]) - self.id = data["id"] - self.length = int(data["length"]) - self.published = 0 - self.insert_date = None - self.link = None - self.type = data["mime"] - self.podurl = podurl - self.chapters = [] - self.save() + self.init_file_entry(data, logo_url, podurl) return + self.init(entry, logo_url, podurl) + + def init_file_entry(self, data, logo_url, podurl): + self.title = data["title"] + self.plainpart = self.htmlpart = data["description"] + self.author = data["author"] + self.logo_url = self.logo_path = logo_url + self.file_path = podurl + self.href = podurl + self.duration = int(data["duration"]) + self.id = data["id"] + self.length = int(data["length"]) + self.published = 0 + self.insert_date = None + self.link = None + self.type = data["mime"] + self.podurl = podurl + self.chapters = [] + + def init(self, entry, logo_url, podurl): + self.length = 0 self.podurl = podurl self.logo_url = logo_url self.logo_path = None @@ -113,23 +117,19 @@ class Podpost: self.published = mktime_tz(parsedate_tz(entry.published)) except: self.published = 0 - self.title = entry.title if "link" in entry: self.link = entry.link else: self.link = None - self.plainpart = None self.htmlpart = None - if "content" in entry.keys(): for cont in entry.content: if cont.type == "text/html": self.htmlpart = cont.value if cont.type == "text/plain": self.plainpart = cont.value - if not self.plainpart: try: self.plainpart = entry.summary @@ -140,18 +140,14 @@ class Podpost: self.htmlpart = entry.summary_detail.value except: self.htmlpart = "" - h = html2text.HTML2Text() h.ignore_links = True h.ignore_images = True - self.plainpart = h.handle(self.plainpart) - if "author" in entry.keys(): self.author = entry.author else: self.author = "" - if "id" in entry: if entry.id != "": self.id = hashlib.sha256(entry.id.encode()).hexdigest() @@ -160,7 +156,6 @@ class Podpost: self.id = hashlib.sha256(entry.summary.encode()).hexdigest() else: self.id = hashlib.sha256(entry.summary.encode()).hexdigest() - for e in entry.enclosures: if e.type[:5] == "audio": if "length" in e.keys(): @@ -177,9 +172,7 @@ class Podpost: self.length = 0 self.type = "audio/mp3" self.href = e.href - self.file_path = None - if "itunes_duration" in entry: try: self.duration = tx_to_s(entry.itunes_duration) @@ -187,7 +180,6 @@ class Podpost: self.duration = None else: self.duration = None - if "psc_chapters" in entry: self.chapters = entry.psc_chapters.chapters else: diff --git a/qml/pages/Inbox.qml b/qml/pages/Inbox.qml index 7767e6548fd4faec90aa8d06bdaadde1d59e5581..0fa4cbb0c7d06f23dca08f71dc7cb2ef89b0df8d 100644 --- a/qml/pages/Inbox.qml +++ b/qml/pages/Inbox.qml @@ -37,7 +37,7 @@ Page { } Connections { - target: feedparser + target: feedparserhandler onNewPodcasts: { inboxhandler.getInboxEntries(podqast.ifilter) inboxhandler.getInboxPodData() @@ -58,7 +58,7 @@ Page { Column { id: allmovecol anchors.verticalCenter: parent.verticalCenter - anchors.left: placeholder.right + anchors.left: parent.left IconButton { id: allmoveicon icon.source: "image://theme/icon-m-backup"