Merge pull request #221 from SomeRandomDude870/master

HDoujin-format Metadata file
This commit is contained in:
Ricter Zheng 2021-06-07 16:02:43 +08:00 committed by GitHub
commit ad1e876611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 8 deletions

View File

@ -119,6 +119,9 @@ def cmd_parser():
parser.add_option('--template', dest='viewer_template', action='store', parser.add_option('--template', dest='viewer_template', action='store',
help='set viewer template', default='') help='set viewer template', default='')
parser.add_option('--meta', dest='generate_metadata', action='store_true', help='generate a Metadata File in HDoujin Format')
try: try:
sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv] sys.argv = [unicode(i.decode(sys.stdin.encoding)) for i in sys.argv]
except (NameError, TypeError): except (NameError, TypeError):

View File

@ -13,7 +13,7 @@ from nhentai.doujinshi import Doujinshi
from nhentai.downloader import Downloader from nhentai.downloader import Downloader
from nhentai.logger import logger from nhentai.logger import logger
from nhentai.constant import BASE_URL from nhentai.constant import BASE_URL
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, \ from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, generate_metadatafile, \
paging, check_cookie, signal_handler, DB paging, check_cookie, signal_handler, DB
@ -84,6 +84,8 @@ def main():
if (i + 1) % 10 == 0: if (i + 1) % 10 == 0:
logger.info('Progress: %d / %d' % (i + 1, len(doujinshi_ids))) logger.info('Progress: %d / %d' % (i + 1, len(doujinshi_ids)))
if not options.is_show: if not options.is_show:
downloader = Downloader(path=options.output_dir, size=options.threads, downloader = Downloader(path=options.output_dir, size=options.threads,
timeout=options.timeout, delay=options.delay) timeout=options.timeout, delay=options.delay)
@ -93,6 +95,14 @@ def main():
doujinshi.downloader = downloader doujinshi.downloader = downloader
doujinshi.download() doujinshi.download()
doujinshi.downloader = downloader
doujinshi.download()
if options.generate_metadata:
table=doujinshi.table
generate_metadatafile(options.output_dir,table,doujinshi)
if options.is_save_download_history: if options.is_save_download_history:
with DB() as db: with DB() as db:
db.add_one(doujinshi.id) db.add_one(doujinshi.id)
@ -116,6 +126,7 @@ def main():
[doujinshi.show() for doujinshi in doujinshi_list] [doujinshi.show() for doujinshi in doujinshi_list]
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)

View File

@ -42,11 +42,8 @@ class Doujinshi(object):
name_format = name_format.replace('%s', self.info.subtitle) name_format = name_format.replace('%s', self.info.subtitle)
self.filename = format_filename(name_format) self.filename = format_filename(name_format)
def __repr__(self):
return '<Doujinshi: {0}>'.format(self.name)
def show(self): self.table =[
table = [
["Parodies", self.info.parodies], ["Parodies", self.info.parodies],
["Doujinshi", self.name], ["Doujinshi", self.name],
["Subtitle", self.info.subtitle], ["Subtitle", self.info.subtitle],
@ -57,7 +54,15 @@ class Doujinshi(object):
["URL", self.url], ["URL", self.url],
["Pages", self.pages], ["Pages", self.pages],
] ]
logger.info(u'Print doujinshi information of {0}\n{1}'.format(self.id, tabulate(table)))
def __repr__(self):
return '<Doujinshi: {0}>'.format(self.name)
def show(self):
logger.info(u'Print doujinshi information of {0}\n{1}'.format(self.id, tabulate(self.table)))
def download(self): def download(self):
logger.info('Starting to download doujinshi: %s' % self.name) logger.info('Starting to download doujinshi: %s' % self.name)

View File

@ -290,6 +290,58 @@ def paging(page_string):
return page_list return page_list
def generate_metadatafile(output_dir, table, doujinshi_obj=None):
logger.info("Writing Metadata Info")
if doujinshi_obj is not None:
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
else:
doujinshi_dir = '.'
logger.info(doujinshi_dir)
f = open(os.path.join(doujinshi_dir, 'info.txt'), "w", encoding="utf-8")
fields = ["TITLE", "ORIGINAL TITLE", "AUTHOR", "ARTIST", "CIRCLE", "SCANLATOR", "TRANSLATOR", "PUBLISHER", "DESCRIPTION", "STATUS", "CHAPTERS", "PAGES", "TAGS", "TYPE", "LANGUAGE", "RELEASED", "READING DIRECTION", "CHARACTERS", "SERIES", "PARODY", "URL"]
for i in range(21):
f.write("%s: " % fields[i])
if(i==19):
f.write("%s" % table[0][1])
if(i==0):
f.write("%s" % table[1][1])
if(i==1):
f.write("%s" % table[2][1])
if(i==17):
f.write("%s" % table[3][1])
if(i==2):
f.write("%s" % table[4][1])
if(i==14):
f.write("%s" % table[5][1])
if(i==12):
f.write("%s" % table[6][1])
if(i==20):
f.write("%s" % table[7][1])
if(i==11):
f.write("%s" % table[8][1])
f.write("\n")
f.close()
class DB(object): class DB(object):
conn = None conn = None
@ -316,3 +368,6 @@ class DB(object):
def get_all(self): def get_all(self):
data = self.cur.execute('SELECT id FROM download_history') data = self.cur.execute('SELECT id FROM download_history')
return [i[0] for i in data] return [i[0] for i in data]