From 8607bf15a90f5ba0814c97b7e35ef32e4a4632c4 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 8 Jan 2023 19:09:19 +0100 Subject: [PATCH] Add option to sort by last modification date (close #88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store the metadate “last-modified” for a track and an album and add an option sort by it. --- data/ui/library-toolbar.ui | 18 +++++++++++++++++- data/xyz.suruatoel.mcg.gschema.xml | 1 + po/de.mo | Bin 4190 -> 4246 bytes po/de.po | 22 +++++++++++++--------- po/en.mo | Bin 3931 -> 4042 bytes po/en.po | 22 +++++++++++++--------- po/mcg.pot | 16 ++++++++++------ src/client.py | 26 ++++++++++++++++++++++++++ src/librarypanel.py | 4 +++- src/utils.py | 1 + 10 files changed, 84 insertions(+), 26 deletions(-) diff --git a/data/ui/library-toolbar.ui b/data/ui/library-toolbar.ui index 97cad01..aabcc8f 100644 --- a/data/ui/library-toolbar.ui +++ b/data/ui/library-toolbar.ui @@ -129,6 +129,22 @@ 4 + + + sort by modification + True + True + False + True + sort_year + + + + False + True + 5 + + gtk-sort-descending @@ -143,7 +159,7 @@ False True - 5 + 6 diff --git a/data/xyz.suruatoel.mcg.gschema.xml b/data/xyz.suruatoel.mcg.gschema.xml index 934564c..9f50878 100644 --- a/data/xyz.suruatoel.mcg.gschema.xml +++ b/data/xyz.suruatoel.mcg.gschema.xml @@ -4,6 +4,7 @@ + diff --git a/po/de.mo b/po/de.mo index da025a58e832a15d8da250d349124781c1c8f3c1..abfee53fda80f21b12bf31bcc5049bc16bef6d96 100644 GIT binary patch delta 1618 zcmcboFio-ko)F7a1_lNOHwFd<83qOhA0`HdLyVXJ7#Np_CnBaTQd)mmT8Jsq7$!)iW?G1~V8KHnB4> zh%hiP9Asx;;ACK6xCS-g0o0<}Nlfm-ktD*qd*59D2tPenN(7OHSS9AwS`vWS7f zo`ZpbpMinFkAs0hjDdk6j)Q@Lt)78_p_Bt+aSaCpgCYY1!$b}S25ANchR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?*KbB=LC9CDePp&pz_ZgE3`<}o(|gA@Y;!)K@lJ{|@J zH3kL-2_6Op0R{#Jdmczg1n@vCh~|M9n8?GxP|m=>kjKNopv1ty@C-_G@%D}*&$qz{*{``F#-n9pnRG@fZfVdi@ z%#HyPRNA0~#sEoB#taM$Rv<|Rh_AFj*^7aJ!4MR>pyJGY@\n" "Language-Team: \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.4.1\n" -"X-Poedit-Basepath: ../../..\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.2.2\n" +"X-Poedit-Basepath: ../../..\n" "X-Poedit-SourceCharset: UTF-8\n" #: data/xyz.suruatoel.mcg.gschema.xml:11 @@ -216,15 +216,19 @@ msgstr "nach Titel" msgid "sort by year" msgstr "nach Jahr" -#: data/ui/library-toolbar.ui:169 data/ui/shortcuts-dialog.ui:115 +#: data/ui/library-toolbar.ui:134 +msgid "sort by modification" +msgstr "nach Änderungsdatum" + +#: data/ui/library-toolbar.ui:185 data/ui/shortcuts-dialog.ui:115 msgid "Search the library" msgstr "Die Bibliothek durchsuchen" -#: data/ui/library-toolbar.ui:192 data/ui/playlist-toolbar.ui:15 +#: data/ui/library-toolbar.ui:208 data/ui/playlist-toolbar.ui:15 msgid "Select multiple albums" msgstr "Mehrere Alben auswählen" -#: data/ui/library-toolbar.ui:214 +#: data/ui/library-toolbar.ui:230 msgid "Settings and actions" msgstr "Einstellungen und Aktionen" @@ -353,11 +357,11 @@ msgstr "Zu MPD verbinden" msgid "Adjust the volume" msgstr "Die Lautstärke anpassen" -#: src/librarypanel.py:419 +#: src/librarypanel.py:421 msgid "Loading albums" msgstr "Alben werden geladen" -#: src/librarypanel.py:519 +#: src/librarypanel.py:521 msgid "Loading images" msgstr "Bilder werden geladen" diff --git a/po/en.mo b/po/en.mo index 39a611bfc9450b522475a80bd696a35fed4a99b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644 --- a/po/en.po +++ b/po/en.po @@ -2,17 +2,17 @@ msgid "" msgstr "" "Project-Id-Version: CoverGrid (mcg)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-05 15:08+0200\n" -"PO-Revision-Date: 2020-10-24 14:40+0200\n" +"POT-Creation-Date: 2023-01-08 19:06+0100\n" +"PO-Revision-Date: 2023-01-08 19:07+0100\n" "Last-Translator: coderkun \n" "Language-Team: \n" "Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 2.4.1\n" -"X-Poedit-Basepath: ../../..\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.2.2\n" +"X-Poedit-Basepath: ../../..\n" "X-Poedit-SearchPath-0: mcg\n" "X-Poedit-SearchPath-1: data/ui\n" @@ -217,15 +217,19 @@ msgstr "by Title" msgid "sort by year" msgstr "by Year" -#: data/ui/library-toolbar.ui:169 data/ui/shortcuts-dialog.ui:115 +#: data/ui/library-toolbar.ui:134 +msgid "sort by modification" +msgstr "by Modification Date" + +#: data/ui/library-toolbar.ui:185 data/ui/shortcuts-dialog.ui:115 msgid "Search the library" msgstr "Search the library" -#: data/ui/library-toolbar.ui:192 data/ui/playlist-toolbar.ui:15 +#: data/ui/library-toolbar.ui:208 data/ui/playlist-toolbar.ui:15 msgid "Select multiple albums" msgstr "Select multiple albums" -#: data/ui/library-toolbar.ui:214 +#: data/ui/library-toolbar.ui:230 msgid "Settings and actions" msgstr "Settings and actions" @@ -354,11 +358,11 @@ msgstr "Connect to MPD" msgid "Adjust the volume" msgstr "Adjust the volume" -#: src/librarypanel.py:419 +#: src/librarypanel.py:421 msgid "Loading albums" msgstr "Loading albums" -#: src/librarypanel.py:519 +#: src/librarypanel.py:521 msgid "Loading images" msgstr "Loading images" diff --git a/po/mcg.pot b/po/mcg.pot index 19fd383..c409fd6 100644 --- a/po/mcg.pot +++ b/po/mcg.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: mcg\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-09-05 15:08+0200\n" +"POT-Creation-Date: 2023-01-08 19:06+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -215,15 +215,19 @@ msgstr "" msgid "sort by year" msgstr "" -#: data/ui/library-toolbar.ui:169 data/ui/shortcuts-dialog.ui:115 +#: data/ui/library-toolbar.ui:134 +msgid "sort by modification" +msgstr "" + +#: data/ui/library-toolbar.ui:185 data/ui/shortcuts-dialog.ui:115 msgid "Search the library" msgstr "" -#: data/ui/library-toolbar.ui:192 data/ui/playlist-toolbar.ui:15 +#: data/ui/library-toolbar.ui:208 data/ui/playlist-toolbar.ui:15 msgid "Select multiple albums" msgstr "" -#: data/ui/library-toolbar.ui:214 +#: data/ui/library-toolbar.ui:230 msgid "Settings and actions" msgstr "" @@ -352,11 +356,11 @@ msgstr "" msgid "Adjust the volume" msgstr "" -#: src/librarypanel.py:419 +#: src/librarypanel.py:421 msgid "Loading albums" msgstr "" -#: src/librarypanel.py:519 +#: src/librarypanel.py:521 msgid "Loading images" msgstr "" diff --git a/src/client.py b/src/client.py index 3929d26..cc043d8 100644 --- a/src/client.py +++ b/src/client.py @@ -3,6 +3,7 @@ import concurrent.futures import configparser +import dateutil.parser import logging import os import queue @@ -937,6 +938,8 @@ class Client(Base): track.set_date(song['date']) if 'albumartist' in song: track.set_albumartists(song['albumartist']) + if 'last-modified' in song: + track.set_last_modified(song['last-modified']) return track @@ -998,6 +1001,7 @@ class MCGAlbum: self._host = host self._tracks = [] self._length = 0 + self._last_modified = None self._id = Utils.generate_id(title) @@ -1057,6 +1061,9 @@ class MCGAlbum: path = os.path.dirname(track.get_file()) if path not in self._pathes: self._pathes.append(path) + if track.get_last_modified(): + if not self._last_modified or track.get_last_modified() > self._last_modified: + self._last_modified = track.get_last_modified() def get_tracks(self): @@ -1067,6 +1074,10 @@ class MCGAlbum: return self._length + def get_last_modified(self): + return self._last_modified + + def filter(self, filter_string): if len(filter_string) == 0: return True @@ -1102,6 +1113,8 @@ class MCGAlbum: value_function = "get_title" elif criterion == SortOrder.YEAR: value_function = "get_date" + elif criterion == SortOrder.MODIFIED: + value_function = "get_last_modified" value1 = getattr(album1, value_function)() value2 = getattr(album2, value_function)() @@ -1137,6 +1150,7 @@ class MCGTrack: self._track = None self._length = 0 self._date = None + self._last_modified = None def __eq__(self, other): @@ -1208,6 +1222,18 @@ class MCGTrack: return self._file + def set_last_modified(self, date_string): + if date_string: + try: + self._last_modified = dateutil.parser.isoparse(date_string) + except ValueError as e: + self._logger.debug("Invalid date format: %s", date_string) + + + def get_last_modified(self): + return self._last_modified + + class MCGPlaylistTrack(MCGTrack): diff --git a/src/librarypanel.py b/src/librarypanel.py index 48b5342..2626c7b 100644 --- a/src/librarypanel.py +++ b/src/librarypanel.py @@ -39,6 +39,7 @@ class LibraryToolbar(Gtk.ButtonBox): sort_artist = Gtk.Template.Child() sort_title = Gtk.Template.Child() sort_year = Gtk.Template.Child() + sort_modified = Gtk.Template.Child() grid_scale = Gtk.Template.Child() @@ -50,7 +51,8 @@ class LibraryToolbar(Gtk.ButtonBox): self._toolbar_sort_buttons = { SortOrder.ARTIST: self.sort_artist, SortOrder.TITLE: self.sort_title, - SortOrder.YEAR: self.sort_year + SortOrder.YEAR: self.sort_year, + SortOrder.MODIFIED: self.sort_modified } diff --git a/src/utils.py b/src/utils.py index 713c85c..e5a08bd 100644 --- a/src/utils.py +++ b/src/utils.py @@ -86,3 +86,4 @@ class SortOrder: ARTIST = 0 TITLE = 1 YEAR = 2 + MODIFIED = 3