aboutsummaryrefslogtreecommitdiff
path: root/read_manga.py
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-05-31 07:55:31 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:12:33 +0200
commit1f623da3b6b056a028c83bd1809b3429b94e1857 (patch)
tree645f71a7f5f7abae5b9110bdd89ebbbb76079eb8 /read_manga.py
Initial commit, support for rss torrent, manganelo and readms
Diffstat (limited to 'read_manga.py')
-rwxr-xr-xread_manga.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/read_manga.py b/read_manga.py
new file mode 100755
index 0000000..7d9fd2d
--- /dev/null
+++ b/read_manga.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import re
+import subprocess
+
+def usage():
+ print("read_manga.py manga_directory [start_at_chapter]")
+ print("examples:")
+ print(" read_manga.py /home/adam/Manga/Naruto \"Chapter 10\"")
+ exit(1)
+
+if len(sys.argv) < 2:
+ usage()
+
+def chapter_sort_func(ch):
+ match1 = re.search(r"Chapter ([0-9.]+)", ch)
+ if match1 and len(match1.groups()) >= 1:
+ return float(match1.groups()[0])
+ match2 = re.search(r"^([0-9.]+)", ch)
+ if match2 and len(match2.groups()) >= 1:
+ return float(match2.groups()[0])
+ raise Exception("Failed to sort. Unexpected chapter name format: {}".format(ch))
+
+def image_sort_func(ch):
+ return int(ch[0:ch.rfind(".")])
+
+start_at_chapter = None
+if len(sys.argv) >= 3:
+ start_at_chapter = sys.argv[2]
+
+manga_directory = sys.argv[1]
+chapters = []
+for chapter in os.listdir(manga_directory):
+ chapters.append(chapter)
+
+chapters_by_oldest = sorted(chapters, key=chapter_sort_func)
+start_index = 0
+if start_at_chapter:
+ found_chapter = False
+ index = 0
+ for chapter in chapters_by_oldest:
+ if chapter == start_at_chapter:
+ start_index = index
+ found_chapter = True
+ break
+ index += 1
+
+ if not found_chapter:
+ print("Failed to find chapter %s in list of chapters: %s" % (start_at_chapter, str(chapters_by_oldest)))
+
+index = 0
+images_str = []
+for chapter in chapters_by_oldest:
+ if index < start_index:
+ index += 1
+ continue
+
+ images = []
+ image_dir = os.path.join(manga_directory, chapter)
+ for image in os.listdir(image_dir):
+ # Ignore "in_progress", "finished" and "session_id". We only want image files.
+ if image.find(".") != -1:
+ images.append(image)
+
+ images = sorted(images, key=image_sort_func)
+ for image in images:
+ images_str.append(os.path.join(image_dir, image))
+ index += 1
+
+process = subprocess.Popen(["sxiv", "-i", "-s", "f", "-f"], stdin=subprocess.PIPE)
+process.communicate("\n".join(images_str).encode())