fix migration for tv seasons
This commit is contained in:
parent
14861cf609
commit
2a853024cd
5 changed files with 40 additions and 25 deletions
|
@ -175,12 +175,8 @@ class Item(SoftDeleteMixin, PolymorphicModel):
|
|||
category = None # subclass must specify this
|
||||
demonstrative = None # subclass must specify this
|
||||
uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)
|
||||
# item_type = models.CharField(_("类型"), choices=ItemType.choices, blank=False, max_length=50)
|
||||
title = models.CharField(_("title in primary language"), max_length=1000, default="")
|
||||
# title_ml = models.JSONField(_("title in different languages {['lang':'zh-cn', 'text':'', primary:True], ...}"), null=True, blank=True, default=list)
|
||||
brief = models.TextField(_("简介"), blank=True, default="")
|
||||
# brief_ml = models.JSONField(_("brief in different languages {['lang':'zh-cn', 'text':'', primary:True], ...}"), null=True, blank=True, default=list)
|
||||
genres = models.JSONField(_("分类"), null=True, blank=True, default=list)
|
||||
primary_lookup_id_type = models.CharField(_("isbn/cubn/imdb"), blank=False, null=True, max_length=50)
|
||||
primary_lookup_id_value = models.CharField(_("1234/tt789"), blank=False, null=True, max_length=1000)
|
||||
metadata = models.JSONField(_("其他信息"), blank=True, null=True, default=dict)
|
||||
|
|
|
@ -103,8 +103,23 @@ class AbstractSite:
|
|||
def ready(self):
|
||||
return bool(self.resource and self.resource.ready)
|
||||
|
||||
def get_resource_ready(self, auto_save=True, auto_create=True, auto_link=True, preloaded_content=None, reload=False):
|
||||
"""return a resource scraped, or scrape if not yet"""
|
||||
def get_resource_ready(self, auto_save=True, auto_create=True, auto_link=True, preloaded_content=None, ignore_existing_content=False):
|
||||
"""
|
||||
Returns an ExternalResource in scraped state if possible
|
||||
|
||||
Parameters
|
||||
----------
|
||||
auto_save : bool
|
||||
automatically saves the ExternalResource and, if auto_create, the Item too
|
||||
auto_create : bool
|
||||
automatically creates an Item if not exist yet
|
||||
auto_link : bool
|
||||
automatically scrape the linked resources (e.g. a TVSeason may have a linked TVShow)
|
||||
preloaded_content : ResourceContent or dict
|
||||
skip scrape(), and use this as scraped result
|
||||
ignore_existing_content : bool
|
||||
if ExternalResource already has content, ignore that and either use preloaded_content or call scrape()
|
||||
"""
|
||||
if auto_link:
|
||||
auto_create = True
|
||||
if auto_create:
|
||||
|
@ -113,7 +128,7 @@ class AbstractSite:
|
|||
resource_content = {}
|
||||
if not self.resource:
|
||||
return None
|
||||
if not p.ready or reload:
|
||||
if not p.ready or ignore_existing_content:
|
||||
if isinstance(preloaded_content, ResourceContent):
|
||||
resource_content = preloaded_content
|
||||
elif isinstance(preloaded_content, dict):
|
||||
|
|
|
@ -36,7 +36,8 @@ class TVShow(Item):
|
|||
imdb = PrimaryLookupIdDescriptor(IdType.IMDB)
|
||||
tmdb_tv = PrimaryLookupIdDescriptor(IdType.TMDB_TV)
|
||||
imdb = PrimaryLookupIdDescriptor(IdType.IMDB)
|
||||
season_count = jsondata.IntegerField(null=True)
|
||||
season_count = models.IntegerField(null=True)
|
||||
episode_count = models.PositiveIntegerField(null=True)
|
||||
|
||||
METADATA_COPY_LIST = [
|
||||
'title',
|
||||
|
@ -53,7 +54,8 @@ class TVShow(Item):
|
|||
'language',
|
||||
'year',
|
||||
'duration',
|
||||
'season_number',
|
||||
'season_count',
|
||||
'episode_count',
|
||||
'single_episode_length',
|
||||
'brief',
|
||||
]
|
||||
|
|
|
@ -23,53 +23,55 @@ Item .. Content
|
|||
class Content {
|
||||
+Item target
|
||||
}
|
||||
Content <|-- Rating
|
||||
Content <|-- Rating
|
||||
class Rating {
|
||||
+int grade
|
||||
}
|
||||
Content <|-- Review
|
||||
Content <|-- Review
|
||||
class Review {
|
||||
+Enum warning_type
|
||||
+str title
|
||||
+str body
|
||||
}
|
||||
Content <|-- Comment
|
||||
class Comment {
|
||||
+str text
|
||||
}
|
||||
|
||||
Content <|-- Note
|
||||
class Note {
|
||||
+str text
|
||||
+int position
|
||||
+enum position_type
|
||||
+str quotation
|
||||
+Image image
|
||||
|
||||
+Image image
|
||||
|
||||
}
|
||||
Content <|-- Reply
|
||||
class Reply {
|
||||
+Content reply_to
|
||||
}
|
||||
Piece <|-- List
|
||||
Item <|-- List
|
||||
class List{
|
||||
+ListItem[] items
|
||||
}
|
||||
Item .. ListItem
|
||||
List *-- ListItem
|
||||
class ListItem {
|
||||
+int position
|
||||
+Item item
|
||||
+Comment comment
|
||||
+Dict metadata
|
||||
}
|
||||
List <|-- Collection
|
||||
List <|-- Collection
|
||||
Item .. Collection
|
||||
class Collection {
|
||||
+str title
|
||||
+str brief
|
||||
+Bool collabrative
|
||||
}
|
||||
List <|-- Tag
|
||||
List <|-- Tag
|
||||
class Tag {
|
||||
+str title
|
||||
}
|
||||
List <|-- Shelf
|
||||
List <|-- Shelf
|
||||
class Shelf {
|
||||
+Enum type
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ def _movie_tv_convert(entity):
|
|||
'duration': entity.duration,
|
||||
'season_count': entity.other_info.get('Seasons') if entity.other_info else None,
|
||||
'season_number': entity.season,
|
||||
'episodes': entity.episodes,
|
||||
'episode_count': entity.episodes,
|
||||
'single_episode_length': entity.single_episode_length,
|
||||
'is_series': entity.is_series,
|
||||
})
|
||||
|
@ -185,11 +185,11 @@ class Command(BaseCommand):
|
|||
item = None
|
||||
if site:
|
||||
if not site.DEFAULT_MODEL and not content.metadata.get('preferred_model'):
|
||||
if model_map[typ] != Movie or not content.metadata.get('is_series'):
|
||||
if model_map[typ] == Movie and entity.is_series:
|
||||
content.metadata['preferred_model'] = 'TVSeason' if entity.season else 'TVShow'
|
||||
else:
|
||||
content.metadata['preferred_model'] = model_map[typ].__name__
|
||||
else: # TV
|
||||
content.metadata['preferred_model'] = 'TVSeason' if content.metadata.get('season') else 'TVShow'
|
||||
item = site.get_resource_ready(preloaded_content=content, reload=reload).item
|
||||
item = site.get_resource_ready(preloaded_content=content, ignore_existing_content=reload).item
|
||||
else:
|
||||
# not known site, try save item without external resource
|
||||
item = None
|
||||
|
|
Loading…
Add table
Reference in a new issue