diff --git a/PlayBot/sites/parser.pm b/PlayBot/sites/parser.pm index 00df7cbbe006eaf278289fedef02dfaf2e0b7ebc..00fd58c8b41c37e0dffd54eeec7c01a82c8473f0 100644 --- a/PlayBot/sites/parser.pm +++ b/PlayBot/sites/parser.pm @@ -1,5 +1,8 @@ package PlayBot::sites::parser; +use strict; +use warnings; + use PlayBot::sites::youtube; use PlayBot::sites::soundcloud; use PlayBot::sites::mixcloud; @@ -31,6 +34,10 @@ sub parse { elsif ($msg =~ m#(^|[^!])https?://soundcloud.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)(?:\?.+)?#) { my $url = 'https://www.soundcloud.com/'.$2; eval { %content = PlayBot::sites::soundcloud::get($url) }; + + use Data::Dumper; + print Dumper(\%content); + $content{'site'} = 'soundcloud'; } elsif ($msg =~ m#(^|[^!])https?://www.mixcloud.com/([a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+)#) { @@ -64,42 +71,37 @@ sub parse { # we assume it's a new content my $new = 1; - if ($debug) { - $log->debug($content{'url'}); - } - else { - # insertion de la vidéo dans la bdd - eval { - my $sth = $dbh->prepare(' - INSERT INTO playbot (type, url, sender, title, duration) - VALUES (?,?,?,?,?) - '); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute($content{'site'}, $content{'url'}, - $content{'author'}, $content{'title'}, $content{'duration'}); - }; - if ($@) { - # seems to be already present in database - $new = 0; - - my $sth = $dbh->prepare(' - UPDATE playbot playbot SET - sender = ?, - title = ?, - duration = ? - WHERE url = ? - '); - $log->error("Couldn't prepare querie; aborting") unless (defined $sth); - - $sth->execute( - $content{'author'}, - $content{'title'}, - $content{'duration'}, - $content{'url'}, - ); - } - } + # insertion de la vidéo dans la bdd + eval { + my $sth = $dbh->prepare(' + INSERT INTO playbot (type, url, sender, title, duration) + VALUES (?,?,?,?,?) + '); + $log->error("Couldn't prepare querie; aborting") unless (defined $sth); + + $sth->execute($content{'site'}, $content{'url'}, + $content{'author'}, $content{'title'}, $content{'duration'}); + }; + if ($@) { + # seems to be already present in database + $new = 0; + + my $sth = $dbh->prepare(' + UPDATE playbot playbot SET + sender = ?, + title = ?, + duration = ? + WHERE url = ? + '); + $log->error("Couldn't prepare querie; aborting") unless (defined $sth); + + $sth->execute( + $content{'author'}, + $content{'title'}, + $content{'duration'}, + $content{'url'}, + ); + } # sélection de l'id de la vidéo insérée my $sth = $dbh->prepare('SELECT id FROM playbot WHERE url = ?');