Skip to content
Snippets Groups Projects
Commit fc812c4e authored by Simon Künzel's avatar Simon Künzel
Browse files

Add more fields to target media

parent 55260ba9
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,21 @@ class SourceMedium(DeletableApiObject, Base): ...@@ -67,6 +67,21 @@ class SourceMedium(DeletableApiObject, Base):
data_notes="Only calculated once this is sorted" data_notes="Only calculated once this is sorted"
) )
) )
file_size: Mapped[int] = api_mapped(
mapped_column(sql.types.BigInteger, nullable=True),
ApiIntegerField(
include_in_data=True,
data_notes="Only calculated once this is sorted"
)
)
metadata: Mapped[JsonTypes] = api_mapped(
mapped_column(sql.JSON, nullable=True),
ApiDataField(
include_in_data=True,
# See source file sorter for contents
data_notes="Only calculated once this is sorted. There are no guarantees regarding the content"
)
)
tag: Mapped[str] = mapped_column(String(collation=STRING_COLLATION), nullable=True) tag: Mapped[str] = mapped_column(String(collation=STRING_COLLATION), nullable=True)
lecture: Mapped[Lecture] = relationship( lecture: Mapped[Lecture] = relationship(
...@@ -105,7 +120,6 @@ class TargetMedium(DeletableApiObject, Base): ...@@ -105,7 +120,6 @@ class TargetMedium(DeletableApiObject, Base):
producer_job_id: Mapped[int] = mapped_column(ForeignKey("job.id"), nullable=True) producer_job_id: Mapped[int] = mapped_column(ForeignKey("job.id"), nullable=True)
is_produced: Mapped[bool] = mapped_column(nullable=False, default=False) is_produced: Mapped[bool] = mapped_column(nullable=False, default=False)
to_be_replaced: Mapped[bool] = mapped_column(nullable=False, default=False) to_be_replaced: Mapped[bool] = mapped_column(nullable=False, default=False)
file_path: Mapped[str] = mapped_column(String(collation=STRING_COLLATION), nullable=True, index=True) # TODO move?
type: Mapped[TargetMediumType] = api_mapped( type: Mapped[TargetMediumType] = api_mapped(
mapped_column(_TARGET_MEDIUM_TYPE_ENUM, nullable=False), mapped_column(_TARGET_MEDIUM_TYPE_ENUM, nullable=False),
ApiEnumField( ApiEnumField(
...@@ -127,19 +141,6 @@ class TargetMedium(DeletableApiObject, Base): ...@@ -127,19 +141,6 @@ class TargetMedium(DeletableApiObject, Base):
lazy="raise_on_sql" lazy="raise_on_sql"
) )
@api_include_in_data(
type_id="string",
data_notes="URL to the mediums's file (Maybe with a redirect)"
)
def url(self) -> str:
# This is not too nice and only works from the API, but we need to access the API config
import api
return f"{api.config['API_BASE_URL']}/resources/target_medium/{self.id}"
def get_default_file_path_no_ending(self):
# TODO path
return f"{self.process_target_id}.{self.id}"
@hybrid_method @hybrid_method
def is_active(self, usable_check: bool = True, from_lecture: bool = False, from_publish_medium: bool = False, **kwargs): def is_active(self, usable_check: bool = True, from_lecture: bool = False, from_publish_medium: bool = False, **kwargs):
cond = super().is_active(**kwargs) cond = super().is_active(**kwargs)
...@@ -194,32 +195,61 @@ class TargetMedium(DeletableApiObject, Base): ...@@ -194,32 +195,61 @@ class TargetMedium(DeletableApiObject, Base):
return options return options
# Note that this usually also includes audio class FileTargetMedium(TargetMedium):
class PlainVideoTargetMedium(TargetMedium): file_path: Mapped[str] = mapped_column(String(collation=STRING_COLLATION), nullable=True, index=True) # TODO move?
__tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance
__mapper_args__ = { @api_include_in_data(
"polymorphic_identity": TargetMediumType.PLAIN_VIDEO type_id="string",
} data_notes="URL to the mediums's file (Maybe with a redirect)"
)
def url(self) -> str:
# This is not too nice and only works from the API, but we need to access the API config
import api
return f"{api.config['API_BASE_URL']}/resources/target_medium/{self.id}"
vertical_resolution: Mapped[int] = api_mapped( def get_default_file_path_no_ending(self):
# TODO path
return f"{self.process_target_id}.{self.id}"
class SingleAudioContainingMedium(TargetMedium):
audio_sample_rate: Mapped[int] = api_mapped(
mapped_column(nullable=True),
ApiIntegerField(
include_in_data=True,
help="In Hz"
)
)
audio_channel_count: Mapped[int] = api_mapped(
mapped_column(nullable=True),
ApiIntegerField(
include_in_data=True
)
)
class SingleVideoContainingMedium(TargetMedium):
video_vertical_resolution: Mapped[int] = api_mapped(
mapped_column(nullable=True), mapped_column(nullable=True),
ApiIntegerField( ApiIntegerField(
include_in_data=True include_in_data=True
) )
) )
horizontal_resolution: Mapped[int] = api_mapped( video_horizontal_resolution: Mapped[int] = api_mapped(
mapped_column(nullable=True), mapped_column(nullable=True),
ApiIntegerField( ApiIntegerField(
include_in_data=True include_in_data=True
) )
) )
frame_rate_numerator: Mapped[int] = api_mapped( video_frame_rate_numerator: Mapped[int] = api_mapped(
mapped_column(nullable=True), mapped_column(nullable=True),
ApiIntegerField( ApiIntegerField(
include_in_data=True include_in_data=True
) )
) )
frame_rate_denominator: Mapped[int] = api_mapped( video_frame_rate_denominator: Mapped[int] = api_mapped(
mapped_column(nullable=True), mapped_column(nullable=True),
ApiIntegerField( ApiIntegerField(
include_in_data=True include_in_data=True
...@@ -227,14 +257,36 @@ class PlainVideoTargetMedium(TargetMedium): ...@@ -227,14 +257,36 @@ class PlainVideoTargetMedium(TargetMedium):
) )
class PlainAudioTargetMedium(TargetMedium): class PlainVideoTargetMedium(FileTargetMedium, SingleVideoContainingMedium, SingleAudioContainingMedium):
__tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance
__mapper_args__ = {
"polymorphic_identity": TargetMediumType.PLAIN_VIDEO
}
duration_sec: Mapped[int] = api_mapped(
mapped_column(nullable=True),
ApiIntegerField(
include_in_data=True
)
)
# TODO check vars not null (except audio)
class PlainAudioTargetMedium(FileTargetMedium, SingleAudioContainingMedium):
__tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance __tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance
__mapper_args__ = { __mapper_args__ = {
"polymorphic_identity": TargetMediumType.PLAIN_AUDIO "polymorphic_identity": TargetMediumType.PLAIN_AUDIO
} }
duration_sec: Mapped[int] = api_mapped(
mapped_column(nullable=True),
ApiIntegerField(
include_in_data=True
)
)
class ThumbnailTargetMedium(TargetMedium): class ThumbnailTargetMedium(FileTargetMedium):
__tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance __tablename__ = None # Prevent our own base from adding a table name. This should be a single-table inheritance
__mapper_args__ = { __mapper_args__ = {
"polymorphic_identity": TargetMediumType.THUMBNAIL "polymorphic_identity": TargetMediumType.THUMBNAIL
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment