Skip to content

Commit

Permalink
Merge pull request #18 from djdembeck/develop
Browse files Browse the repository at this point in the history
Improve score calculation; Fix crash on single-genre
  • Loading branch information
djdembeck committed Aug 28, 2021
2 parents a5150ed + 7dd4251 commit 1fa230b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
36 changes: 28 additions & 8 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from update_tools import UpdateTool
from urls import SiteUrl

VERSION_NO = '2021.08.27.1'
VERSION_NO = '2021.08.28.1'

# Delay used when requesting HTML,
# may be good to have to prevent being banned from the site
Expand Down Expand Up @@ -235,8 +235,8 @@ def update(self, metadata, media, lang, force=False):

log.separator(
msg=(
"UPDATING" + media.title + (
"ID: " + metadata.id
"UPDATING: " + media.title + (
" ID: " + metadata.id
)
),
log_level="info"
Expand Down Expand Up @@ -288,14 +288,20 @@ def update(self, metadata, media, lang, force=False):
.replace("</p>", "\n")
)

# Handle single genre result
if update_helper.genre_child:
genre_string = update_helper.genre_parent + ', ' + update_helper.genre_child
else:
genre_string = update_helper.genre_parent

# Setup logging of all data in the array
data_to_log = [
{'date': update_helper.date},
{'title': update_helper.title},
{'author': update_helper.author},
{'narrator': update_helper.narrator},
{'series': update_helper.series},
{'genres': update_helper.genre_parent + ', ' + update_helper.genre_child},
{'genres': genre_string},
{'studio': update_helper.studio},
{'thumb': update_helper.thumb},
{'rating': update_helper.rating},
Expand Down Expand Up @@ -473,20 +479,32 @@ def run_search(self, helper, media, result):
if date is not None:
year = date.year

# Make sure this isn't a pre-order listing
if helper.check_if_preorder(date):
continue

# Score the album name
scorebase1 = media.album
scorebase2 = title.encode('utf-8')

score = INITIAL_SCORE - Util.LevenshteinDistance(
album_score = INITIAL_SCORE - Util.LevenshteinDistance(
scorebase1, scorebase2
)
log.debug("Score from album: " + str(album_score))

# Score the author name
if media.artist:
scorebase3 = media.artist
scorebase4 = author
score = INITIAL_SCORE - Util.LevenshteinDistance(
author_score = INITIAL_SCORE - Util.LevenshteinDistance(
scorebase3, scorebase4
)
log.debug("Score from author: " + str(author_score))
# Find the difference in score between name and author
score = (
album_score + author_score
) - INITIAL_SCORE
else:
score = album_score

log.info("Result #" + str(i + 1))
# Log basic metadata
Expand Down Expand Up @@ -687,7 +705,9 @@ def compile_metadata(self, helper):
if not Prefs['no_overwrite_genre']:
helper.metadata.genres.clear()
helper.metadata.genres.add(helper.genre_parent)
helper.metadata.genres.add(helper.genre_child)
# Not all books have 2 genres
if helper.genre_child:
helper.metadata.genres.add(helper.genre_child)

self.parse_author_narrator(helper)

Expand Down
6 changes: 6 additions & 0 deletions Contents/Code/search_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import date
import re
# Import internal tools
from logging import Logging
Expand All @@ -13,6 +14,11 @@ def __init__(self, lang, manual, media, results):
self.media = media
self.results = results

def check_if_preorder(self, book_date):
current_date = (date.today())
if book_date > current_date:
return True

def get_id_from_url(self, item):
url = item['url']
log.debug('URL For Breakdown: %s', url)
Expand Down
6 changes: 6 additions & 0 deletions Contents/Code/update_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def re_parse_with_date_published(self, json_data):
)
except AttributeError:
continue
except IndexError:
log.info(
'"' + self.title + '", '
"only has one genre"
)
continue

# Writes metadata information to log.
def writeInfo(self):
Expand Down

0 comments on commit 1fa230b

Please sign in to comment.