Skip to content

Commit

Permalink
Feature: can update reviews (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Dec 17, 2023
1 parent 8e80187 commit af1e821
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion MetaTube.bundle/Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ def translate_reviews(reviews, lang):
review.comment = translate_text(review.comment, lang=lang,
fallback=review.comment)

# noinspection PyMethodMayBeStatic
@staticmethod
def try_update_reviews(pid):
if not pid.update:
return

try:
return api.get_movie_reviews(provider=pid.provider, id=pid.id,
lazy=(pid.update is not True))
except Exception as e:
Log.Warn('Try to update reviews for {pid:s} failed: {error}'
.format(pid=pid, error=e))

def search(self, results, media, lang, manual=False):

position = None
Expand All @@ -165,6 +176,7 @@ def search(self, results, media, lang, manual=False):
position = pid.position # update position
search_results.append(api.get_movie_info(
provider=pid.provider, id=pid.id, lazy=(pid.update is not True)))
self.try_update_reviews(pid=pid)
except ValueError: # fallback to name based search
search_results = api.search_movie(q=media.name)

Expand Down
4 changes: 2 additions & 2 deletions MetaTube.bundle/Contents/Code/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ def get_movie_info(self, provider, id, lazy=None):
lazy=lazy),
require_auth=True))

def get_movie_reviews(self, provider, id, homepage=None):
def get_movie_reviews(self, provider, id, homepage=None, lazy=None):
return [MovieReviewObject(**data) for data in self.get_json(
url=self.prepare_url(
self.MOVIE_REVIEW_API, provider, id,
homepage=homepage),
homepage=homepage, lazy=lazy),
require_auth=True)]

def get_primary_image_url(self, provider, id,
Expand Down

0 comments on commit af1e821

Please sign in to comment.