From dbadbff646f25b937e7aa76ec4594f8908484333 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 30 Jun 2019 08:36:07 +0200 Subject: read_manga_rofi: sort list by chapter number instead of timestamp --- read_manga.py | 26 +++++++++++++++++--------- read_manga_rofi.sh | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/read_manga.py b/read_manga.py index 7d9fd2d..d08127a 100755 --- a/read_manga.py +++ b/read_manga.py @@ -6,9 +6,10 @@ import re import subprocess def usage(): - print("read_manga.py manga_directory [start_at_chapter]") + print("read_manga.py manga_directory [start_at_chapter] [--list-reverse]") print("examples:") print(" read_manga.py /home/adam/Manga/Naruto \"Chapter 10\"") + print(" read_manga.py /home/adam/Manga/Naruto --list-reverse") exit(1) if len(sys.argv) < 2: @@ -35,7 +36,19 @@ chapters = [] for chapter in os.listdir(manga_directory): chapters.append(chapter) -chapters_by_oldest = sorted(chapters, key=chapter_sort_func) +chapters_by_oldest = [] +try: + chapters_by_oldest = sorted(chapters, key=chapter_sort_func) +except Exception as e: + print("Failed to sord chapters using custom sorting method, using default sorting method. Reason for failure: %s" % str(e), file=sys.stderr) + chapters_by_oldest = sorted(chapters) + +for argv in sys.argv: + if argv == "--list-reverse": + chapters_by_oldest.reverse() + print("\n".join(chapters_by_oldest)) + exit(0) + start_index = 0 if start_at_chapter: found_chapter = False @@ -48,15 +61,10 @@ if start_at_chapter: index += 1 if not found_chapter: - print("Failed to find chapter %s in list of chapters: %s" % (start_at_chapter, str(chapters_by_oldest))) + print("Failed to find chapter %s in list of chapters: %s" % (start_at_chapter, str(chapters_by_oldest)), file=sys.stderr) -index = 0 images_str = [] -for chapter in chapters_by_oldest: - if index < start_index: - index += 1 - continue - +for chapter in chapters_by_oldest[start_index:]: images = [] image_dir = os.path.join(manga_directory, chapter) for image in os.listdir(image_dir): diff --git a/read_manga_rofi.sh b/read_manga_rofi.sh index cbdc19b..4eed923 100755 --- a/read_manga_rofi.sh +++ b/read_manga_rofi.sh @@ -9,6 +9,6 @@ cd "$script_dir" download_dir="$1" manga_list=$(ls -t "$download_dir") selected_manga=$(echo "$manga_list" | rofi -dmenu -i -p "Select manga") -chapters=$(ls -t "$download_dir/$selected_manga") +chapters=$(./read_manga.py "$download_dir/$selected_manga" --list-reverse) selected_starting_chapter=$(echo "$chapters" | rofi -dmenu -i -p "Select starting chapter") ./read_manga.py "$download_dir/$selected_manga" "$selected_starting_chapter" -- cgit v1.2.3