Gossamer Forum
Quote Reply
AutoValidation
Hi there,

I have a Links installation to which users upload their videos.
When they have uploaded their videos, it sits in the database and waits to be validated.
After it is validated, a plugin converts it to flash format and it is ready to go.

I have to find a way to auto validate the videos. I have tried to use isValidated, which
works, but it skips the PRE and POST validation, and since the convertion is done there,
it isn't really helpfull.

So I went and toyed a bit with 'tools_validate.html', but I'd rather not say like what it looked llike.

If anyone can help me or point me in the right direction, please do Smile

Thanks


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] AutoValidation In reply to
Hi,

Not sure editing tools_validate.html will do what you want =)

I'm a bit confused as to how you have it working. You say the conversion is done when SOMEONE validates the link?

Is it an existing plugin, or one you've written to do this?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] AutoValidation In reply to
Yes, it is done when someone validates the link. It is to save space on the server. No use for a flash file that is linked to a bad link :)
And luckily I didn't write the plugin. My condolences with the one who did. The code in that plugin is just nasty.
I thought I might simulate the command the 'tools.validate.html' uses to validate links, with a plugin.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] AutoValidation In reply to
Hi,

I'm still confused as to what you are trying to do though? :/

If the plugin converts them ok - why do you want to do it?

Quote:
The code in that plugin is just nasty.

Nasty, or just confusing? Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] AutoValidation In reply to
Sorry, I have not been very clear

The converter is working. there is nothing wrong with it.

I am trying to write a plugin that auto Validates links the users submitted.
For links like photos and reviews, the plugin works fine. Also for the videos,
in theory.

I do it by setting 'isValidated' = 'Yes'.

But, when the video link is validated the 'validate_link','PRE' event is fired. Right?
Now, in the converter's plugin there is a hook that hooks to this event.
And it is the one that converts the video to flash. The down side is
if I just set 'isValidated' = 'Yes', it is not firing the 'validate_link','PRE' event.

For the photos and reviews everything is fine, because they don't have any hooks on the
'validate_link','PRE' event. But for the videos it is critical. That is why I asked if there is a whay
to call one plugin's functions from another. But apparently that doesn't work. I can't get the
parameters passed correctly. I get that 'Can't use string 'blablathingy' as hasref while 'strictsomething' is.......'.
I can't remember the rest of it.

And yes, that code is very confusing Smile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] AutoValidation In reply to
Hi,

Quote:
For the photos and reviews everything is fine, because they don't have any hooks on the
'validate_link','PRE' event. But for the videos it is critical. That is why I asked if there is a whay
to call one plugin's functions from another. But apparently that doesn't work. I can't get the
parameters passed correctly. I get that 'Can't use string 'blablathingy' as hasref while 'strictsomething' is.......'.
I can't remember the rest of it.

I think the best way, would be to re-write a "copy" of the function you are trying to call - and then edit it so it uses only the paramaters you pass in.

I expect in the function you were trying to use - it has:

my $opts = shift;

..or similar?

..and I guess your trying to pass in function_name(string) , which would be where the Can't use string 'blablathingy' as hasref while 'stricts error code :)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] AutoValidation In reply to
Here is the code that converts the video

