diff --git a/README.rst b/README.rst index 6f5aaba..00098b8 100644 --- a/README.rst +++ b/README.rst @@ -140,6 +140,7 @@ Format output doujinshi folder name: Supported doujinshi folder formatter: - %i: Doujinshi id +- %f: Doujinshi favorite count - %t: Doujinshi name - %s: Doujinshi subtitle (translated name) - %a: Doujinshi authors' name diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index d5efe24..7d9bd2f 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -29,11 +29,12 @@ def __getattr__(self, item): class Doujinshi(object): - def __init__(self, name=None, pretty_name=None, id=None, img_id=None, + def __init__(self, name=None, pretty_name=None, id=None, favorite_counts=0, img_id=None, ext='', pages=0, name_format='[%i][%a][%t]', **kwargs): self.name = name self.pretty_name = pretty_name self.id = id + self.favorite_counts = favorite_counts self.img_id = img_id self.ext = ext self.pages = pages @@ -45,6 +46,7 @@ def __init__(self, name=None, pretty_name=None, id=None, img_id=None, name_format = name_format.replace('%ag', format_filename(ag_value)) name_format = name_format.replace('%i', format_filename(str(self.id))) + name_format = name_format.replace('%f', format_filename(str(self.favorite_counts))) name_format = name_format.replace('%a', format_filename(self.info.artists)) name_format = name_format.replace('%g', format_filename(self.info.groups)) @@ -63,6 +65,7 @@ def __init__(self, name=None, pretty_name=None, id=None, img_id=None, ['Groups', self.info.groups], ['Languages', self.info.languages], ['Tags', self.info.tags], + ['Favorite Counts', self.info.favorite_counts], ['URL', self.url], ['Pages', self.pages], ] diff --git a/nhentai/parser.py b/nhentai/parser.py index fcee9ad..4060bfb 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -142,10 +142,11 @@ def doujinshi_parser(id_, counter=0): title = doujinshi_info.find('h1').text pretty_name = doujinshi_info.find('h1').find('span', attrs={'class': 'pretty'}).text subtitle = doujinshi_info.find('h2') - + favorite_counts = doujinshi_info.find('span', class_='nobold').find('span', class_='count').text.strip() doujinshi['name'] = title doujinshi['pretty_name'] = pretty_name doujinshi['subtitle'] = subtitle.text if subtitle else '' + doujinshi['favorite_counts'] = favorite_counts doujinshi_cover = html.find('div', attrs={'id': 'cover'}) img_id = re.search('/galleries/([0-9]+)/cover.(jpg|png|gif|webp)$', diff --git a/nhentai/serializer.py b/nhentai/serializer.py index c76bab9..29c0ef4 100644 --- a/nhentai/serializer.py +++ b/nhentai/serializer.py @@ -8,6 +8,8 @@ def serialize_json(doujinshi, output_dir): metadata = {'title': doujinshi.name, 'subtitle': doujinshi.info.subtitle} + if doujinshi.info.favorite_counts: + metadata['favorite_counts'] = doujinshi.favorite_counts if doujinshi.info.date: metadata['upload_date'] = doujinshi.info.date if doujinshi.info.parodies: @@ -44,6 +46,7 @@ def serialize_comic_xml(doujinshi, output_dir): xml_write_simple_tag(f, 'PageCount', doujinshi.pages) xml_write_simple_tag(f, 'URL', doujinshi.url) xml_write_simple_tag(f, 'NhentaiId', doujinshi.id) + xml_write_simple_tag(f, 'Favorites', doujinshi.favorite_counts) xml_write_simple_tag(f, 'Genre', doujinshi.info.categories) xml_write_simple_tag(f, 'BlackAndWhite', 'No' if doujinshi.info.tags and