Skip to content

Commit

Permalink
Merge pull request #357 from FelixJS123/favorite_metadata
Browse files Browse the repository at this point in the history
add favorites count metadata
  • Loading branch information
RicterZ authored Dec 4, 2024
2 parents c2e880f + 841988b commit b2befd3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion nhentai/doujinshi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand All @@ -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],
]
Expand Down
3 changes: 2 additions & 1 deletion nhentai/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)$',
Expand Down
3 changes: 3 additions & 0 deletions nhentai/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2befd3

Please sign in to comment.