Update all the places we need base_run_time_seconds now
This commit is contained in:
@ -34,7 +34,7 @@ def test_track():
|
|||||||
Track.objects.create(
|
Track.objects.create(
|
||||||
title="Emotion",
|
title="Emotion",
|
||||||
artist=Artist.objects.create(name="Carly Rae Jepsen"),
|
artist=Artist.objects.create(name="Carly Rae Jepsen"),
|
||||||
run_time_seconds=60,
|
base_run_time_seconds=60,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,9 @@ def import_chess_games_for_user_id(user_id: int, commit: bool = False) -> dict:
|
|||||||
for game_dict in games:
|
for game_dict in games:
|
||||||
chess, created = BoardGame.objects.get_or_create(title="Chess")
|
chess, created = BoardGame.objects.get_or_create(title="Chess")
|
||||||
if created:
|
if created:
|
||||||
chess.run_time_seconds = 1800
|
chess.base_run_time_seconds = 1800
|
||||||
chess.bggeek_id = 171
|
chess.bggeek_id = 171
|
||||||
chess.save(update_fields=["run_time_seconds", "bggeek_id"])
|
chess.save(update_fields=["base_run_time_seconds", "bggeek_id"])
|
||||||
scrobble = Scrobble.objects.filter(
|
scrobble = Scrobble.objects.filter(
|
||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
timestamp=game_dict.get("createdAt"),
|
timestamp=game_dict.get("createdAt"),
|
||||||
|
|||||||
@ -114,7 +114,7 @@ def create_book_from_row(row: list):
|
|||||||
"raw_row_data": clean_row,
|
"raw_row_data": clean_row,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
run_time_seconds=run_time,
|
base_run_time_seconds=run_time,
|
||||||
)
|
)
|
||||||
# TODO Move these to async processes after importing
|
# TODO Move these to async processes after importing
|
||||||
# book.fix_metadata()
|
# book.fix_metadata()
|
||||||
|
|||||||
@ -402,7 +402,7 @@ class Book(LongPlayScrobblableMixin):
|
|||||||
self.cover.save(fname, ContentFile(r.content), save=True)
|
self.cover.save(fname, ContentFile(r.content), save=True)
|
||||||
|
|
||||||
if self.pages:
|
if self.pages:
|
||||||
self.run_time_seconds = int(self.pages) * int(
|
self.base_run_time_seconds = int(self.pages) * int(
|
||||||
self.AVG_PAGE_READING_SECONDS
|
self.AVG_PAGE_READING_SECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -67,9 +67,9 @@ def lookup_book_from_google(title: str) -> dict:
|
|||||||
.replace("&edge=curl", "")
|
.replace("&edge=curl", "")
|
||||||
)
|
)
|
||||||
|
|
||||||
book_dict["run_time_seconds"] = 3600
|
book_dict["base_run_time_seconds"] = 3600
|
||||||
if book_dict.get("pages"):
|
if book_dict.get("pages"):
|
||||||
book_dict["run_time_seconds"] = book_dict.get("pages", 10) * getattr(
|
book_dict["base_run_time_seconds"] = book_dict.get("pages", 10) * getattr(
|
||||||
settings, "AVERAGE_PAGE_READING_SECONDS", 60
|
settings, "AVERAGE_PAGE_READING_SECONDS", 60
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -67,7 +67,7 @@ def lookup_paper_from_semantic(title: str) -> dict:
|
|||||||
paper_dict["openaccess_pdf_url"] = result.get("openAccessPdf", {}).get(
|
paper_dict["openaccess_pdf_url"] = result.get("openAccessPdf", {}).get(
|
||||||
"url"
|
"url"
|
||||||
)
|
)
|
||||||
paper_dict["run_time_seconds"] = paper_dict.get("pages", 10) * getattr(
|
paper_dict["base_run_time_seconds"] = paper_dict.get("pages", 10) * getattr(
|
||||||
settings, "AVERAGE_PAGE_READING_SECONDS", 60
|
settings, "AVERAGE_PAGE_READING_SECONDS", 60
|
||||||
)
|
)
|
||||||
paper_dict["author_dicts"] = result.get("authors")
|
paper_dict["author_dicts"] = result.get("authors")
|
||||||
|
|||||||
@ -677,7 +677,7 @@ class Track(ScrobblableMixin):
|
|||||||
|
|
||||||
lookup_keys = {"title": title, "artist": artist}
|
lookup_keys = {"title": title, "artist": artist}
|
||||||
if run_time_seconds:
|
if run_time_seconds:
|
||||||
lookup_keys["run_time_seconds"] = run_time_seconds
|
lookup_keys["base_run_time_seconds"] = run_time_seconds
|
||||||
logger.info(f"Looking up track using: {lookup_keys}")
|
logger.info(f"Looking up track using: {lookup_keys}")
|
||||||
track = cls.objects.filter(**lookup_keys).first()
|
track = cls.objects.filter(**lookup_keys).first()
|
||||||
if track:
|
if track:
|
||||||
@ -699,7 +699,7 @@ class Track(ScrobblableMixin):
|
|||||||
if album:
|
if album:
|
||||||
track.albums.add(album)
|
track.albums.add(album)
|
||||||
|
|
||||||
if enrich or not track.run_time_seconds:
|
if enrich or not track.base_run_time_seconds:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Enriching track {track}",
|
f"Enriching track {track}",
|
||||||
extra={
|
extra={
|
||||||
@ -715,7 +715,7 @@ class Track(ScrobblableMixin):
|
|||||||
except Exception:
|
except Exception:
|
||||||
print("No musicbrainz result found, cannot enrich")
|
print("No musicbrainz result found, cannot enrich")
|
||||||
return track
|
return track
|
||||||
track.run_time_seconds = run_time_seconds or int(length / 1000)
|
track.base_run_time_seconds = run_time_seconds or int(length / 1000)
|
||||||
track.musicbrainz_id = mbid
|
track.musicbrainz_id = mbid
|
||||||
if commit:
|
if commit:
|
||||||
track.save()
|
track.save()
|
||||||
|
|||||||
@ -145,7 +145,7 @@ class PodcastEpisode(ScrobblableMixin):
|
|||||||
title: str,
|
title: str,
|
||||||
pub_date: str,
|
pub_date: str,
|
||||||
episode_num: int = 0,
|
episode_num: int = 0,
|
||||||
run_time_seconds: int = 1800,
|
base_run_time_seconds: int = 2400,
|
||||||
mopidy_uri: str = "",
|
mopidy_uri: str = "",
|
||||||
podcast_name: str = "",
|
podcast_name: str = "",
|
||||||
podcast_producer: str = "",
|
podcast_producer: str = "",
|
||||||
@ -174,7 +174,7 @@ class PodcastEpisode(ScrobblableMixin):
|
|||||||
title=title,
|
title=title,
|
||||||
podcast=podcast,
|
podcast=podcast,
|
||||||
defaults={
|
defaults={
|
||||||
"run_time_seconds": run_time_seconds,
|
"base_run_time_seconds": base_run_time_seconds,
|
||||||
"number": episode_num,
|
"number": episode_num,
|
||||||
"pub_date": pub_date,
|
"pub_date": pub_date,
|
||||||
"mopidy_uri": mopidy_uri,
|
"mopidy_uri": mopidy_uri,
|
||||||
|
|||||||
@ -62,7 +62,7 @@ def fetch_metadata_from_rss(uri: str) -> dict[str, Any]:
|
|||||||
podcast_data["title"] = entry.title
|
podcast_data["title"] = entry.title
|
||||||
podcast_data["episode_num"] = int(entry.get("itunes_episode", 0))
|
podcast_data["episode_num"] = int(entry.get("itunes_episode", 0))
|
||||||
podcast_data["pub_date"] = parse(entry.get("published", None))
|
podcast_data["pub_date"] = parse(entry.get("published", None))
|
||||||
podcast_data["run_time_seconds"] = parse_duration(entry.get("itunes_duration", None))
|
podcast_data["base_run_time_seconds"] = parse_duration(entry.get("itunes_duration", None))
|
||||||
# podcast_data["description"] = entry.get("description", None)
|
# podcast_data["description"] = entry.get("description", None)
|
||||||
# podcast_data["episode_url"] = entry.enclosures[0].href if entry.get("enclosures") else None
|
# podcast_data["episode_url"] = entry.enclosures[0].href if entry.get("enclosures") else None
|
||||||
return podcast_data
|
return podcast_data
|
||||||
|
|||||||
@ -95,8 +95,8 @@ class Task(LongPlayScrobblableMixin):
|
|||||||
def find_or_create(cls, title: str) -> "Task":
|
def find_or_create(cls, title: str) -> "Task":
|
||||||
task, created = cls.objects.get_or_create(title=title)
|
task, created = cls.objects.get_or_create(title=title)
|
||||||
if created:
|
if created:
|
||||||
task.run_time_seconds = 1800
|
task.base_run_time_seconds = 1800
|
||||||
task.save(update_fields=["run_time_seconds"])
|
task.save(update_fields=["base_run_time_seconds"])
|
||||||
|
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
|||||||
@ -238,8 +238,8 @@ class VideoGame(LongPlayScrobblableMixin):
|
|||||||
load_game_data_from_igdb(self.id, self.igdb_id)
|
load_game_data_from_igdb(self.id, self.igdb_id)
|
||||||
|
|
||||||
if force_update and self.main_story_time:
|
if force_update and self.main_story_time:
|
||||||
self.run_time_seconds = self.main_story_time
|
self.base_run_time_seconds = self.main_story_time
|
||||||
self.save(update_fields=["run_time_seconds"])
|
self.save(update_fields=["base_run_time_seconds"])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_or_create(cls, data_dict: dict) -> "Game":
|
def find_or_create(cls, data_dict: dict) -> "Game":
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class VideoType(Enum):
|
|||||||
class VideoMetadata:
|
class VideoMetadata:
|
||||||
title: str
|
title: str
|
||||||
video_type: VideoType = VideoType.UNKNOWN
|
video_type: VideoType = VideoType.UNKNOWN
|
||||||
run_time_seconds: int = (
|
base_run_time_seconds: int = (
|
||||||
60 # Silly default, but things break if this is 0 or null
|
60 # Silly default, but things break if this is 0 or null
|
||||||
)
|
)
|
||||||
imdb_id: Optional[str]
|
imdb_id: Optional[str]
|
||||||
@ -51,11 +51,11 @@ class VideoMetadata:
|
|||||||
self,
|
self,
|
||||||
imdb_id: Optional[str] = "",
|
imdb_id: Optional[str] = "",
|
||||||
youtube_id: Optional[str] = "",
|
youtube_id: Optional[str] = "",
|
||||||
run_time_seconds: int = 900,
|
base_run_time_seconds: int = 900,
|
||||||
):
|
):
|
||||||
self.imdb_id = imdb_id
|
self.imdb_id = imdb_id
|
||||||
self.youtube_id = youtube_id
|
self.youtube_id = youtube_id
|
||||||
self.run_time_seconds = run_time_seconds
|
self.base_run_time_seconds = base_run_time_seconds
|
||||||
|
|
||||||
def as_dict_with_cover_and_genres(self) -> tuple:
|
def as_dict_with_cover_and_genres(self) -> tuple:
|
||||||
video_dict = vars(self)
|
video_dict = vars(self)
|
||||||
|
|||||||
@ -84,7 +84,7 @@ def lookup_video_from_imdb(
|
|||||||
video_metadata.tv_series_id = series.id
|
video_metadata.tv_series_id = series.id
|
||||||
|
|
||||||
if imdb_result.get("runtimes"):
|
if imdb_result.get("runtimes"):
|
||||||
video_metadata.run_time_seconds = (
|
video_metadata.base_run_time_seconds = (
|
||||||
int(imdb_result.get("runtimes")[0]) * 60
|
int(imdb_result.get("runtimes")[0]) * 60
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ def lookup_video_from_skatevideosite(title: str) -> Optional[dict]:
|
|||||||
.replace("(", "")
|
.replace("(", "")
|
||||||
.replace(")", "")
|
.replace(")", "")
|
||||||
)
|
)
|
||||||
run_time_seconds = (
|
base_run_time_seconds = (
|
||||||
int(
|
int(
|
||||||
detail_soup.find("div", class_="p-1")
|
detail_soup.find("div", class_="p-1")
|
||||||
.contents[-1]
|
.contents[-1]
|
||||||
@ -123,6 +123,6 @@ def lookup_video_from_skatevideosite(title: str) -> Optional[dict]:
|
|||||||
"title": str(result.find("img").get("alt").replace(" cover", "")),
|
"title": str(result.find("img").get("alt").replace(" cover", "")),
|
||||||
"video_type": "S",
|
"video_type": "S",
|
||||||
"year": year,
|
"year": year,
|
||||||
"run_time_seconds": run_time_seconds,
|
"base_run_time_seconds": run_time_seconds,
|
||||||
"cover_url": str(result.find("img").get("src")),
|
"cover_url": str(result.find("img").get("src")),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ def lookup_video_from_tmdb(
|
|||||||
return video_metadata
|
return video_metadata
|
||||||
|
|
||||||
video_metadata.tmdb_id = media.id
|
video_metadata.tmdb_id = media.id
|
||||||
video_metadata.run_time_seconds = media.runtime * 60
|
video_metadata.base_run_time_seconds = media.runtime * 60
|
||||||
video_metadata.plot = media.overview
|
video_metadata.plot = media.overview
|
||||||
video_metadata.overview = media.overview
|
video_metadata.overview = media.overview
|
||||||
video_metadata.tmdb_rating = media.vote_average
|
video_metadata.tmdb_rating = media.vote_average
|
||||||
|
|||||||
@ -65,7 +65,7 @@ def lookup_video_from_youtube(youtube_id: str) -> VideoMetadata:
|
|||||||
video_metadata.channel_id = channel.id
|
video_metadata.channel_id = channel.id
|
||||||
|
|
||||||
video_metadata.title = yt_metadata.get("title", "")
|
video_metadata.title = yt_metadata.get("title", "")
|
||||||
video_metadata.run_time_seconds = duration
|
video_metadata.base_run_time_seconds = duration
|
||||||
video_metadata.video_type = VideoType.YOUTUBE.value
|
video_metadata.video_type = VideoType.YOUTUBE.value
|
||||||
video_metadata.youtube_id = youtube_id
|
video_metadata.youtube_id = youtube_id
|
||||||
video_metadata.cover_url = (
|
video_metadata.cover_url = (
|
||||||
|
|||||||
@ -220,8 +220,8 @@ class WebPage(ScrobblableMixin):
|
|||||||
if not self.domain or force:
|
if not self.domain or force:
|
||||||
self._update_domain_from_url()
|
self._update_domain_from_url()
|
||||||
|
|
||||||
if not self.run_time_seconds or force:
|
if not self.base_run_time_seconds or force:
|
||||||
self.run_time_seconds = self.estimated_time_to_read_in_seconds
|
self.base_run_time_seconds = self.estimated_time_to_read_in_seconds
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
self.save()
|
self.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user