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

various fixes #724

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion catalog/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def display_description(self) -> str:

@property
def brief_description(self):
return (self.display_description or "")[:155]
return (str(self.display_description) or "")[:155]

@classmethod
def get_by_url(cls, url_or_b62: str, resolve_merge=False) -> "Self | None":
Expand Down
20 changes: 10 additions & 10 deletions catalog/common/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ def match_existing_item_for_resource(
ids = resource.get_lookup_ids(cls.DEFAULT_MODEL)
for t, v in ids:
matched = None
# matched = model.objects.filter(
# primary_lookup_id_type=t,
# primary_lookup_id_value=v,
# title=resource.metadata["title"],
# ).first()
# if matched is None and resource.id_type not in [
# IdType.DoubanMusic, # DoubanMusic has many dirty data with same UPC
# # IdType.Goodreads, # previous scraper generated some dirty data
# ]:
matched = model.objects.filter(
primary_lookup_id_type=t,
primary_lookup_id_value=v,
title=resource.metadata["title"],
primary_lookup_id_type=t, primary_lookup_id_value=v
).first()
if matched is None and resource.id_type not in [
IdType.DoubanMusic, # DoubanMusic has many dirty data with same UPC
# IdType.Goodreads, # previous scraper generated some dirty data
]:
matched = model.objects.filter(
primary_lookup_id_type=t, primary_lookup_id_value=v
).first()
if matched is None:
matched = model.objects.filter(
primary_lookup_id_type=resource.id_type,
Expand Down
14 changes: 5 additions & 9 deletions catalog/sites/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ def id_to_url(cls, id_value):
return "https://www.imdb.com/title/" + id_value + "/"

def scrape(self):
res_data = {}
try:
res_data = search_tmdb_by_imdb_id(self.id_value)
except:
pass
res_data = search_tmdb_by_imdb_id(self.id_value)

url = None
pd = None
Expand Down Expand Up @@ -91,15 +87,15 @@ def scrape_imdb(self):
"genre": (
[x["text"] for x in d["genres"]["genres"]] if d.get("genres") else []
),
"brief": (
d["plot"].get("plotText").get("plainText") if d.get("plot") else None
),
"brief": d.get("plot", {}).get("plotText", {}).get("plainText", ""),
"cover_image_url": (
d["primaryImage"].get("url") if d.get("primaryImage") else None
),
}
data["localized_title"] = [{"lang": "en", "text": data["title"]}]
data["localized_description"] = [{"lang": "en", "text": data["brief"]}]
data["localized_description"] = (
[{"lang": "en", "text": data["brief"]}] if data["brief"] else []
)
if d.get("series"):
episode_info = d["series"].get("episodeNumber")
if episode_info:
Expand Down
24 changes: 14 additions & 10 deletions catalog/sites/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def _get_language_code():

def _get_preferred_languages():
langs = {}
for l in PREFERRED_LANGUAGES:
if l == "zh":
for lang in PREFERRED_LANGUAGES:
if lang == "zh":
langs.update({"zh-cn": "zh-CN", "zh-tw": "zh-TW", "zh-hk": "zh-HK"})
else:
langs[l] = l
langs[lang] = lang
return langs


Expand All @@ -50,9 +50,13 @@ def _get_preferred_languages():


def search_tmdb_by_imdb_id(imdb_id):
if not settings.TMDB_API3_KEY or settings.TMDB_API3_KEY == "TESTONLY":
return {}
tmdb_api_url = f"https://api.themoviedb.org/3/find/{imdb_id}?api_key={settings.TMDB_API3_KEY}&language={TMDB_DEFAULT_LANG}&external_source=imdb_id"
res_data = BasicDownloader(tmdb_api_url).download().json()
return res_data
try:
return BasicDownloader(tmdb_api_url).download().json()
except Exception:
return {}


def query_tmdb_tv_episode(tv, season, episode):
Expand Down Expand Up @@ -126,7 +130,7 @@ def scrape(self):
actor = list(map(lambda x: x["name"], res_data["credits"]["cast"]))
area = []

other_info = {}
# other_info = {}
# other_info['TMDB评分'] = res_data['vote_average']
# other_info['分级'] = res_data['contentRating']
# other_info['Metacritic评分'] = res_data['metacriticRating']
Expand Down Expand Up @@ -233,9 +237,9 @@ def scrape(self):
)
actor = list(map(lambda x: x["name"], res_data["credits"]["cast"]))
area = []
other_info = {}
other_info["Seasons"] = res_data["number_of_seasons"]
other_info["Episodes"] = res_data["number_of_episodes"]
# other_info = {}
# other_info["Seasons"] = res_data["number_of_seasons"]
# other_info["Episodes"] = res_data["number_of_episodes"]
# TODO: use GET /configuration to get base url
img_url = (
("https://image.tmdb.org/t/p/original/" + res_data["poster_path"])
Expand Down Expand Up @@ -446,7 +450,7 @@ def scrape(self):
season_id = v[1]
episode_id = v[2]
site = TMDB_TV(TMDB_TV.id_to_url(show_id))
show_resource = site.get_resource_ready(auto_create=False, auto_link=False)
site.get_resource_ready(auto_create=False, auto_link=False)
api_url = f"https://api.themoviedb.org/3/tv/{show_id}/season/{season_id}/episode/{episode_id}?api_key={settings.TMDB_API3_KEY}&language={TMDB_DEFAULT_LANG}&append_to_response=external_ids,credits"
d = BasicDownloader(api_url).download().json()
if not d.get("id"):
Expand Down
4 changes: 2 additions & 2 deletions mastodon/models/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def _send(email, subject, body):
fail_silently=False,
)
except Exception as e:
logger.error(f"send email to {email} failed: {e}", extra={"exception": e})
logger.error(f"send email to {email} failed: {e}")

@staticmethod
def generate_login_email(email: str, action: str) -> tuple[str, str]:
if action != "verify":
account = EmailAccount.objects.filter(handle__iexact=email).first()
action = "register" if account and account.user else "login"
action = "login" if account and account.user else "register"
s = {"e": email, "a": action}
# v = TimestampSigner().sign_object(s)
code = b62_encode(random.randint(pow(62, 4), pow(62, 5) - 1))
Expand Down
3 changes: 2 additions & 1 deletion social/templates/feed_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<div>
<div class="avatar" style="margin:0.6em 0.6em 0.6em 0;">
<a href="{{ post.author.url }}">
<img src="{{ post.author.icon_uri }}" alt="@{{ post.author.handle }}">
<img src="{{ post.author.local_icon_url }}"
alt="@{{ post.author.handle }}">
</a>
</div>
</div>
Expand Down
Loading