#!/usr/bin/perl -w
#===============================================================================
#
# FILE: youdwnperl.pl
#
# USAGE: ./youdwnperl.pl or perl youdwnperl.pl
#
# DESCRIPTION: Descarga videos desde YouTube
# Los videos son descargados en el directorio ~
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# COMPANY: CodeSolution
# VERSION: 1.0
# CREATED: 09/01/11 02:02:27
# REVISION: ---
#===============================================================================
use strict;
use Gtk2 -init;
use Gtk2::GladeXML;
use WWW::YouTube::Download;
use File::Copy;
use encoding ':locale';
use constant TRUE => 1;
use constant FALSE => !TRUE;
# Variables globales indispensables.
########################################################################
my($programa, $ventana_principal);
$programa = Gtk2::GladeXML->new('youdwnperl.glade');
$ventana_principal = $programa->get_widget('window1');
# Ventana about
my $ventana_about = $programa->get_widget('about');
# Cargamos los componentes.
$programa->signal_autoconnect_from_package('main');
# La señal para que cuando cierre se CIERRE TODO.
$ventana_principal->signal_connect(destroy => sub
{
Gtk2->main_quit();
}
);
$ventana_about->signal_connect(destroy => sub
{
$ventana_about->hide();
}
);
# Mostrar todo.
$ventana_principal->resize(600, 90);
$ventana_principal->show_all();
# YouTube Shit:
my $client = WWW::YouTube::Download->new();
my $video_title;
# Objeto de tipo YouTube
my $client = WWW::YouTube::Download->new();
# Agregar los TextBox
my $texto = $programa->get_widget('texto');
# Agregar la barra de status
my $status = $programa->get_widget('status');
my $context_id = $status->get_context_id("");
# Agregar el label de Video ID:
my $lblVideoID = $programa->get_widget('lblVideoID');
my $lblVideoID2 = $programa->get_widget('lblVideoID2');
$ventana_principal->show_all();
Gtk2->main();
########################################################################
sub on_boton_cerrar_activate
{
Gtk2->main_quit();
}
sub on_texto_activate
{
unless ($texto->get_text())
{
$status->push($context_id, sprintf("Ingrese su video."));
return;
}
$lblVideoID2->set_text(&getVideoID());
}
sub on_btnObtener_clicked
{
$status->push($context_id, sprintf(""));
unless ($texto->get_text())
{
$status->push($context_id, sprintf("Ingrese su video."));
return;
}
$status->push($context_id, sprintf("Video title : [ " . &getTitle() . " ] ... ... ... Descargando"));
$lblVideoID2->set_text(&getVideoID());
&downloadVideo();
$status->push($context_id, sprintf("Video -> [" . &getTitle() . "] descargado con éxito"));
}
sub getVideoID
{
my $url = $texto->get_text();
my ($video_id) = $texto->get_text() =~ m/^.*v=(.*)$/;
return $video_id;
}
sub getTitle
{
my $title = $client->get_title(&getVideoID());
return $title;
}
sub downloadVideo
{
my $name = &getTitle() . ".flv";
$client->download(&getVideoID(), {
file_name => $name
});
move($name, $ENV{'HOME'}) or die("No se pudo mover el video al directorio ~ . $!");
}
sub on_aboutFileItem_activate
{
$ventana_about->run();
$ventana_about->hide();
}
__END__
This program is distributed under the terms of the GPL v2.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
http://www.gnu.org/licenses/gpl-2.0.html