App::510::functions
DESCRIPTION
Functions to handle basic actions with videos.
DEPENDS
-
File::Path
-
Digest::MD5
-
Digest::SHA1
-
File::Type
-
Movie::Info
FUNCTIONS
video_part_file_generate()
video_part_file_generate ( 'video.ID_entity' => '' # related video.ID_entity 'video_format.ID' => '' # related video_format.ID #'video_format.name' => '' # realted video_format.name )
video_add()
Adds new video to gallery, or updates old video
Add new video (uploading new original sized video)
%video=video_add ( 'file' => '/path/to/file', # 'video.ID' => '', # 'video.ID_entity' => '', # 'video_en.keywords' => '', # 'video_format.ID' => '', # 'video_attrs.ID_category' => '', # 'video_attrs.name' => '', # 'video_attrs.description' => '', # 'video_part.ID' => '', # 'video_part.keywords' => '', # 'video_part.part_id' => '', # 'video_part_attrs.ID_category' => '', # 'video_part_attrs.name' => '', # 'video_part_attrs.description' => '', );
Add new part of video
video_add ( 'file' => '/path/to/file', 'video.ID' => 2, #'video_part.ID' => 1, #'video_part.order_id' => 1, );
if ($env{'video_attrs.ID_category'} && $env{'video.ID_entity'} && $env{'video_attrs.lng'} && !$env{'video_attrs.ID'} && !$env{'video.ID'} && $env{'forcesymlink'}) { main::_log("finding compatible video_attrs.ID_entity (also video.ID)");
my $sql=qq{
SELECT
video.ID AS ID_video,
video_attrs.ID AS ID_attrs
FROM
`$App::510::db_name`.a510_video AS video
LEFT JOIN `$App::510::db_name`.a510_video_attrs AS video_attrs
ON ( video.ID = video_attrs.ID_entity )
WHERE
video.ID_entity=$env{'video.ID_entity'} AND
video_attrs.ID_category = $env{'video_attrs.ID_category'} AND
video_attrs.lng != '$env{'video_attrs.lng'}' AND
video_attrs.status IN ('Y','N','L')
LIMIT 1
};
my %sth0=TOM::Database::SQL::execute($sql,'quiet'=>1);
my %db0_line=$sth0{'sth'}->fetchhash();
if ($db0_line{'ID_video'})
{
$env{'video.ID'}=$db0_line{'ID_video'};
$env{'video_attrs.ID'}=$db0_line{'ID_attrs'};
main::_log("setup video.ID='$db0_line{'ID_video'}' video_attrs.ID='$env{'video_attrs.ID'}'");
}
}
=cut
# check if this lng mutation of video_attrs exists if ($env{'video_attrs.ID'} && $env{'video_attrs.lng'} && $env{'video.ID'}) { main::_log("check if lng='$env{'video_attrs.lng'}' of video.ID='$env{'video.ID'}' exists"); my $sql=qq{ SELECT ID FROM `$App::510::db_name`.a510_video_attrs WHERE ID_entity=? AND lng=? LIMIT 1 }; my %sth0=TOM::Database::SQL::execute($sql,'bind'=>[$env{'video.ID'},$env{'video_attrs.lng'}],'quiet'=>1); if (!$sth0{'rows'}) { main::_log("not exists, also reset video_attrs.ID"); undef $env{'video_attrs.ID'}; } else {
}
# if not remove video_attrs.ID
}
=cut
if (!$env{'video.ID'})
{
# generating new video!
main::_log("adding new video");
my %columns;
$columns{'datetime_rec_start'}="NOW()";
$columns{'ID_entity'}=$env{'video.ID_entity'} if $env{'video.ID_entity'};
$env{'video.ID'}=App::020::SQL::functions::new(
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video",
'columns' =>
{
%columns,
},
'-journalize' => 1,
);
main::_log("generated video.ID='$env{'video.ID'}'");
$content_updated=1;
}
if (!$env{'video.ID_entity'})
{
if ($video{'ID_entity'})
{
$env{'video.ID_entity'}=$video{'ID_entity'};
}
elsif ($env{'video.ID'})
{
%video=App::020::SQL::functions::get_ID(
'ID' => $env{'video.ID'},
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video",
'columns' => {'*'=>1}
);
$env{'video.ID_entity'}=$video{'ID_entity'};
}
else
{
die "ufff\n";
}
}
# update if necessary
if ($video{'ID'})
{
my %columns;
# datetime_rec_start
$columns{'datetime_rec_start'}="'".$env{'video.datetime_rec_start'}."'"
if ($env{'video.datetime_rec_start'} && ($env{'video.datetime_rec_start'} ne $video{'datetime_rec_start'}));
$columns{'datetime_rec_start'}=$env{'video.datetime_rec_start'}
if ($env{'video.datetime_rec_start'}=~/^FROM/ && ($env{'video.datetime_rec_start'} ne $video{'datetime_rec_start'}));
# datetime_rec_stop
if (exists $env{'video.datetime_rec_stop'} && ($env{'video.datetime_rec_stop'} ne $video{'datetime_rec_stop'}))
{
if (!$env{'video.datetime_rec_stop'})
{$columns{'datetime_rec_stop'}="NULL";}
else
{$columns{'datetime_rec_stop'}="'".$env{'video.datetime_rec_stop'}."'";}
}
if (keys %columns)
{
App::020::SQL::functions::update(
'ID' => $video{'ID'},
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video",
'columns' => {%columns},
'-journalize' => 1
);
$content_updated=1;
}
}
if (!$env{'video_attrs.ID'})
{
main::_log("finding video_attrs.ID by video.ID=$env{'video.ID'} and video_attrs.lng='$env{'video_attrs.lng'}'");
my $sql=qq{
SELECT
*
FROM
`$App::510::db_name`.`a510_video_attrs`
WHERE
ID_entity='$env{'video.ID'}' AND
lng='$env{'video_attrs.lng'}'
LIMIT 1
};
my %sth0=TOM::Database::SQL::execute($sql,'quiet'=>1);
%video_attrs=$sth0{'sth'}->fetchhash();
$env{'video_attrs.ID'}=$video_attrs{'ID'};
main::_log("video_attrs.ID='$env{'video_attrs.ID'}'");
}
if (!$env{'video_attrs.ID'} && !$env{'video_attrs.ID_category'} && $env{'video.ID'})
{ # find target ID_category if not defined
main::_log("finding video_attrs.ID_category by video.ID=$env{'video.ID'}");
my $sql=qq{
SELECT
ID_category
FROM
`$App::510::db_name`.`a510_video_attrs`
WHERE
ID_entity='$env{'video.ID'}' AND
status IN ('Y','N','L')
LIMIT 1
};
my %sth0=TOM::Database::SQL::execute($sql,'quiet'=>1);
my %db0_line=$sth0{'sth'}->fetchhash();
$env{'video_attrs.ID_category'}=$db0_line{'ID_category'};# if $sth0{'rows'};
main::_log("video_attrs.ID_category='$env{'video_attrs.ID_category'}'");
}
if (!$env{'video_attrs.ID'})
{
# create one language representation of video
my %columns;
$columns{'ID_category'}=$env{'video_attrs.ID_category'} if $env{'video_attrs.ID_category'};
#$columns{'status'}="'$env{'video_attrs.status'}'" if $env{'video_attrs.status'};
$env{'video_attrs.ID'}=App::020::SQL::functions::new(
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video_attrs",
'columns' =>
{
%columns,
'ID_entity' => $env{'video.ID'},
# 'order_id' => $order_id,
'lng' => "'$env{'video_attrs.lng'}'",
},
'-journalize' => 1,
);
# %video_attrs=App::020::SQL::functions::get_ID(
# 'ID' => $env{'video_attrs.ID'},
# 'db_h' => "main",
# 'db_name' => $App::510::db_name,
# 'tb_name' => "a510_video_attrs",
# 'columns' => {'*'=>1}
# );
$content_updated=1;
}
# VIDEO_ENT
my %video_ent;
if (!$env{'video_ent.ID_entity'})
{
my $sql=qq{
SELECT
*
FROM
`$App::510::db_name`.`a510_video_ent`
WHERE
ID_entity='$env{'video.ID_entity'}'
LIMIT 1
};
my %sth0=TOM::Database::SQL::execute($sql,'quiet'=>1);
%video_ent=$sth0{'sth'}->fetchhash();
$env{'video_ent.ID_entity'}=$video_ent{'ID_entity'};
$env{'video_ent.ID'}=$video_ent{'ID'};
}
if (!$env{'video_ent.ID_entity'})
{
# create one entity representation of video
my %columns;
$columns{'datetime_rec_start'}="NOW()" unless $columns{'datetime_rec_start'};
$env{'video_ent.ID'}=App::020::SQL::functions::new(
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video_ent",
'columns' =>
{
%columns,
'ID_entity' => $env{'video.ID_entity'},
},
'-journalize' => 1,
);
$content_updated=1;
}
if (!$video_ent{'posix_owner'} && !$env{'video_ent.posix_owner'})
{
$env{'video_ent.posix_owner'}=$main::USRM{'ID_user'};
}
# update if necessary
if ($env{'video_ent.ID'})
{
my %columns;
$columns{'posix_author'}="'".$env{'video_ent.posix_author'}."'"
if ($env{'video_ent.posix_author'} && ($env{'video_ent.posix_author'} ne $video_ent{'posix_author'}));
$columns{'posix_owner'}="'".TOM::Security::form::sql_escape($env{'video_ent.posix_owner'})."'"
if ($env{'video_ent.posix_owner'} && ($env{'video_ent.posix_owner'} ne $video_ent{'posix_owner'}));
$columns{'keywords'}="'".TOM::Security::form::sql_escape($env{'video_ent.keywords'})."'"
if (exists $env{'video_ent.keywords'} && ($env{'video_ent.keywords'} ne $video_ent{'keywords'}));
$columns{'movie_release_year'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_release_year'})."'"
if (exists $env{'video_ent.movie_release_year'} && ($env{'video_ent.movie_release_year'} ne $video_ent{'movie_release_year'}));
$columns{'movie_release_date'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_release_date'})."'"
if (exists $env{'video_ent.movie_release_date'} && ($env{'video_ent.movie_release_date'} ne $video_ent{'movie_release_date'}));
$columns{'movie_country_code'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_country_code'})."'"
if (exists $env{'video_ent.movie_country_code'} && ($env{'video_ent.movie_country_code'} ne $video_ent{'movie_country_code'}));
$columns{'movie_imdb'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_imdb'})."'"
if (exists $env{'video_ent.movie_imdb'} && ($env{'video_ent.movie_imdb'} ne $video_ent{'movie_imdb'}));
$columns{'movie_catalog_number'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_catalog_number'})."'"
if (exists $env{'video_ent.movie_catalog_number'} && ($env{'video_ent.movie_catalog_number'} ne $video_ent{'movie_catalog_number'}));
$columns{'movie_length'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_length'})."'"
if (exists $env{'video_ent.movie_length'} && ($env{'video_ent.movie_length'} ne $video_ent{'movie_length'}));
$columns{'movie_note'}="'".TOM::Security::form::sql_escape($env{'video_ent.movie_note'})."'"
if (exists $env{'video_ent.movie_note'} && ($env{'video_ent.movie_note'} ne $video_ent{'movie_note'}));
if ((not exists $env{'video_ent.metadata'}) && (!$video_ent{'metadata'})){$env{'video_ent.metadata'}=$App::510::metadata_default;}
$columns{'metadata'}="'".TOM::Security::form::sql_escape($env{'video_ent.metadata'})."'"
if (exists $env{'video_ent.metadata'} && ($env{'video_ent.metadata'} ne $video_ent{'metadata'}));
if ($columns{'metadata'})
{
App::020::functions::metadata::metaindex_set(
'db_h' => 'main',
'db_name' => $App::510::db_name,
'tb_name' => 'a510_video_ent',
'ID' => $env{'video_ent.ID'},
'metadata' => {App::020::functions::metadata::parse($env{'video_ent.metadata'})}
);
}
if (keys %columns)
{
App::020::SQL::functions::update(
'ID' => $env{'video_ent.ID'},
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video_ent",
'columns' => {%columns},
'-journalize' => 1
);
$content_updated=1;
}
}
my %env0=video_part_add
(
'file' => $env{'file'},
'file_nocopy' => $env{'file_nocopy'},
'file_thumbnail' => $env{'file_thumbnail'},
'file_dontcheck' => $env{'file_dontcheck'},
'video.ID_entity' => $env{'video.ID_entity'},
'video.datetime_rec_start' => $video{'datetime_rec_start'},
'video_attrs.name' => $video_attrs{'name'},
'video_format.ID' => $env{'video_format.ID'},
'video_part.ID' => $env{'video_part.ID'},
'video_part.keywords' => $env{'video_part.keywords'},
'video_part.part_id' => $env{'video_part.part_id'},
'video_part_attrs.lng' => $env{'video_attrs.lng'},
'video_part_attrs.name' => $env{'video_part_attrs.name'},
'video_part_attrs.description' => $env{'video_part_attrs.description'},
);
$env{'video_part.ID'} = $env0{'video_part.ID'} if $env0{'video_part.ID'};
if (!$env{'video_part.ID'})
{
$t->close();
return undef
};
if ($env{'video_attrs.ID'})
{
# detect language
%video_attrs=App::020::SQL::functions::get_ID(
'ID' => $env{'video_attrs.ID'},
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video_attrs",
'columns' => {'*'=>1}
);
main::_log("loaded %video_attrs video_attrs.ID='$video_attrs{'ID'}' video_attrs.ID_category='$video_attrs{'ID_category'}'");
}
main::_log("video_attrs.ID='$env{'video_attrs.ID'}' video_attrs.ID_category='$env{'video_attrs.ID_category'}' video_attrs{ID_category}='$video_attrs{'ID_category'}'");
if ($env{'video_attrs.ID'} &&
(
# ID_category
($env{'video_attrs.ID_category'} && ($env{'video_attrs.ID_category'} ne $video_attrs{'ID_category'}))
))
{
my %columns;
main::_log("video_attrs.ID='$video_attrs{'ID'}' video_attrs.status='$video_attrs{'status'}'");
$columns{'ID_category'}=$env{'video_attrs.ID_category'};
my $sql=qq{
SELECT
ID
FROM
`$App::510::db_name`.a510_video_attrs
WHERE
ID_entity=$video_attrs{'ID_entity'} AND
status IN ('Y','N','L')
};
my %sth0=TOM::Database::SQL::execute($sql,'quiet'=>1);
while (my %db0_line=$sth0{'sth'}->fetchhash())
{
# main::_log("update video_attrs.ID='$db0_line{'ID'}'");
App::020::SQL::functions::update(
'ID' => $db0_line{'ID'},
'db_h' => "main",
'db_name' => $App::501::db_name,
'tb_name' => "a510_video_attrs",
'columns' => {%columns},
'-journalize' => 1
);
$content_updated=1;
}
}
# MUST be rewrited - update only if necessary
if ($env{'video_attrs.ID'})
{
my %columns;
# $columns{'ID_category'}=$env{'video_attrs.ID_category'} # if ($env{'video_attrs.ID_category'} && ($env{'video_attrs.ID_category'} ne $video_attrs{'ID_category'})); $columns{'name'}="'".TOM::Security::form::sql_escape($env{'video_attrs.name'})."'" if ($env{'video_attrs.name'} && ($env{'video_attrs.name'} ne $video_attrs{'name'})); $columns{'name_url'}="'".TOM::Net::URI::rewrite::convert($env{'video_attrs.name'})."'" if ($env{'video_attrs.name'} && ($env{'video_attrs.name'} ne $video_attrs{'name'})); $columns{'description'}="'".TOM::Security::form::sql_escape($env{'video_attrs.description'})."'" if (exists $env{'video_attrs.description'} && ($env{'video_attrs.description'} ne $video_attrs{'description'})); $columns{'status'}="'".TOM::Security::form::sql_escape($env{'video_attrs.status'})."'" if ($env{'video_attrs.status'} && ($env{'video_attrs.status'} ne $video_attrs{'status'}));
if (keys %columns)
{
App::020::SQL::functions::update(
'ID' => $env{'video_attrs.ID'},
'db_h' => "main",
'db_name' => $App::510::db_name,
'tb_name' => "a510_video_attrs",
'columns' => {%columns},
'-journalize' => 1
);
$content_updated=1;
}
}
main::_log("video.ID='$env{'video.ID'}' added/updated");
if ($content_updated)
{
App::020::SQL::functions::_save_changetime({'db_h'=>'main','db_name'=>$App::510::db_name,'tb_name'=>'a510_video'});
}
$tr->close(); # commit transaction
$t->close();
return %env;
}
video_part_add()
Adds new video-part to gallery, or updates old video
Add new video-part (uploading new original sized video)
video_part_add ( 'file' => '/path/to/file', 'video.ID_entity' => '', # 'video_part_attrs.lng' => 'en', # 'video.ID_entity' => '', # 'video_format.ID' => '', # 'video_attrs.ID_category' => '', # 'video_attrs.name' => '', # 'video_attrs.description' => '', # 'video_part.ID' => '', # 'video_part.keywords' => '', # 'video_part.part_id' => '', # 'video_part_attrs.ID_category' => '', # 'video_part_attrs.name' => '', # 'video_part_attrs.description' => '', );
video_part_file_add()
Adds new file to video, or updates old
$video_part_file{'ID'}=video_part_file_add
(
'file' => '/path/to/file',
'video_part.ID' => '',
'video_format.ID' => '',
# 'thumbnail_lock_ignore' => 1 # regenerate thumbnail when locked
)
video_part_file_newhash()
Find new unique hash for file
video_part_visit()
Increase number of video_part visits
get_video_part_file()
Return video_part_file columns. This is the fastest way (optimized SQL) to get informations about file in video_part. Informations are cached in memcached and cache is monitored by information of last change of a510_video.
my %video_part_file=get_video_part_file(
'video.ID_entity' => 1 or 'video_part.ID' = > 1
'video_part.part_id' => 1 # default for video.ID_entity
'video_part_file.ID_format' => 1 # default
'video_attrs.lng' => $tom::lng # default
''
)
get_video_part_file_process_front()
Returns front of video_part_file's to process by encoder.
foreach my $video_part_file=(get_video_part_file_process_front(
'limit' => 10
);
AUTHORS
Comsultia, Ltd. (open@comsultia.com)
User Comments