]> git.lizzy.rs Git - nhentai.git/blobdiff - nhentai/utils.py
fix format
[nhentai.git] / nhentai / utils.py
index 7524e926d62cdc0ea419663f7082a80a5704da2e..f7532bf12e3900bbde6683f49fd5b9676d2fe2ee 100644 (file)
@@ -88,7 +88,7 @@ def generate_html(output_dir='.', doujinshi_obj=None, template='default'):
         if not os.path.splitext(image)[1] in ('.jpg', '.png'):
             continue
 
-        image_html += '<img src="{0}" class="image-item"/>\n'\
+        image_html += '<img src="{0}" class="image-item"/>\n' \
             .format(image)
     html = readfile('viewer/{}/index.html'.format(template))
     css = readfile('viewer/{}/styles.css'.format(template))
@@ -169,7 +169,7 @@ def generate_main_html(output_dir='./'):
         else:
             with open('./main.html', 'wb') as f:
                 f.write(data.encode('utf-8'))
-        shutil.copy(os.path.dirname(__file__)+'/viewer/logo.png', './')
+        shutil.copy(os.path.dirname(__file__) + '/viewer/logo.png', './')
         set_js_database()
         logger.log(
             15, 'Main Viewer has been written to \'{0}main.html\''.format(output_dir))
@@ -235,6 +235,7 @@ def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
     except ImportError:
         logger.error("Please install img2pdf package by using pip.")
 
+
 def unicode_truncate(s, length, encoding='utf-8'):
     """https://stackoverflow.com/questions/1809531/truncating-unicode-so-it-fits-a-maximum-size-when-encoded-for-wire-transfer
     """
@@ -251,7 +252,7 @@ def format_filename(s):
     """
     # maybe you can use `--format` to select a suitable filename
     ban_chars = '\\\'/:,;*?"<>|\t'
-    filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars))).strip()
+    filename = s.translate(str.maketrans(ban_chars, ' ' * len(ban_chars))).strip()
     filename = ' '.join(filename.split())
     print(repr(filename))
 
@@ -282,7 +283,7 @@ def paging(page_string):
             start, end = i.split('-')
             if not (start.isdigit() and end.isdigit()):
                 raise Exception('Invalid page number')
-            page_list.extend(list(range(int(start), int(end)+1)))
+            page_list.extend(list(range(int(start), int(end) + 1)))
         else:
             if not i.isdigit():
                 raise Exception('Invalid page number')
@@ -290,58 +291,34 @@ def paging(page_string):
 
     return page_list
 
-def generate_metadatafile(output_dir, table, doujinshi_obj=None):
-    logger.info("Writing Metadata Info")
-   
-       
+
+def generate_metadata_file(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)
+        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")
-    
+        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']
+    special_fields = ['PARODY', 'TITLE', 'ORIGINAL TITLE', 'CHARACTERS', 'AUTHOR',
+                      'LANGUAGE', 'TAGS', 'URL', 'PAGES']
+
+    for i in range(len(fields)):
+        f.write('{}: '.format(fields[i]))
+        if fields[i] in special_fields:
+            f.write(str(table[special_fields.index(fields[i])][1]))
+        f.write('\n')
+
     f.close()
-    
-    
-    
+
 
 class DB(object):
     conn = None
@@ -368,6 +345,3 @@ class DB(object):
     def get_all(self):
         data = self.cur.execute('SELECT id FROM download_history')
         return [i[0] for i in data]
-
-        
-        
\ No newline at end of file