diff --git a/modules/videos/lib.py b/modules/videos/lib.py index 5bff6306..6443ab17 100644 --- a/modules/videos/lib.py +++ b/modules/videos/lib.py @@ -467,7 +467,7 @@ def import_channels_config(): # video_path, so we can match the complete path for the Video. video_path = channel_dir / video_path file_group: FileGroup = FileGroup.find_by_path(video_path, session) - if file_group.tag_files: + if file_group and file_group.tag_files: # Video is already tagged or favorited. pass elif file_group: diff --git a/wrolpi/tags.py b/wrolpi/tags.py index ad3b11b5..ee24c2d2 100644 --- a/wrolpi/tags.py +++ b/wrolpi/tags.py @@ -1,6 +1,7 @@ import contextlib from typing import List +from cryptography.exceptions import InvalidTag from sqlalchemy import Column, Integer, String, ForeignKey, BigInteger from sqlalchemy.orm import relationship, Session @@ -96,6 +97,7 @@ class TagsConfig(ConfigFile): @tags.setter def tags(self, value): + value = sorted(value, key=lambda i: (i[0].lower(), i[1])) self.update({'tags': value}) def add_tag(self, tag_file: TagFile): @@ -105,7 +107,7 @@ class TagsConfig(ConfigFile): tag_name = tag_file.tag.name tags = self.tags.copy() - value = [primary_path, tag_name] + value = [tag_name, primary_path] if value not in tags: tags.append(value) self.tags = tags @@ -118,7 +120,7 @@ class TagsConfig(ConfigFile): tags = self.tags.copy() for idx, value in enumerate(self.tags): - if value == [primary_path, tag_name]: + if value == [tag_name, primary_path]: tags = tags.copy() tags.pop(idx) self.tags = tags @@ -154,6 +156,9 @@ def get_tags(session: Session) -> List[Tag]: @optional_session def new_tag(name: str, color: str, session: Session) -> Tag: + if ',' in name: + raise InvalidTag('Tag name cannot have comma') + tag = Tag(name=name, color=color) session.add(tag) session.flush([tag])