def chapters(comic_id): comic = data.get_comic(comic_id) #chapters = data.get_chapters(comic_id) chapters = data_get_chapters(comic) return render_template('chapters.html', comic=comic, chapters=chapters)
def chapter(comic_id, chapter_id): """ @chapter_id 第几章 """ comic = data.get_comic(comic_id) comic_path = os.path.join(ASSETS, comic.title) state = 1 next_chapter = None prev_chapter = None chapter = None for c in data_get_chapters(comic): print(c.id, chapter_id) if int(c.id) == chapter_id: state = 2 chapter = c continue if state == 2: next_chapter = c break else: prev_chapter = c # 文件目录 #comic_name = os.path.basename(comic_path) comic_name = os.path.basename(comic_path) #找出当前章节,所有的image chapter_path = os.path.join(comic_path, str(chapter.title)) images = os.listdir(chapter_path) images = [x for x in images if 'jpg' in x] images.sort(key=lambda x: int(re.findall(r'\d+', x)[0])) images = [ "/assets/{}/{}/{}".format(comic_name, chapter.title, x) for x in images ] #前后章节 return render_template('images.html', comic=comic, chapter=chapter, next_chapter=next_chapter, prev_chapter=prev_chapter, images=images, url='')
def chapter(comic_id, chapter_id): comic = data.get_comic(comic_id) chapter = data.get_chapter(chapter_id) next_chapter = data.get_next_chapter(comic_id, chapter.chapter_number) prev_chapter = data.get_prev_chapter(comic_id, chapter.chapter_number) url = 'http://www.ishuhui.net/ComicBooks/ReadComicBooksToIsoV1/' + str( chapter_id) + '.html' if chapter.comic_id != comic_id: abort(404) if chapter.images: images = json.loads(chapter.images) else: images = get_images_from_url(url) chapter.images = json.dumps(images) db.session.commit() return render_template('images.html', comic=comic, chapter=chapter, next_chapter=next_chapter, prev_chapter=prev_chapter, images=images, url=url)