Пример #1
0
 def _hdoujindler(self, fp: io.TextIO):
     """HDoujin Downloader"""
     if fp.name.endswith('info.txt'):
         log_i('Detected metafile: HDoujin text')
         lines = fp.readlines()
         if lines:
             for line in lines:
                 splitted = line.split(':', 1)
                 if len(splitted) > 1:
                     other = splitted[1].strip()
                     if not other:
                         continue
                     l = splitted[0].lower()
                     if "title" == l:
                         self.metadata['title'] = other
                     if "artist" == l:
                         self.metadata['artist'] = other.capitalize()
                     if "tags" == l:
                         self.metadata['tags'].update(tag_to_dict(other))
                     if "description" == l:
                         self.metadata['info'] = other
                     if "circle" in l:
                         if not "group" in self.metadata['tags']:
                             self.metadata['tags']['group'] = []
                             self.metadata['tags']['group'].append(other.strip().lower())
                     if "url" == l:
                         self.metadata['link'] = other
             return True
Пример #2
0
    def load_from_file(self, txt_file: TextIO):
        """
        Given the output from an open() method, populates self with data from lines of text file
        """
        txt_lines = txt_file.readlines()
        for row in txt_lines:
            obj_info = list()

            padded_fields = row.split(
                FIELD_ESCAPE_STR)  # split line/row by separator
            for field in padded_fields:
                if field != '\n':
                    field = field.strip()  # remove trailing/padding whitespace
                    field = field.replace(LINEBREAK_ESCAPE_STR,
                                          '\n')  # re-insert escaped linebreaks
                    obj_info.append(field)

            self.add_row(*obj_info)  # add new row/obj to table

        txt_file.close()
        logging.debug(
            f'{type(self).__name__} object successfully populated from file - '
            f'added {len(txt_lines)} {self.row_class.__name__} objects')