2e8a8e95772e_add_video_file_table.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Albireo 作者: lordfriend 项目源码 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    video_file_table = op.create_table('video_file',
                                       sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
                                       sa.Column('bangumi_id', postgresql.UUID(as_uuid=True), nullable=False),
                                       sa.Column('episode_id', postgresql.UUID(as_uuid=True), nullable=False),
                                       sa.Column('file_name', sa.String(), nullable=True),
                                       sa.Column('file_path', sa.String(), nullable=True),
                                       sa.Column('torrent_id', sa.String(), nullable=True),
                                       sa.Column('download_url', sa.String(), nullable=True),
                                       sa.Column('status', sa.Integer(), nullable=False),
                                       sa.Column('resolution_w', sa.Integer(), nullable=True),
                                       sa.Column('resolution_h', sa.Integer(), nullable=True),
                                       sa.Column('duration', sa.Integer(), nullable=True),
                                       sa.Column('label', sa.String(), nullable=True),
                                       sa.ForeignKeyConstraint(['bangumi_id'], ['bangumi.id'], ),
                                       sa.ForeignKeyConstraint(['episode_id'], ['episodes.id'], ),
                                       sa.PrimaryKeyConstraint('id')
                                       )
    # ### end Alembic commands ###

    connection = op.get_bind()
    result = connection.execute(sa.text(
        'SELECT t.episode_id, t.torrent_id, t.file_path, eps.bangumi_id, eps.episode_no FROM torrentfile t LEFT JOIN episodes eps ON eps.id = t.episode_id WHERE file_path NOTNULL'))
    video_file_list = []
    for row in result:
        video_file = {
            'id': uuid4(),
            'status': 3
        }
        if row[1] == -1 or __is_uuid4(row[1]):
            video_file['torrent_id'] = None
        else:
            video_file['torrent_id'] = row[1]
        video_file['episode_id'] = row[0]
        video_file['file_path'] = row[2]
        video_file['bangumi_id'] = row[3]

        meta_info = video_manager.get_video_meta(
            u'{0}/{1}/{2}'.format(get_base_path(), str(video_file['bangumi_id']), video_file['file_path']))

        if meta_info is None:
            continue

        video_file['resolution_w'] = meta_info.get('width')
        video_file['resolution_h'] = meta_info.get('height')
        video_file['duration'] = meta_info.get('duration')

        video_file_list.append(video_file)

    op.bulk_insert(video_file_table, video_file_list)

    connection.execute(sa.text('UPDATE episodes SET status = 0 WHERE status = 1'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号