Code:
sub validate_link_pre {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'validate_link'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my ($link) = @_;
$link = convert_video($link);
return $link;
}
sub convert_video {
# -------------------------------------------------------------------
my $link = shift;
my $linksdb = $DB->table('Links');
my $cfg = Links::Plugins::get_plugin_user_cfg('ConvertVideo');
my $vf_field = $cfg->{video_file_field};
my $ff_field = $cfg->{flash_file_field};
my $thumb = $cfg->{thumbnail_file_field};
# return if no video file uploaded
my $fh = $linksdb->file_info( $vf_field, $link->{ID} ) or return $link;
my $full_path = "$fh";
# get the mpeg filename
my $filename = $full_path;
$filename =~ s/(.+)\/\d+-([^\/]+)\.$/$2/g;
# get the info from the movie file
my ($swidth, $sheight, $bitrate) = get_mov_info($full_path);
my $size_cmd = generate_dimensions($swidth,$sheight);
# set the flash filename
my $flvfile = $CFG->{admin_root_path} . "/tmp/" . $link->{ID} . ".flv";
# convert mpeg file to flash file and put it to field "flv_file"
my $mpeg_cmd = "ffmpeg -y -i $full_path";
if ($size_cmd) {
$mpeg_cmd .= $size_cmd;
}
$mpeg_cmd .= " -ar 22050 -ab 64 -ac 2 -r 15";
if ($cfg->{flash_quality}) {
$mpeg_cmd .= " -b " . $cfg->{flash_quality};
}
if ($cfg->{watermark_file} and -f $cfg->{watermark_file} and -s $cfg->{watermark_file}) {
$mpeg_cmd .= " -vhook '/usr/lib/vhook/watermark.so -f $cfg->{watermark_file}'";
}
$mpeg_cmd .= " $flvfile";
my $res = system "$mpeg_cmd";
if ($res == 0) {
$link->{$ff_field} = GT::SQL::File->open($flvfile);
#unlink $flvfile;
}
# capture the thumbnail picture at the 10th second frame
if (!$link->{$thumb}) {
my $output_fpath = generate_thumbnail($full_path,"$link->{$vf_field}");
if (ref $output_fpath eq 'HASH') {
}
else {
# print "** output_fpath: $output_fpath\n";
$link->{$thumb} = GT::SQL::File->open($output_fpath);
}
}
=tag
my $thumbnail = $CFG->{admin_root_path} . "/tmp/thumbnail-" . $link->{ID} . ".png";
my $thumb_cmd = "ffmpeg -y -i $full_path -vframes 1 -ss ";
$thumb_cmd .= $cfg->{thumbnail_frame_second} =~ /^\d\d\:\d\d\:\d\d$/ ? $cfg->{thumbnail_frame_second} : "00:00:10";
$thumb_cmd .= " -an -vcodec png -f rawvideo -s ";
$thumb_cmd .= $cfg->{thumbnail_size} ? $cfg->{thumbnail_size} : "80x80";
$thumb_cmd .= " $thumbnail";
my $res2 = system "$thumb_cmd";
if ($res2 == 0) {
$link->{$thumb} = GT::SQL::File->open($thumbnail);
unlink $thumbnail;
}
=cut

return $link;
}


And here is the code in my plugin to call the convert_video function.

Code:

sub post_add_link {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'add_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'add_link' code to run, otherwise the code will continue as normal.
#
my ($link) = @_;



my $results = shift;
if($results->{Review_Validated} == "Yes")
{
$link = Plugins::ConvertVideo::convert_video($link);
}
return $link;
}

Quite honestly, I really don't know the defference between @this and $this or shift and @_.
Or even what it is.
But I'm always open to learn Smile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] AutoValidation In reply to
Hi,

Ok, that doesn't look too complex =)

Bit confused as to why you're using this field though?

if($results->{Review_Validated} == "Yes") {


If its being done after someone ADDS a link, and you want to pass it through to the converter right away, something like this should work:
Code:
sub post_add_link {

# get the highest ID in glinks_Links, as this will be the latest one added
my $max_id = $DB->table('Links')->select( ['MAX(ID)'] )->fetchrow;

# get the link of $max_id, as a hashref
my $link = $DB->table('Links')->select( { ID => $max_id } )->fetchrow_hashref;

# now just pass to the converter, and let it do its work =)
use Plugins::ConvertVideo;
Plugins::ConvertVideo::convert_video($link);

}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] AutoValidation In reply to
That seems to work, thanks.

But now...

Plugins::ConvertVideo::convert_video($link);

returns the information, as in

$link = Plugins::ConvertVideo::convert_video($link);

How should I go about to get that information back in the database?


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] AutoValidation In reply to
Hi,

No problem.

Personally, I would use something like:

Code:
sub post_add_link {

# get the highest ID in glinks_Links, as this will be the latest one added
my $max_id = $DB->table('Links')->select( ['MAX(ID)'] )->fetchrow;

# get the link of $max_id, as a hashref
my $link = $DB->table('Links')->select( { ID => $max_id } )->fetchrow_hashref;

# now just pass to the converter, and let it do its work =)
use Plugins::ConvertVideo;
my $link2 = Plugins::ConvertVideo::convert_video($link);

$DB->table('Links')->update( $link2, { ID => $max_id } ) || die $GT::SQL::error;

}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] AutoValidation In reply to
Hahahahahha SmileSmile

It's working!!!! Thanks Andy.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] AutoValidation In reply to
Hi,

No problem =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!