add MediaCollection|MediaElement.add_single_uri and rewrite appropiate usages

master
Felix Stupp 3 years ago
parent c77e0ac81e
commit 5b78e8120c
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -23,7 +23,7 @@ class CollectionExtractor(GeneralExtractor[MediaCollection, T]):
f"Add missing URI mapping entry for uri {uri!r}, " +
"this should not happen at this point and is considered a bug"
)
elem.add_uris((uri,))
elem.add_single_uri(uri)
return elem
return None

@ -85,7 +85,7 @@ class YouTubeCollectionExtractor(CollectionExtractor[Dict]):
info = data["info"]
is_channel = self.__is_channel_id(info["id"])
object.title = f"[channel] [{self.name}] {info['channel']['name']}" if is_channel else f"[playlist] {info['channel']['name']}: {info['title']}"
object.add_uris((info["link"],))
object.add_single_uri(info["link"])
video_list = data["videos"]
if object.watch_in_order_auto:
object.watch_in_order = not is_channel

@ -31,7 +31,7 @@ class MediaExtractor(GeneralExtractor[MediaElement, T]):
f"Add missing URI mapping entry for uri {uri!r}, " +
"this should not happen at this point and is considered a bug"
)
elem.add_uris((uri,))
elem.add_single_uri(uri)
return elem
return None

@ -394,25 +394,27 @@ class MediaElement(db.Entity, Tagable):
self.delete() # will also delete still existing uri mappings and collection links
orm.flush()
def add_uris(self, uri_list: Iterable[str]):
for uri in set(uri_list):
mapping: MediaUriMapping = MediaUriMapping.get(uri=uri)
if not mapping:
logging.debug(f"Add URI mapping {uri!r} to media {self.id!r}")
MediaUriMapping(
uri=uri,
element=self,
)
continue
if mapping.element != self:
raise Exception(f"URI duplicated for two different media's: {uri}") # TODO may replace with merge call
orm.flush()
def add_single_uri(self, uri: str) -> bool:
mapping: MediaUriMapping = MediaUriMapping.get(uri=uri)
if not mapping:
logging.debug(f"Add URI mapping {uri!r} to media {self.id!r}")
MediaUriMapping(
uri=uri,
element=self,
)
return True
if mapping.element != self:
raise Exception(f"URI duplicated for two different media's: {uri}") # TODO may replace with merge call
return False
def add_uris(self, uri_list: Iterable[str]) -> bool:
return all(self.add_single_uri(uri) for uri in set(uri_list))
def before_insert(self):
self.before_update()
def before_update(self):
self.add_uris((self.uri,))
self.add_single_uri(self.uri)
@property
def info_link(self):
@ -486,25 +488,27 @@ class MediaCollection(db.Entity, Tagable):
orm.flush()
return link
def add_uris(self, uri_list: Iterable[str]):
for uri in set(uri_list):
mapping: CollectionUriMapping = CollectionUriMapping.get(uri=uri)
if not mapping:
logging.debug(f"Add URI mapping {uri!r} to collection {self.id!r}")
CollectionUriMapping(
uri=uri,
element=self,
)
continue
if mapping.element != self:
raise Exception(f"URI duplicated for two different collections's: {uri}") # TODO may replace with merge call
orm.flush()
def add_single_uri(self, uri: str) -> bool:
mapping: CollectionUriMapping = CollectionUriMapping.get(uri=uri)
if not mapping:
logging.debug(f"Add URI mapping {uri!r} to collection {self.id!r}")
CollectionUriMapping(
uri=uri,
element=self,
)
return True
if mapping.element != self:
raise Exception(f"URI duplicated for two different collections's: {uri}") # TODO may replace with merge call
return False
def add_uris(self, uri_list: Iterable[str]) -> bool:
return all(self.add_single_uri(uri) for uri in set(uri_list))
def before_insert(self):
self.before_update()
def before_update(self):
self.add_uris((self.uri,))
self.add_single_uri(self.uri)
@property
def info_link(self):

Loading…
Cancel
Save