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

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

View File

@ -13,7 +13,7 @@ from nhentai.doujinshi import Doujinshi
from nhentai.downloader import Downloader
from nhentai.logger import logger
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
@ -84,6 +84,8 @@ def main():
if (i + 1) % 10 == 0:
logger.info('Progress: %d / %d' % (i + 1, len(doujinshi_ids)))
if not options.is_show:
downloader = Downloader(path=options.output_dir, size=options.threads,
timeout=options.timeout, delay=options.delay)
@ -92,6 +94,14 @@ def main():
if not options.dryrun:
doujinshi.downloader = downloader
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:
with DB() as db:
@ -114,6 +124,7 @@ def main():
else:
[doujinshi.show() for doujinshi in doujinshi_list]
signal.signal(signal.SIGINT, signal_handler)

View File

@ -41,12 +41,9 @@ class Doujinshi(object):
name_format = name_format.replace('%t', self.name)
name_format = name_format.replace('%s', self.info.subtitle)
self.filename = format_filename(name_format)
def __repr__(self):
return '<Doujinshi: {0}>'.format(self.name)
def show(self):
table = [
self.table =[
["Parodies", self.info.parodies],
["Doujinshi", self.name],
["Subtitle", self.info.subtitle],
@ -57,7 +54,15 @@ class Doujinshi(object):
["URL", self.url],
["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):
logger.info('Starting to download doujinshi: %s' % self.name)

View File

@ -290,6 +290,58 @@ def paging(page_string):
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):
conn = None
@ -316,3 +368,6 @@ class DB(object):
def get_all(self):
data = self.cur.execute('SELECT id FROM download_history')
return [i[0] for i in data]