From 8e1dfd0be6c691704be2ecd9cc29d2d9f7e93bb9 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 29 Apr 2024 17:36:43 +0200 Subject: [PATCH] draft: added canged version --- music_kraken/objects/source.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/music_kraken/objects/source.py b/music_kraken/objects/source.py index 66a012e..26425a8 100644 --- a/music_kraken/objects/source.py +++ b/music_kraken/objects/source.py @@ -7,6 +7,7 @@ from urllib.parse import urlparse, ParseResult from dataclasses import dataclass, field from functools import cached_property +from ..utils import generate_id from ..utils.enums.source import SourcePages, SourceTypes from ..utils.config import youtube_settings from ..utils.string_processing import hash_url, shorten_display_url @@ -99,6 +100,8 @@ class Source: class SourceCollection: + __change_version__ = generate_id() + _indexed_sources: Dict[str, Source] _page_to_source_list: Dict[SourcePages, List[Source]] @@ -131,9 +134,15 @@ class SourceCollection: else: self._page_to_source_list[source.page_enum].append(source) + changed = False for key in source.indexing_values: + if key not in self._indexed_sources: + changed = True self._indexed_sources[key] = source + if changed: + self.__change_version__ = generate_id() + def extend(self, sources: Iterable[Source]): for source in sources: self.append(source) @@ -148,6 +157,10 @@ class SourceCollection: def source_pages(self) -> Iterable[SourcePages]: return sorted(self._page_to_source_list.keys(), key=lambda page: page.value) + @property + def hash_url_list(self) -> List[str]: + return [hash_url(source.url) for source in self.get_sources()] + @property def url_list(self) -> List[str]: return [source.url for source in self.get_sources()]