Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Implemented chapter title;
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddli committed Nov 13, 2015
1 parent 558e08a commit ebfab4c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion version/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def update_gallery(g):
if index:
self.manga_list_view.replace_edit_gallery([g], index.row())
else:
log_e('Could not find gallery to update from Watcher')
log_e('Could not find gallery to update from watcher')

def created(path):
c_popup = io_misc.CreatedPopup(path, self)
Expand Down
2 changes: 2 additions & 0 deletions version/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def chapters_sql(cols=False):
CREATE TABLE IF NOT EXISTS chapters(
chapter_id INTEGER PRIMARY KEY,
series_id INTEGER,
chapter_title TEXT NOT NULL DEFAULT '',
chapter_number INTEGER,
chapter_path BLOB,
pages INTEGER,
Expand All @@ -108,6 +109,7 @@ def chapters_sql(cols=False):
col_list = [
'chapter_id INTEGER PRIMARY KEY',
'series_id INTEGER',
"chapter_title TEXT NOT NULL DEFAULT ''",
'chapter_number INTEGER',
'chapter_path BLOB',
'pages INTEGER',
Expand Down
4 changes: 4 additions & 0 deletions version/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ def create_gallery(path, folder_name, do_chapters=True, archive=None):
log_i('Gallery has {} chapters'.format(numb_of_chapters))
for ch in chapters:
chap = new_gallery.chapters.create_chapter()
chap.title = utils.title_parser(ch)['title']
chap.path = os.path.join(path, ch)
chap.pages = len(list(scandir.scandir(chap.path)))

else: #else assume that all images are in gallery folder
chap = new_gallery.chapters.create_chapter()
chap.title = utils.title_parser(os.path.split(path)[1])['title']
chap.path = path
chap.pages = len(list(scandir.scandir(path)))

Expand Down Expand Up @@ -153,12 +155,14 @@ def create_gallery(path, folder_name, do_chapters=True, archive=None):
raise ValueError
for g in archive_g:
chap = new_gallery.chapters.create_chapter()
chap.title = utils.title_parser(g)['title']
chap.path = g
arch = utils.ArchiveFile(temp_p)
chap.pages = len(arch.dir_contents(g))
arch.close()
else:
chap = new_gallery.chapters.create_chapter()
chap.title = utils.title_parser(os.path.split(path)[1])['title']
chap.path = path
arch = utils.ArchiveFile(path)
chap.pages = len(arch.dir_contents(''))
Expand Down
28 changes: 16 additions & 12 deletions version/gallerydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def gen_thumbnail(gallery, width=app_constants.THUMB_W_SIZE,

def chapter_map(row, chapter):
assert isinstance(chapter, Chapter)
chapter.title = row['chapter_title']
chapter.path = bytes.decode(row['chapter_path'])
chapter.pages = row['pages']
chapter.in_archive = row['in_archive']
Expand Down Expand Up @@ -204,12 +205,13 @@ def default_chap_exec(gallery_or_id, chap, only_values=False):
in_archive = chap.in_archive

if only_values:
execute = (gid, chap.number, str.encode(chap.path), chap.pages, in_archive)
execute = (gid, chap.title, chap.number, str.encode(chap.path), chap.pages, in_archive)
else:
execute = ("""
INSERT INTO chapters(series_id, chapter_number, chapter_path, pages, in_archive)
VALUES(:series_id, :chapter_number, :chapter_path, :pages, :in_archive)""",
INSERT INTO chapters(series_id, chapter_title, chapter_number, chapter_path, pages, in_archive)
VALUES(:series_id, :chapter_title, :chapter_number, :chapter_path, :pages, :in_archive)""",
{'series_id':gid,
'chapter_title':chap.title,
'chapter_number':chap.number,
'chapter_path':str.encode(chap.path),
'pages':chap.pages,
Expand All @@ -224,11 +226,10 @@ def check(obj):
else:
return obj
executing = ["""INSERT INTO series(title, artist, profile, series_path, is_archive,
info, type, fav, status, pub_date, date_added, last_read, link, last_update,
info, type, fav, status, pub_date, date_added, last_read, link,
times_read, exed)
VALUES(:title, :artist, :profile, :series_path, :is_archive, :info, :type, :fav,
:status, :pub_date, :date_added, :last_read, :link, :last_update,
:times_read, :exed)""",
:status, :pub_date, :date_added, :last_read, :link, :times_read, :exed)""",
{
'title':check(object.title),
'artist':check(object.artist),
Expand Down Expand Up @@ -599,9 +600,9 @@ def update_chapter(cls, chapter_container, numbers=[]):
executing = []
for chap in chapters:
new_path = chap.path
executing.append((str.encode(new_path), chap.in_archive, chap.gallery.id, chap.number,))
executing.append((chap.title, str.encode(new_path), chap.in_archive, chap.gallery.id, chap.number,))

cls.executemany(cls, "UPDATE chapters SET chapter_path=?, in_archive=? WHERE series_id=? AND chapter_number=?",
cls.executemany(cls, "UPDATE chapters SET chapter_title=?, chapter_path=?, in_archive=? WHERE series_id=? AND chapter_number=?",
executing)

@classmethod
Expand All @@ -614,7 +615,7 @@ def add_chapters(cls, gallery_object):
executing.append(default_chap_exec(gallery_object, chap, True))
if not executing:
raise Exception
cls.executemany(cls, 'INSERT INTO chapters VALUES(NULL, ?, ?, ?, ?, ?)', executing)
cls.executemany(cls, 'INSERT INTO chapters VALUES(NULL, ?, ?, ?, ?, ?, ?)', executing)

@classmethod
def add_chapters_raw(cls, series_id, chapters_container):
Expand All @@ -628,7 +629,7 @@ def add_chapters_raw(cls, series_id, chapters_container):
else:
cls.update_chapter(cls, chapters_container, [chap.number])

cls.executemany(cls, 'INSERT INTO chapters VALUES(NULL, ?, ?, ?, ?, ?)', executing)
cls.executemany(cls, 'INSERT INTO chapters VALUES(NULL, ?, ?, ?, ?, ?, ?)', executing)


@classmethod
Expand Down Expand Up @@ -1479,14 +1480,16 @@ class Chapter:
Contains following attributes:
parent -> The ChapterContainer it belongs in
gallery -> The Gallery it belongs to
title -> title of chapter
path -> path to chapter
number -> chapter number
pages -> chapter pages
in_archive -> 1 if the chapter path is in an archive else 0
"""
def __init__(self, parent, gallery, number=0, path="", pages=0, in_archive=0):
def __init__(self, parent, gallery, number=0, path='', pages=0, in_archive=0, title=''):
self.parent = parent
self.gallery = gallery
self.title = title
self.path = path
self.number = number
self.pages = pages
Expand All @@ -1498,10 +1501,11 @@ def __lt__(self, other):
def __str__(self):
s = """
Chapter: {}
Title: {}
Path: {}
Pages: {}
in_archive: {}
""".format(self.number, self.path, self.pages, self.in_archive)
""".format(self.number, self.title, self.path, self.pages, self.in_archive)
return s

@property
Expand Down
2 changes: 2 additions & 0 deletions version/gallerydialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,13 @@ def set_chapters(self, gallery_object, add_to_model=True):
log_d('Chapters divided in folders..')
for ch in chapters:
chap = chap_container.create_chapter()
chap.title = utils.title_parser(ch)['title']
chap.path = os.path.join(path, ch)
chap.pages = len(list(scandir.scandir(chap.path)))

else: #else assume that all images are in gallery folder
chap = chap_container.create_chapter()
chap.title = utils.title_parser(os.path.split(path)[1])['title']
chap.path = path
chap.pages = len(list(scandir.scandir(path)))

Expand Down

0 comments on commit ebfab4c

Please sign in to comment.