Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(release): v1.1.0 #77

Merged
merged 12 commits into from
Jan 26, 2023
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.1.0](https://github.com/djdembeck/Audnexus.bundle/compare/v1.0.0...v1.1.0) (2023-01-26)


### Features

* use centered images for authors ([#76](https://github.com/djdembeck/Audnexus.bundle/issues/76)) ([6c857ad](https://github.com/djdembeck/Audnexus.bundle/commit/6c857ad84d77c6aacbb08e8c30a06a154e970098))


### Bug Fixes

* **author-search:** bug fix unreachable code when scoring author ([92ec69b](https://github.com/djdembeck/Audnexus.bundle/commit/92ec69b262a4d0d1aef46dcb32fd682c4d1e1a55))

## [1.0.0](https://github.com/djdembeck/Audnexus.bundle/compare/v0.4.1...v1.0.0) (2023-01-24)


Expand Down
152 changes: 46 additions & 106 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from logging import Logging
from search_tools import AlbumSearchTool, ArtistSearchTool, ScoreTool
from time import sleep
from update_tools import AlbumUpdateTool, ArtistUpdateTool, TagTool
from update_tools import AlbumUpdateTool, ArtistUpdateTool

VERSION_NO = version

Expand Down Expand Up @@ -50,6 +50,9 @@ class AudiobookArtist(Agent.Artist):
prev_search_provider = 0

def search(self, results, media, lang, manual):
"""
Search for artist metadata.
"""
# Instantiate search helper
search_helper = ArtistSearchTool(
'authors', lang, manual, media, Prefs, results)
Expand Down Expand Up @@ -130,6 +133,9 @@ def search(self, results, media, lang, manual):
break

def update(self, metadata, media, lang, force):
"""
Update artist metadata.
"""
log.separator(
msg=(
"UPDATING: " + media.title + (
Expand All @@ -145,30 +151,6 @@ def update(self, metadata, media, lang, force):

self.call_item_api(update_helper)

# cleanup description
update_helper.description = (
update_helper.description.replace("<i>", "")
.replace("</i>", "")
.replace("<em>", "")
.replace("</em>", "")
.replace("<u>", "")
.replace("</u>", "")
.replace("<b>", "")
.replace("</b>", "")
.replace("<strong>", "")
.replace("</strong>", "")
.replace("<ul>", "")
.replace("</ul>", "\n")
.replace("<ol>", "")
.replace("</ol>", "\n")
.replace("<li>", " • ")
.replace("</li>", "\n")
.replace("<br />", "")
.replace("<p>", "")
.replace("</p>", "\n")
.strip()
)

self.compile_metadata(update_helper)

def call_search_api(self, helper):
Expand All @@ -188,6 +170,9 @@ def call_search_api(self, helper):
return results_list

def process_results(self, helper, result):
"""
Process the results from the API call.
"""
# Walk the found items and gather extended information
info = []

Expand Down Expand Up @@ -221,38 +206,19 @@ def call_item_api(self, helper):
helper.parse_api_response(response)

def compile_metadata(self, helper):
"""
Compiles the metadata for the artist.
"""
# Description.
if not helper.metadata.summary or helper.force:
helper.metadata.summary = helper.description
tagger = TagTool(helper, Prefs)
# Genres.
tagger.add_genres()
helper.set_metadata_description()
# Tags.
helper.set_metadata_tags()
# Title.
if not helper.metadata.title or helper.force:
helper.metadata.title = helper.name
helper.set_metadata_title()
# Sort Title.
if not helper.metadata.title_sort or helper.force:
if Prefs['sort_author_by_last_name'] and not (
# Handle single word names
re.match(r'\A[\w-]+\Z', helper.name)
):
split_author_surname = re.match(
'^(.+?).([^\s,]+)(,?.(?:[JS]r\.?|III?|IV))?$',
helper.name,
)
helper.metadata.title_sort = ', '.join(
filter(
None,
[
(split_author_surname.group(2) + ', ' +
split_author_surname.group(1)),
split_author_surname.group(3)
]
)
)
else:
helper.metadata.title_sort = helper.metadata.title
helper.set_metadata_sort_title()
# Thumb.
# Kept here because of Proxy
if helper.thumb:
if helper.thumb not in helper.metadata.posters or helper.force:
helper.metadata.posters[helper.thumb] = Proxy.Media(
Expand All @@ -261,12 +227,6 @@ def compile_metadata(self, helper):

helper.log_update_metadata()

def hasProxy(self):
return Prefs['imageproxyurl'] is not None

def makeProxyUrl(self, url, referer):
return Prefs['imageproxyurl'] + ('?url=%s&referer=%s' % (url, referer))


class AudiobookAlbum(Agent.Album):
name = 'Audnexus Agent'
Expand All @@ -279,6 +239,9 @@ class AudiobookAlbum(Agent.Album):
prev_search_provider = 0

def search(self, results, media, lang, manual):
"""
Search for an album.
"""
# Instantiate search helper
search_helper = AlbumSearchTool(
'books', lang, manual, media, Prefs, results)
Expand Down Expand Up @@ -388,6 +351,9 @@ def search(self, results, media, lang, manual):
break

def update(self, metadata, media, lang, force):
"""
Update an album.
"""
log.separator(
msg=(
"UPDATING: " + media.title + (
Expand All @@ -403,30 +369,6 @@ def update(self, metadata, media, lang, force):

self.call_item_api(update_helper)

# cleanup synopsis
update_helper.synopsis = (
update_helper.synopsis.replace("<i>", "")
.replace("</i>", "")
.replace("<em>", "")
.replace("</em>", "")
.replace("<u>", "")
.replace("</u>", "")
.replace("<b>", "")
.replace("</b>", "")
.replace("<strong>", "")
.replace("</strong>", "")
.replace("<ul>", "")
.replace("</ul>", "\n")
.replace("<ol>", "")
.replace("</ol>", "\n")
.replace("<li>", " • ")
.replace("</li>", "\n")
.replace("<br />", "")
.replace("<p>", "")
.replace("</p>", "\n")
.strip()
)

self.compile_metadata(update_helper)

def call_search_api(self, helper):
Expand All @@ -441,6 +383,9 @@ def call_search_api(self, helper):
return results_list

def process_results(self, helper, result):
"""
Process the results from the API call.
"""
# Walk the found items and gather extended information
info = []

Expand Down Expand Up @@ -487,30 +432,24 @@ def call_item_api(self, helper):
helper.date = self.getDateFromString(helper.date)

def compile_metadata(self, helper):
"""
Compiles the metadata for the book.
"""
# Date.
helper.set_date()
tagger = TagTool(helper, Prefs)
# Genres.
tagger.add_genres()
# Narrators.
tagger.add_narrators_to_styles()

helper.set_metadata_date()
# Tags.
helper.set_metadata_tags()
# Moods:
if helper.force:
helper.metadata.moods.clear()
# Authors.
if Prefs['store_author_as_mood']:
tagger.add_authors_to_moods()
# Series.
tagger.add_series_to_moods()
# Title.
helper.set_title()
helper.set_metadata_title()
# Sort Title.
helper.set_sort_title()
helper.set_metadata_sort_title()
# Studio.
helper.set_studio()
helper.set_metadata_studio()
# Summary.
helper.set_summary()
helper.set_metadata_summary()
# Thumb.
# Kept here because of Proxy
if helper.thumb:
Expand All @@ -521,28 +460,29 @@ def compile_metadata(self, helper):
# Re-prioritize the poster to the first position
helper.metadata.posters.validate_keys([helper.thumb])
# Rating.
helper.set_rating()
helper.set_metadata_rating()

# Log the resulting metadata
helper.log_update_metadata()

def getDateFromString(self, string):
"""
Converts a string to a date object.
"""
try:
return Datetime.ParseDate(string).date()
except AttributeError:
return None
except ValueError:
return None

def hasProxy(self):
return Prefs['imageproxyurl'] is not None

def makeProxyUrl(self, url, referer):
return Prefs['imageproxyurl'] + ('?url=%s&referer=%s' % (url, referer))


# Common helpers

def json_decode(output):
"""
Decodes JSON output.
"""
try:
return json.loads(output, encoding="utf-8")
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion Contents/Code/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.0.0"
version = "1.1.0"
49 changes: 28 additions & 21 deletions Contents/Code/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def warn(self, message, *args):
if Prefs['logging_level'] == "DEBUG" or (
Prefs['logging_level'] == "INFO") or (
Prefs['logging_level'] == "WARN"
):
):
# No builtin warn, so use info level for it
return Log(message, *args)

Expand All @@ -39,15 +39,31 @@ def error(self, message, *args):
Prefs['logging_level'] == "INFO") or (
Prefs['logging_level'] == "WARN") or (
Prefs['logging_level'] == "ERROR"
):
):
return Log.Error(message, *args)

def log_output(self, key, val, log_level):
"""
Logs key/value pair with passed log level.
"""
output = "{key:<20}{val}".format(
key=key,
val=val
)
if log_level.lower() == "debug":
self.debug(output)
else:
self.info(output)

# For the below logging:
# Default level is info
# Set debug by calling (msg='sometext', log_level='debug')

# Prints a bunch of divider chars like ---
def separator(self, msg=None, log_level="info"):
"""
Prints a bunch of divider chars like ---,
with optional message.
"""
divider = "-" * 35
output = divider + divider
# Override output with message if passed
Expand All @@ -58,36 +74,27 @@ def separator(self, msg=None, log_level="info"):
return self.debug(output)
return self.info(output)

# Loops through array of dictionaries and logs them
def metadata(self, dict_arr, log_level="info"):
"""
Logs key/value pairs from array of dictionaries.
"""
# Loop through dicts in array
for log_type in dict_arr:
# Loop through each key/value
for key, val in log_type.items():
if val:
output = "{key:<20}{val}".format(
key=key,
val=val
)
if log_level.lower() == "debug":
self.debug(output)
else:
self.info(output)
self.log_output(key, val, log_level)

def metadata_arrs(self, dict_arr, log_level="info"):
"""
Logs key/value pairs from array of dictionaries,
where value is an array.
"""
# Loop through dicts in array
for log_type in dict_arr:
# Loop through each key/value
for key, val in log_type.items():
if val:
# Loop through dict's array
for item in val:
output = ("{key:<20}{val}".format(
key=key,
val=item
)
)
if log_level.lower() == "debug":
self.debug(output)
else:
self.info(output)
self.log_output(item, key, log_level)
Loading