Esempio n. 1
0
 def __update_video_meta(self, video_file):
     meta = video_manager.get_video_meta(u'{0}/{1}/{2}'.format(
         self.base_path, str(video_file.bangumi_id), video_file.file_path))
     if meta is not None:
         video_file.duration = meta.get('duration')
         video_file.resolution_w = meta.get('width')
         video_file.resolution_h = meta.get('height')
Esempio n. 2
0
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'))
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'))
Esempio n. 4
0
 def update_video_meta(video_file):
     meta = video_manager.get_video_meta(u'{0}/{1}/{2}'.format(self.base_path, str(video_file.bangumi_id), video_file.file_path))
     if meta is not None:
         video_file.duration = meta.get('duration')
         video_file.resolution_w = meta.get('width')
         video_file.resolution_h = meta.get('height')