From 0cf164a3bee7e44a07a27104cf69d6e65bc4145a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20DEFRANCE?= <loic.defrance@gmail.com>
Date: Mon, 14 Mar 2016 14:41:14 +0100
Subject: [PATCH] Deezer support

---
 PlayBot/sites/deezer.pm  | 45 ++++++++++++++++++++++++++++++++++++++++
 PlayBot/utils/db/chan.pm |  2 +-
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 PlayBot/sites/deezer.pm

diff --git a/PlayBot/sites/deezer.pm b/PlayBot/sites/deezer.pm
new file mode 100644
index 0000000..5bfa8e9
--- /dev/null
+++ b/PlayBot/sites/deezer.pm
@@ -0,0 +1,45 @@
+package PlayBot::sites::deezer;
+
+use strict;
+use warnings;
+
+use LWP::UserAgent;
+use JSON;
+use FindBin;
+
+my $conf;
+my $endpoint = "https://api.deezer.com/track/";
+
+sub regex
+{
+    return qr#(?:^|[^!])https?://(?:www.)?deezer.com/track/([a-zA-Z0-9_-]+)#;
+}
+
+sub get {
+    shift;
+	my $id = shift;
+	
+    my $ua = LWP::UserAgent->new(
+        timeout     => 30,
+        env_proxy   => 1,
+    );
+	my $response = $ua->get($endpoint
+        .$id);
+	die($response->status_line) unless ($response->is_success);
+
+	my $content = decode_json($response->decoded_content);
+
+#    die "video not found" if (not scalar @{ $content->{items} });
+    
+    my %infos;
+
+    $infos{'title'} = $content->{'title'};
+    $infos{'duration'} = $content->{'duration'};
+	$infos{'site'} = 'deezer';
+    $infos{'url'} = 'https://www.deezer.com/track/'.$id;
+    $infos{'author'} = $content->{'artist'}->{'name'};
+
+	return %infos;
+}
+
+1;
diff --git a/PlayBot/utils/db/chan.pm b/PlayBot/utils/db/chan.pm
index 7d3312f..3a6c412 100644
--- a/PlayBot/utils/db/chan.pm
+++ b/PlayBot/utils/db/chan.pm
@@ -32,7 +32,7 @@ around 'BUILDARGS' => sub
 
     if (not $row)
     {
-        $sites = ['dailymotion', 'mixcloud', 'soundcloud', 'youtube', 'spotify'];
+        $sites = ['dailymotion', 'mixcloud', 'soundcloud', 'youtube', 'spotify', 'deezer'];
 
         $sth = $dbh->prepare('
             insert into playbot_config (name, sites)
-- 
GitLab