import json from datetime import datetime from pathlib import Path from typing import Optional, List from sqlalchemy import Column, Integer, String, Boolean, JSON, Date, ARRAY, ForeignKey, Computed from sqlalchemy.orm import relationship, Session from sqlalchemy.orm.collections import InstrumentedList from wrolpi.common import Base, tsvector, ModelHelper, logger from wrolpi.dates import now, TZDateTime from wrolpi.db import get_db_curs from wrolpi.downloader import Download from wrolpi.errors import UnknownVideo, UnknownFile, UnknownDirectory from wrolpi.media_path import MediaPathType, MediaPath logger = logger.getChild(__name__) class Video(ModelHelper, Base): __tablename__ = 'video' id = Column(Integer, primary_key=True) channel_id = Column(Integer, ForeignKey('channel.id')) channel = relationship('Channel', primaryjoin='Video.channel_id==Channel.id', back_populates='videos') idempotency = Column(String) # File paths caption_path = Column(MediaPathType) description_path = Column(MediaPathType) ext = Column(String) info_json_path = Column(MediaPathType) poster_path = Column(MediaPathType) video_path = Column(MediaPathType) caption = Column(String) duration = Column(Integer) favorite = Column(TZDateTime) size = Column(Integer) source_id = Column(String) title = Column(String) upload_date = Column(TZDateTime) validated_poster = Column(Boolean, default=False) viewed = Column(TZDateTime) view_count = Column(Integer) url = Column(String) textsearch = Column(tsvector, Computed('''to_tsvector('english'::regconfig, ((COALESCE(title, ''::text) || ' '::text) || COALESCE(caption, ''::text)))''')) def __repr__(self): return f'