Skip to content

Commit c2a3e60

Browse files
authored
Merge pull request #10 from schemen/devel
Sync to Master
2 parents 9680a93 + e62f667 commit c2a3e60

20 files changed

+1146
-1428
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.vscode
33
test\ Kopie.db
44
_test.db
5+
test.db
56
__pycache__
67
comic/*
78
kindlegen.exe

bin/Converter.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# -*- coding: utf-8 -*-
2+
import logging
3+
import os
4+
import zipfile
5+
import subprocess
6+
import bin.Helper as helper
7+
8+
9+
class Converter:
10+
""" This Class Converts the result of the Downloader class into Ebooks"""
11+
12+
def __init__(self):
13+
self.saveloc = None
14+
self.ebformat = None
15+
self.ebprofile = None
16+
self.mangatitle = None
17+
self.manganame = None
18+
self.imagefolder = None
19+
self.eblocation = None
20+
self.cbzlocation = None
21+
self.chapterdate = None
22+
23+
24+
25+
def data_collector(self, config, chapter):
26+
""" Method that collects data"""
27+
28+
# Load configs required here
29+
self.saveloc = config["SaveLocation"]
30+
self.ebformat = config["EbookFormat"]
31+
self.ebprofile = config["EbookProfile"]
32+
33+
34+
# get relevant data of this Manga
35+
self.mangatitle = chapter.title
36+
self.manganame = chapter.manganame
37+
self.chapterdate = chapter.date
38+
39+
# check if mangatitle or manganame contains ":" characters that OS can't handle as folders
40+
self.mangatitle = helper.sanetizeName(self.mangatitle)
41+
self.manganame = helper.sanetizeName(self.manganame)
42+
43+
44+
# create folder variables
45+
self.imagefolder = str(self.saveloc + self.manganame + "/" +
46+
self.mangatitle + "/images/")
47+
self.eblocation = str(self.saveloc + self.manganame + "/"+
48+
self.mangatitle + "/" + self.mangatitle + "." + self.ebformat.lower())
49+
self.cbzlocation = str(self.saveloc + self.manganame + "/"+
50+
self.mangatitle + "/" + self.mangatitle + ".cbz")
51+
52+
53+
54+
55+
def cbz_creator(self):
56+
""" Method that converts images into CBZ"""
57+
58+
# Create CBZ to make creation easier
59+
if os.path.exists(self.cbzlocation):
60+
logging.debug("Manga %s converted to CBZ already!", self.mangatitle)
61+
else:
62+
logging.info("Starting conversion to CBZ of %s...", self.mangatitle)
63+
64+
65+
logging.debug("Opening CBZ archive...")
66+
try:
67+
zfile = zipfile.ZipFile(self.cbzlocation, "w")
68+
except Exception as fail:
69+
logging.warning("Failed opening archive! %s", fail)
70+
71+
72+
73+
logging.debug("Writing Images into CBZ")
74+
for img in sorted(os.listdir(self.imagefolder)):
75+
image = self.imagefolder + img
76+
logging.debug("Writing %s", image)
77+
zfile.write(image, img)
78+
79+
zfile.close()
80+
81+
82+
83+
def eb_creator(self):
84+
""" Method that creates the Ebook out of the CBZ """
85+
86+
# Start conversion to Ebook format!
87+
if os.path.exists(self.eblocation):
88+
logging.debug("Manga %s converted to Ebook already!", self.mangatitle)
89+
else:
90+
logging.info("Starting conversion to Ebook of %s...", self.mangatitle)
91+
92+
try:
93+
subprocess.call(["kcc-c2e", "-p", self.ebprofile, "-f", self.ebformat,
94+
"-m", "-r", "2", "-u", "-s", self.cbzlocation])
95+
except Exception as fail:
96+
logging.debug("Failed to convert epub %s", fail)
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
import logging
22
import os
3-
import bin.m2emHelper as helper
4-
from bin.m2emConverter import Converter
5-
3+
import bin.Helper as helper
4+
from bin.Converter import Converter
65

76
def ConverterHandler(config, args):
8-
9-
# Load configs required here
10-
database = config["Database"]
7+
""" Function that handles the Converter in a loop """
118

129
# Load Chapters!
13-
chapters = helper.getChapters(database)
10+
chapters = helper.getChapters()
1411

1512

1613
# Start conversion loop!
17-
for chapter in chapters:
18-
14+
for chapter in chapters.iterator():
1915

2016

2117
# Verify if chapter has been downloaded already
2218
if not helper.verifyDownload(config, chapter):
23-
logging.debug("Manga %s has not been downloaded!" % chapter[2])
19+
logging.debug("Manga %s has not been downloaded!", chapter.title)
2420
else:
2521

2622

2723
# Spawn an Converter Object & get basic data from database & config
2824
current_conversation = Converter()
29-
current_conversation.data_collector(config,chapter)
25+
current_conversation.data_collector(config, chapter)
3026

3127
# Check if Download loop & Download task is selected
3228
if not args.start:
@@ -39,21 +35,19 @@ def ConverterHandler(config, args):
3935
current_conversation.cbz_creator()
4036
current_conversation.eb_creator()
4137
else:
42-
logging.debug("%s is older than 24h, will not be processed by daemon." % current_conversation.mangatitle)
38+
logging.debug("%s is older than 24h, will not be processed by daemon.",
39+
current_conversation.mangatitle)
4340

4441

4542

4643

4744
def directConverter(config, chapterids=[]):
45+
""" Function that handles direct calls of the Converter """
4846

4947
logging.debug("Following Chapters are directly converted:")
5048
logging.debug(chapterids)
5149

52-
# Load configs required here
53-
database = config["Database"]
54-
55-
56-
chapters = helper.getChaptersFromID(database, chapterids)
50+
chapters = helper.getChaptersFromID(chapterids)
5751

5852

5953
if not chapters:
@@ -64,23 +58,23 @@ def directConverter(config, chapterids=[]):
6458

6559
# Verify if chapter has been downloaded already
6660
if not helper.verifyDownload(config, chapter):
67-
logging.info("Manga %s has not been downloaded!" % chapter[2])
61+
logging.info("Manga %s has not been downloaded!", chapter[2])
6862
else:
6963

7064

7165
# Spawn an Converter Object & get basic data from database & config
7266
current_conversation = Converter()
73-
current_conversation.data_collector(config,chapter)
67+
current_conversation.data_collector(config, chapter)
7468

7569
if os.path.exists(current_conversation.cbzlocation):
76-
logging.info("Manga %s converted to CBZ already!" % current_conversation.mangatitle)
70+
logging.info("Manga %s converted to CBZ already!",
71+
current_conversation.mangatitle)
7772
else:
78-
logging.info("Starting conversion to CBZ of %s..." % current_conversation.mangatitle)
7973
current_conversation.cbz_creator()
8074

8175
# Start conversion to Ebook format!
8276
if os.path.exists(current_conversation.eblocation):
83-
logging.info("Manga %s converted to Ebook already!" % current_conversation.mangatitle)
77+
logging.info("Manga %s converted to Ebook already!",
78+
current_conversation.mangatitle)
8479
else:
85-
logging.info("Starting conversion to Ebook of %s..." % current_conversation.mangatitle)
8680
current_conversation.eb_creator()

bin/m2emDownloader.py bin/Downloader.py

+27-27
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import os
33
import requests
44
from shutil import move
5-
import bin.m2emHelper as helper
6-
import bin.sourceparser.m2emMangastream as msparser
7-
import bin.sourceparser.m2emMangafox as mxparser
5+
import bin.Helper as helper
6+
import bin.sourceparser.Mangastream as msparser
7+
import bin.sourceparser.Mangafox as mxparser
88
from PIL import Image
99
from PIL import ImageOps
1010
from PIL import ImageFilter
@@ -13,16 +13,16 @@
1313
class Downloader:
1414

1515
def __init__(self):
16-
self.database = None
17-
self.saveloc = None
18-
self.mangastarturl = None
19-
self.mangapages = None
20-
self.mangatitle = None
21-
self.manganame = None
22-
self.chapterdate = None
23-
self.downloadfolder = None
24-
self.origin = None
25-
self.imageurls = None
16+
self.database = None
17+
self.saveloc = None
18+
self.mangastarturl = None
19+
self.mangapages = None
20+
self.mangatitle = None
21+
self.manganame = None
22+
self.chapterdate = None
23+
self.downloadfolder = None
24+
self.origin = None
25+
self.imageurls = None
2626

2727

2828

@@ -31,27 +31,27 @@ def data_collector(self, config, chapter):
3131

3232
# Load configs required here
3333
self.database = config["Database"]
34-
self.saveloc = config["SaveLocation"]
34+
self.saveloc = config["SaveLocation"]
3535

3636
# get relevant data of this Chapter
37-
self.mangastarturl = chapter[4]
38-
self.mangapages = chapter[9]
39-
self.mangatitle = chapter[2]
40-
self.manganame = chapter[11]
41-
self.chapterdate = chapter[3]
37+
self.mangastarturl = chapter.url
38+
self.mangapages = chapter.pages
39+
self.mangatitle = chapter.title
40+
self.manganame = chapter.manganame
41+
self.chapterdate = chapter.date
4242

4343
# check if mangatitle or manganame contains ":" characters that OS can't handle as folders
4444
self.mangatitle = helper.sanetizeName(self.mangatitle)
4545
self.manganame = helper.sanetizeName(self.manganame)
4646

4747
# Define Download location
48-
self.downloadfolder = str(self.saveloc + self.manganame + "/" + self.mangatitle + "/images")
48+
self.downloadfolder = str(self.saveloc + self.manganame + "/" + self.mangatitle + "/images")
4949

5050
# get Origin of manga (Which mangawebsite)
5151
self.origin = helper.getSourceURL(self.mangastarturl)
52-
52+
5353
# Initiate URL list
54-
self.imageurls=[]
54+
self.imageurls = []
5555

5656

5757

@@ -70,27 +70,27 @@ def data_processor(self):
7070
# Turn Manga pages into Image links!
7171
for i in urllist:
7272
self.imageurls.append(msparser.getImageUrl(i))
73-
logging.debug("List of all Images for %s" % self.mangatitle)
73+
logging.debug("List of all Images for %s", self.mangatitle)
7474
logging.debug(self.imageurls)
7575

7676

7777
# Mangafox Parser
7878
elif self.origin == "mangafox.me" or self.origin == "mangafox.la":
79-
urllist = mxparser.getPagesUrl(self.mangastarturl,self.mangapages)
79+
urllist = mxparser.getPagesUrl(self.mangastarturl, self.mangapages)
8080

8181

8282
# Turn Manga pages into Image links!
8383
for i in urllist:
8484
self.imageurls.append(mxparser.getImageUrl(i))
85-
logging.debug("List of all Images for %s" % self.mangatitle)
85+
logging.debug("List of all Images for %s", self.mangatitle)
8686
logging.debug(self.imageurls)
8787

8888

8989

9090

9191

9292
def downloader(self):
93-
logging.info("Starting download of %s..." % self.mangatitle)
93+
logging.info("Starting download of %s...", self.mangatitle)
9494
# Download & save images!
9595
# check if we have images to download
9696
if not len(self.imageurls) == 0:
@@ -134,4 +134,4 @@ def downloader(self):
134134
cleaned.save(imagepath)
135135

136136
# Finish :)
137-
logging.info("Finished download of %s!"% self.mangatitle)
137+
logging.info("Finished download of %s!", self.mangatitle)

bin/m2emDownloaderHandler.py bin/DownloaderHandler.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import logging
22
import os
33
from shutil import move
4-
import bin.m2emHelper as helper
5-
from bin.m2emDownloader import Downloader
6-
4+
import bin.Helper as helper
5+
from bin.Downloader import Downloader
76

87
'''
98
downloadHandler
109
'''
1110
def downloader(config, args):
1211

13-
# Load configs required here
14-
database = config["Database"]
15-
16-
17-
chapters = helper.getChapters(database)
12+
# Make the query
13+
chapters = helper.getChapters()
1814

1915
if args.start:
2016
logging.debug("The loop will only consider Chapters younger than 24h!")
2117

2218

2319

2420
# Start Download loop!
25-
for chapter in chapters:
21+
for chapter in chapters.iterator():
2622

2723
# Initialize Downloader class & load basic params
2824
current_chapter = Downloader()
@@ -63,14 +59,11 @@ def directDownloader(config, chapterids=[]):
6359
logging.debug("Following Chapters are directly converted:")
6460
logging.debug(chapterids)
6561

66-
# Load configs required here
67-
database = config["Database"]
68-
6962

70-
chapters = helper.getChaptersFromID(database, chapterids)
63+
chapters = helper.getChaptersFromID(chapterids)
7164

7265
# Load Users
73-
users = helper.getUsers(database)
66+
users = helper.getUsers()
7467

7568
# Debug Users:
7669
logging.debug("Userlist:")

0 commit comments

Comments
 (0)