diff --git a/Logging.pm b/Logging.pm deleted file mode 100644 index 6b7085bbfda620b556316df2384c1a529e868b98..0000000000000000000000000000000000000000 --- a/Logging.pm +++ /dev/null @@ -1,606 +0,0 @@ -package Logging; - -# ==============[ Classe pour gérer les logs correctement ]============== # -# Date : 29/10/2010 # -# Auteur : TC # -# ======================================================================= # - -use strict; -use warnings; - -use Fcntl ':mode'; - - -# ### -# new -# Instancie la classe - un constructeur en somme -# ### -sub new -{ - my $class = shift; - my $self = { - _file => shift, - _colored => 0, - _pending => 0, - _utf8 => 0, - _right_align => shift, - }; - - bless $self, $class; - - # On active la couleur que si on est sur un terminal - # C'est moche après pour les fichiers ou un less - if($self->file eq "STDOUT") - { - $self->{"_colored"} = 1 if((stat(STDOUT))[2] & S_IFCHR); - } - elsif($self->file eq "STDERR") - { - $self->{"_colored"} = 1 if((stat(STDERR))[2] & S_IFCHR); - } - else - { - $self->{"_colored"} = 1 if((stat($self->file))[2] & S_IFCHR); - } - - - unless(defined $self->{"_right_align"}) - { - $self->{"_right_align"} = 0; - } - - return $self; -} # Fin new - - -# ### -# file -# Renvoie/maj $self->{'_file'} -# ### -sub file -{ - my $self = shift; - $self->{"_file"} = $_[0] if(defined($_[0])); - return $self->{"_file"}; -} # Fin file - - -# ### -# colored -# Renvoie/maj $self->{'_colored'} -# ### -sub colored -{ - my $self = shift; - $self->{"_colored"} = $_[0] if(defined($_[0])); - return $self->{"_colored"}; -} # Fin colored - - -# ### -# pending -# Renvoie/maj $self->{'_pending'} -# ### -sub pending -{ - my $self = shift; - $self->{"_pending"} = $_[0] if(defined($_[0])); - return $self->{"_pending"}; -} # Fin pending - - -# ### -# utf8 -# Renvoie/maj $self->{"_utf8"} -# ### -sub utf8 -{ - my $self = shift; - $self->{"_utf8"} = $_[0] if(defined($_[0])); - return $self->{"_utf8"}; -} # Fin utf8 - - -# ### -# right_align -# Renvoie/maj $self->{"_right_align"} -# ### -sub right_align -{ - my $self = shift; - $self->{"_right_align"} = $_[0] if(defined($_[0])); - return $self->{"_right_align"}; -} # Fin right_align - - -# ### -# debug -# Fonction gérant les logs du niveau debug (1) -# ### -sub debug -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[36mDEBUG\e[0m:$parent:$text"; - } - else - { - $text = "DEBUG:$parent:$text"; - } - - return $self->print_in_file($text, $self->DEBUG); -} # Fin debug - - -# ### -# pending_debug -# Fonction gérant les logs du niveau debug (1) -# ### -sub pending_debug -{ - my ($self, $text) = @_; - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[36mDEBUG\e[0m:$parent:$text"; - } - else - { - $text = "DEBUG:$parent:$text"; - } - - return $self->pending_in_file($text, $self->DEBUG); -} # Fin pending_debug - - -# ### -# info -# Fonction gérant les logs du niveau info (2) -# ### -sub info -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[33;1mINFO\e[0m:$parent:$text"; - } - else - { - $text = "INFO:$parent:$text"; - } - - return $self->print_in_file($text, $self->INFO); -} # Fin info - - -# ### -# pending_info -# Fonction gérant les logs du niveau info (2) -# ### -sub pending_info -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[33;1mINFO\e[0m:$parent:$text"; - } - else - { - $text = "INFO:$parent:$text"; - } - - return $self->pending_in_file($text, $self->INFO); -} # Fin pending_info - - -# ### -# warning -# Fonction gérant les logs du niveau warning (3) -# ### -sub warning -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[33mWARNING\e[0m:$parent:$text"; - } - else - { - $text = "WARNING:$parent:$text"; - } - - return $self->print_in_file($text, $self->WARNING); -} # Fin warning - - -# ### -# pending_warning -# Fonction gérant les logs du niveau warning (3) -# ### -sub pending_warning -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[33mWARNING\e[0m:$parent:$text"; - } - else - { - $text = "WARNING:$parent:$text"; - } - - return $self->pending_in_file($text, $self->WARNING); -} # Fin pending_warning - - -# ### -# error -# Fonction gérant les logs du niveau error (4) -# ### -sub error -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[31mERROR\e[0m:$parent:$text"; - } - else - { - $text = "ERROR:$parent:$text"; - } - - return $self->print_in_file($text, $self->ERROR); -} # Fin error - - -# ### -# pending_error -# Fonction gérant les logs du niveau error (4) -# ### -sub pending_error -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[31mERROR\e[0m:$parent:$text"; - } - else - { - $text = "ERROR:$parent:$text"; - } - - return $self->pending_in_file($text, $self->ERROR); -} # Fin pending_error - - -# ### -# critical -# Fonction gérant les logs du niveau critical (5) -# ### -sub critical -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[31;1mCRITICAL\e[0m:$parent:$text"; - } - else - { - $text = "CRITICAL:$parent:$text"; - } - - return $self->print_in_file($text, $self->CRITICAL); -} # Fin critical - - -# ### -# pending_critical -# Fonction gérant les logs du niveau critical (5) -# ### -sub pending_critical -{ - my ($self, $text) = @_; - return unless(defined $text); - - chomp $text; - - my $parent = ( caller(1) )[3]; - $parent = "" if(!defined($parent)); - - if($self->colored) - { - $text = "\e[31;1mCRITICAL\e[0m:$parent:$text"; - } - else - { - $text = "CRITICAL:$parent:$text"; - } - - return $self->pending_in_file($text, $self->CRITICAL); -} # Fin pending_critical - - -# ### -# print_in_file -# Écrit dans le fichier -# ### -sub print_in_file -{ - my ($self, $text, $level) = @_; - return unless(defined $text); - - chomp $text; - $text = "[\e[32m" . (scalar localtime time) . "\e[0m] $text"; - - $self->end_pending(0, $level) if($self->pending); - - if($self->file eq "STDOUT") - { - print STDOUT $text."\n"; - } - elsif($self->file eq "STDERR") - { - print STDERR $text."\n"; - } - else - { - open LOG, ">>", $self->file or return 0; - print LOG $text."\n"; - close LOG; - - print $text."\n" if(defined($level) && $Config::debug >= $level); - } - - return 1; -} # Fin print_in_file - - -# ### -# pending_in_file -# Écrit dans le fichier en attendant de savoir si ça a réussi ou pas -# ### -sub pending_in_file -{ - my ($self, $text, $level) = @_; - return unless(defined $text); - - chomp $text; - $text = "[" . (scalar localtime time) . "] $text"; - - if($self->file eq "STDOUT") - { - if($self->right_align) - { - printf STDOUT "%-90s", $text; - } - else - { - print STDOUT $text; - } - } - elsif($self->file eq "STDERR") - { - if($self->right_align) - { - printf STDERR "%-90s", $text; - } - else - { - print STDERR $text; - } - } - else - { - if($self->right_align) - { - open LOG, ">>", $self->file or return 0; - printf LOG "%-90s", $text; - close LOG; - - printf "%-90s", $text if(defined($level) && $Config::debug >= $level); - } - else - { - open LOG, ">>", $self->file or return 0; - print LOG $text; - close LOG; - - print $text if(defined($level) && $Config::debug >= $level); - } - } - - $self->pending(1); - - return 1; -} # Fin pending_in_file - - -# ### -# end_pending -# Écrit dans le fichier le résultat de l'attente -# ### -sub end_pending -{ - my ($self, $done_or_error, $level) = @_; - - my $done = ""; - - if($done_or_error) - { - if($self->colored) - { - $done = sprintf "%c[32m Done ", 0x1B; - } - else - { - $done = sprintf " Done \n"; - } - - $done .= "☑" if($self->utf8); - } - else - { - if($self->colored) - { - $done = sprintf "%c[31m Error ", 0x1B; - } - else - { - $done = sprintf " Error \n"; - } - - $done .= "☒" if($self->utf8); - } - - $done .= "\e[0m\n" if($self->colored); - - - # À partir d'ici, $done peut vouloir dire que c'est bon, ou pas - if($self->file eq "STDOUT") - { - printf STDOUT $done; - } - elsif($self->file eq "STDERR") - { - printf STDERR $done; - } - else - { - open LOG, ">>", $self->file or return 0; - printf LOG $done; - close LOG; - - printf $done if(defined($level) && $Config::debug >= $level); - } - - - $self->pending(0); - - return 1; -} # Fin end_pending - - -# -# Fonctions pour récupérer les différents niveaux de debug -# -sub DEBUG { return 3; } -sub INFO { return 2; } -sub WARNING { return 1; } -sub ERROR { return 0; } -sub CRITICAL { return -1; } -# Pour ceux qui préfèrent utiliser des variables... -our $DEBUG = 3; -our $INFO = 2; -our $WARNING = 1; -our $ERROR = 0; -our $CRITICAL = -1; -our %LVL_NAME = ( - "DEBUG" => 3, - "INFO" => 2, - "WARNING" => 1, - "ERROR" => 0, - "CRITICAL" => -1 -); - -# Et dans l'autre sens -sub LVL -{ - my ($self, $num) = @_; - - my %LVL = ( - 3 => "DEBUG", - 2 => "INFO", - 1 => "WARNING", - 0 => "ERROR", - "-1" => "CRITICAL" - ); - - return $LVL{$num}; -} -our %LVL = ( - 3 => "DEBUG", - 2 => "INFO", - 1 => "WARNING", - 0 => "ERROR", - "-1" => "CRITICAL" -); - - -# ### -# dbg -# Imprime des infos de debug à l'écran (STDOUT) -# ### -sub dbg -{ - my $self = shift; - - require Data::Dumper; - print Data::Dumper->Dump([$self], [qw(Logging)]); -} # Fin dbg - - -1; - -__END__ - diff --git a/PlayBot.pl b/PlayBot.pl deleted file mode 100755 index 9f6e0426fab4d6bb1c7d5e23521a1aabc6805cf9..0000000000000000000000000000000000000000 --- a/PlayBot.pl +++ /dev/null @@ -1,366 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use warnings; -use POE; -use POE::Component::IRC; -use POSIX 'strftime'; -use DBI; -use Tie::File; -use JSON; - -use Logging; -use youtube; -use soundcloud; -use mixcloud; -use zippy; - - -# nom du fichier -my $bot = $0; - -my $log = Logging->new('STDOUT', 1); - -# config -my $serveur = 'IRC.iiens.net'; -my $nick = 'PlayBot'; -my $port = 6667; -my $ircname = 'nightiies'; -my $username = 'nightiies'; -my @channels = qw(#nightiies #bigphatsubwoofer); -my $admin = 'moise'; -my $baseurl = 'http://nightiies.iiens.net/links/'; -my @nicksToVerify; -my @codesToVerify; -my $lastID; - -my $debug = 0; - -# mode debug -if ($#ARGV + 1) { - @channels = qw(#hormone); - $nick = 'kikoo'; - $debug = 1; -} - - -local $/; -open CONF, '<', 'playbot.conf'; -my $json = <CONF>; -my $conf = decode_json($json); - - -## CONNEXION -my ($irc) = POE::Component::IRC->spawn(); -my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $conf->{'user'}, $conf->{'passwd'}, { - PrintError => 0, - AutoCommit => 1, - mysql_auto_reconnect => 1 - }) - or die("Couldn't connect to database: ".DBI->errstr); - - -# Evenements que le bot va gérer -POE::Session->create( - inline_states => { - _start => \&bot_start, - irc_001 => \&on_connect, - irc_public => \&on_speak, - irc_msg => \&on_query, - irc_notice => \&on_notice, - _flux => \&flux, - _later => \&later - }, -); - - -my %commandes_admin = ("cycle" => \&cycle); - - - -### FONCTIONS -sub flux -{ - my $kernel = $_[ KERNEL ]; - my $date = strftime ("%Y-%m-%d", localtime(time - 3600*24)); - - my $sth = $dbh->prepare_cached('SELECT COUNT(*) FROM playbot WHERE date = ?'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - $sth->execute($date) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - my ($nbr) = $sth->fetchrow_array; - - if ($nbr) { - $irc->yield(privmsg => $_ => $nbr.' liens aujourd\'hui : '.$baseurl.$date) foreach (@channels); - } - - $kernel->delay_set('_flux', 3600*24); -} - - -sub addTag -{ - my ($id, $tag) = @_; - - my $sth = $dbh->prepare_cached('INSERT INTO playbot_tags (id, tag) VALUES (?, ?)'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($id, $tag) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); -} - - -sub later -{ - my ($nick, $id) = @_[ARG0,ARG1]; - - my $sth = $dbh->prepare_cached('SELECT url, sender, title FROM playbot WHERE id = ?'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($id) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - if ($sth->rows) { - my @donnees = $sth->fetchrow_array; - - $irc->yield(privmsg => $nick => '['.$id.'] '.$donnees[2].' | '.$donnees[1]); - $irc->yield(privmsg => $nick => $donnees[0]); - } -} - - -sub cycle -{ - my ($arg) = @_; - - $log->info("restarting"); - $irc->yield(quit => 'goodbye'); - sleep 1; - exec $bot; -} - - -## GESTION EVENTS - -# Au démarrage -sub bot_start { - $irc->yield(register => "all"); - $irc->yield( - connect => { - Nick => $nick, - Username => $username, - Ircname => $ircname, - Server => $serveur, - Port => $port, - } - ); -} - - -# A la connection -sub on_connect -{ - my $kernel = $_[ KERNEL ]; - $irc->yield(join => $_) foreach (@channels); - $log->info('connected'); - - my $hour = strftime ('%H', localtime); - my $min = strftime ('%M', localtime); - - $kernel->delay_set('_flux', (23-$hour)*3600 + (60-$min)*60); -} - - -# Discussion privée -sub on_query -{ - my ($user,$msg) = @_[ARG0, ARG2]; - my ($nick) = split (/!/,$user); - print $msg."\n"; - - if ($msg =~ m/^!/ && $nick eq $admin) { - my $commande = ( $msg =~ m/^!([^ ]*)/ )[0]; - my @params = grep {!/^\s*$/} split(/\s+/, substr($msg, length("!$commande"))); - - foreach (keys(%commandes_admin)) { - if ($commande eq $_) { - $commandes_admin{$_}->(@params); - last; - } - } - } - elsif ($msg =~ /^PB/) { - # on vérifie si le nick est register - push (@nicksToVerify, $nick); - push (@codesToVerify, $msg); - $irc->yield(privmsg => $nick => 'Vérification en cours…'); - $irc->yield(privmsg => nickserv => 'info '.$nick); - } -} - - -sub on_notice -{ - my ($user, $msg) = @_[ARG0, ARG2]; - my ($nick) = split(/!/,$user); - - return unless ($nick =~ /^NickServ$/i); - - my $nickToVerify = shift @nicksToVerify; - my $code = shift @codesToVerify; - - return unless (defined($nickToVerify)); - - if ($msg !~ /$nickToVerify/) { - push (@nicksToVerify, $nickToVerify); - push (@codesToVerify, $code); - } - elsif ($msg =~ /isn't registered/) { - $irc->yield(privmsg => $nickToVerify => "Il faut que ton pseudo soit enregistré auprès de NickServ"); - } - else { - my $sth = $dbh->prepare_cached('SELECT user FROM playbot_codes WHERE code = ?'); - $log->error("Counldn't prepare querie; aborting") unless (defined $sth); - $sth->execute($code); - - if ($sth->rows) { - my $sth = $dbh->prepare_cached('UPDATE playbot_codes SET nick = ? WHERE code = ?'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($nickToVerify, $code) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - $irc->yield(privmsg => $nickToVerify => 'Association effectuée'); - $irc->yield(privmsg => $nickToVerify => 'pour enregistrer un lien dans tes favoris : !fav <id>'); - } - else { - $irc->yield(privmsg => $nickToVerify => "Ce code n'existe pas"); - } - } -} - - -# Quand un user parle -sub on_speak -{ - my ($kernel, $user, $chan, $msg) = @_[KERNEL, ARG0, ARG1, ARG2]; - my ($nick,$mask) = split(/!/,$user); - my $site; - my %content; - - if ($msg =~ m#(^|[^!])https?://(www.youtube.com/watch\?[a-zA-Z0-9_=&-]*v=|youtu.be/)([a-zA-Z0-9_-]+)#) { - my $url = 'https://www.youtube.com/watch?v='.$3; - eval { %content = youtube($url) }; - $site = 'youtube'; - } - elsif ($msg =~ m#(^|[^!])https?://soundcloud.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)#) { - my $url = 'https://www.soundcloud.com/'.$2; - eval { %content = soundcloud($url) }; - $site = 'soundcloud'; - } - elsif ($msg =~ m#(^|[^!])https?://www.mixcloud.com/([a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+)#) { - my $url = 'https://www.mixcloud.com/'.$2; - eval { %content = mixcloud($url) }; - $site = 'mixcloud'; - } - elsif ($msg =~ m#((^|[^!])http://www[0-9]+.zippyshare.com/v/[0-9]+/file.html)#) { - my $url = $1; - eval { %content = zippy($url) }; - $site = 'zippyshare'; - } - elsif ($msg =~ /^!fav( ([0-9]+))?/) { - my $id = ($2) ? $2 : $lastID; - - my $sth = $dbh->prepare_cached('SELECT user FROM playbot_codes WHERE nick = ?'); - $sth->execute($nick) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - unless ($sth->rows) { - $irc->yield(privmsg => $nick => "Ce nick n'est associé à aucun login arise. Va sur http://nightiies.iiens.net/links/fav pour obtenir ton code personel."); - return; - } - - my $sth2 = $dbh->prepare_cached('INSERT INTO playbot_fav (id, user) VALUES (?, ?)'); - $sth2->execute($id, $sth->fetch->[0]) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - return; - } - elsif ($msg =~ /^!later( ([0-9]*)( in ([0-9]*)(h|m|s)?)?)?/) { - my ($id, $time, $unit) = ($2, $4, $5); - - $id = $lastID if (!$id); - $time = 6 if (!$time); - $time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600; - print "$time eq\n"; - $kernel->delay_set('_later', $time, $nick, $id); - - return; - } - elsif ($msg =~ /^!tag( +([0-9]+))?/) { - my $id = ($2) ? $2 : $lastID; - while ($msg =~ /#([a-zA-Z0-9_-]+)/g) { - addTag($id, $1); - } - - return; - } - else { - return; - } - - if ($@) { - $log->warning ($@); - return; - } - - if ($debug) { - $log->debug($content{'url'}); - } - else { - # insertion de la vidéo dans la bdd - - my $sth = $dbh->prepare_cached('INSERT INTO playbot (date, type, url, sender_irc, sender, title, chan) VALUES (NOW(),?,?,?,?,?,?)'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($site, $content{'url'}, $nick, $content{'author'}, $content{'title'}, '#nightiies') - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - } - - # sélection de l'id de la vidéo insérée - my $id = $dbh->{mysql_insert_id}; - if (!$id) { - my $sth = $dbh->prepare_cached('SELECT id FROM playbot WHERE url = ?'); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($content{'url'}) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - $id = $sth->fetch->[0]; - } - $lastID = $id; - - - # insertion des éventuels tags - while ($msg =~ /#([a-zA-Z0-9_-]+)/g) { - if ($debug) { - $log->debug($1); - next; - } - - addTag ($lastID, $1); - } - - - # message sur irc - if (defined $content{'author'}) { - $irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}.' | '.$content{'author'}) ; - } - else { - $irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}) ; - } -} - - -# Boucle des events -$poe_kernel->run(); -exit 0; diff --git a/mixcloud.pm b/mixcloud.pm deleted file mode 100644 index 8cd29a53518b7b1021a9f25c6e7623648b7071ee..0000000000000000000000000000000000000000 --- a/mixcloud.pm +++ /dev/null @@ -1,71 +0,0 @@ -package mixcloud; - -use LWP::UserAgent; -use HTML::Parser; -use HTML::Entities; - -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(mixcloud); - - -my $inTitle = 0; -my $inAuthor = 0; -my %infos; - - -sub mixcloud { - my ($url) = @_; - - my $ua = LWP::UserAgent->new( - agent => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1", - timeout => 30 - ); - - my $response = $ua->get($url); - die($response->status_line) unless ($response->is_success); - - my $content = $response->decoded_content; - - my $parser = HTML::Parser->new(); - $parser->handler(text => \&parser_text, 'text'); - $parser->handler(start => \&parser_start, 'tagname'); - $parser->handler(end => \&parser_end, 'tagname'); - $parser->unbroken_text(1); - $parser->report_tags('title', 'a'); - $parser->parse($content); - $parser->eof(); - - $infos{'url'} = $url; - - return %infos; -} - -sub parser_text -{ - my ($text) = @_; - chomp $text; - $text = decode_entities($text); - - if ($inTitle) { - $text =~ s/\n//; - $text =~ s/ \| Mixcloud .*//; - $text =~ s/^ *//; - $text =~ s/[^a-zA-Z0-9\(\)\[\]]*$//; - ($infos{'author'}, $infos{'title'}) = split (' - ', $text, 2); - } -} - -sub parser_start -{ - my ($tag) = @_; - $inTitle = 1 if ($tag eq 'title'); -} - -sub parser_end -{ - my ($tag) = @_; - $inTitle = 0 if ($tag eq 'title'); -} - -1; diff --git a/soundcloud.pm b/soundcloud.pm deleted file mode 100644 index 1e00ebfb755515ed016121cf8e9d045a9f1bf001..0000000000000000000000000000000000000000 --- a/soundcloud.pm +++ /dev/null @@ -1,35 +0,0 @@ -package soundcloud; - -use LWP::UserAgent; -use JSON; - -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(soundcloud); - - -my $root = 'http://api.soundcloud.com'; -my $clientId = 'f4956716fe1a9dc9c3725af822963365'; - - -sub soundcloud { - my ($url) = @_; - - my $ua = LWP::UserAgent->new(timeout => 30); - - my $response = $ua->get($root.'/resolve.json?url='.$url.'&client_id='.$clientId); - die($response->status_line) unless ($response->is_success); - - $content = decode_json($response->decoded_content); - $infos{'title'} = $content->{'title'}; - $infos{'author'} = $content->{'user'}->{'username'}; - $infos{'url'} = $url; - - if ($content->{'downloadable'}) { - $infos{'ddl'} = $content->{'download_url'}; - } - - return %infos; -} - -1; diff --git a/youtube.pm b/youtube.pm deleted file mode 100644 index d9039b50ce6425aa736166fbeb465b13d0bd3ed4..0000000000000000000000000000000000000000 --- a/youtube.pm +++ /dev/null @@ -1,76 +0,0 @@ -package youtube; - -use LWP::UserAgent; -use HTML::Parser; -use HTML::Entities; - -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(youtube); - - -my $inTitle = 0; -my $inAuthor = 0; -my %infos; - - -sub youtube { - my ($url) = @_; - - my $ua = LWP::UserAgent->new( - agent => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1", - timeout => 30 - ); - - my $response = $ua->get($url); - die($response->status_line) unless ($response->is_success); - - my $content = $response->decoded_content; - - my $parser = HTML::Parser->new(); - $parser->handler(text => \&parser_text, 'text'); - $parser->handler(start => \&parser_start, 'tagname,attr'); - $parser->handler(end => \&parser_end, 'tagname'); - $parser->unbroken_text(1); - $parser->report_tags('title', 'a'); - $parser->parse($content); - $parser->eof(); - - $infos{'url'} = $url; - - return %infos; -} - -sub parser_text -{ - my ($text) = @_; - chomp $text; - - if ($inTitle) { - $text =~ s/\n//; - $text =~ s/- YouTube//; - $text =~ s/^ *//; - $text =~ s/[^a-zA-Z0-9\(\)\[\]]*$//; - $infos{'title'} = decode_entities($text); - } - elsif ($inAuthor) { - $infos{'author'} = $text; - } -} - -sub parser_start -{ - my ($tag, $attr) = @_; - $inTitle = 1 if ($tag eq 'title'); - return unless (defined $attr); - $inAuthor = 1 if ($tag eq 'a' && exists($attr->{'class'}) && $attr->{'class'} =~ /yt-user-name author/); -} - -sub parser_end -{ - my ($tag) = @_; - $inTitle = 0 if ($tag eq 'title'); - $inAuthor = 0 if ($tag eq 'a'); -} - -1; diff --git a/zippy.pm b/zippy.pm deleted file mode 100644 index 872b13a6ac2b2a12ee61e2752398181d4eb25038..0000000000000000000000000000000000000000 --- a/zippy.pm +++ /dev/null @@ -1,70 +0,0 @@ -package zippy; - -use LWP::UserAgent; -use HTML::Parser; -use HTML::Entities; - -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(zippy); - - -my $inTitle = 0; -my $inAuthor = 0; -my %infos; - - -sub zippy { - my ($url) = @_; - - my $ua = LWP::UserAgent->new( - agent => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1", - timeout => 30 - ); - - my $response = $ua->get($url); - die($response->status_line) unless ($response->is_success); - - my $content = $response->decoded_content; - - my $parser = HTML::Parser->new(); - $parser->handler(text => \&parser_text, 'text'); - $parser->handler(start => \&parser_start, 'tagname'); - $parser->handler(end => \&parser_end, 'tagname'); - $parser->unbroken_text(1); - $parser->report_tags('title', 'a'); - $parser->parse($content); - $parser->eof(); - - $infos{'url'} = $url; - $infos{'author'} = undef; - - return %infos; -} - -sub parser_text -{ - my ($text) = @_; - chomp $text; - $text = decode_entities($text); - - if ($inTitle) { - $text =~ s/^Zippyshare.com - //; - $text =~ s/\.mp3$//; - $infos{'title'} = $text; - } -} - -sub parser_start -{ - my ($tag) = @_; - $inTitle = 1 if ($tag eq 'title'); -} - -sub parser_end -{ - my ($tag) = @_; - $inTitle = 0 if ($tag eq 'title'); -} - -1;