Skip to content
This repository
Browse code

added ampache resolver

  • Loading branch information...
commit 96404a95d0307dd50640ab0c9426a1f062d122dd 1 parent 287331e
authored RJ committed
10  contrib/ampache/ampache-resolver.conf.example
... ...
@@ -0,0 +1,10 @@
  1
+<?php
  2
+
  3
+$db = array(
  4
+  'host' => 'localhost', // ampache database host
  5
+  'db' => 'ampache', // ampache database
  6
+  'user' => 'ampache_db_user', // ampache database user
  7
+  'password' => 'ampache_db_password', // ampache database password
  8
+);
  9
+
  10
+
69  contrib/ampache/ampache-resolver.php
... ...
@@ -0,0 +1,69 @@
  1
+#!/usr/bin/env php
  2
+<?php
  3
+
  4
+require dirname(__FILE__) . '/../phpresolver/playdarresolver.php';
  5
+
  6
+class AmpacheResolver extends PlaydarResolver {
  7
+    protected $name = 'ampache resolver';
  8
+    protected $targetTime = 50;
  9
+    protected $weight = 100;
  10
+    protected $localonly = FALSE;
  11
+  
  12
+    private $link;
  13
+    private $prefix;
  14
+    
  15
+    function __construct($db){
  16
+      parent::__construct();
  17
+      
  18
+      $this->link = mysql_connect($db['host'], $db['user'], $db['password']) or die('Could not connect to MySQL database');
  19
+      mysql_select_db($db['db'], $this->link);
  20
+      mysql_query('SET NAMES utf8', $this->link);
  21
+    }
  22
+    
  23
+    function query($sql){
  24
+      $result = mysql_query($sql, $this->link);
  25
+      if (mysql_errno($this->link))
  26
+        exit('MySQL error ' . mysql_errno($this->link) . ': ' . mysql_error() . "\n");
  27
+      
  28
+      if (!$result)
  29
+        return array();
  30
+        
  31
+      $items = array();
  32
+      while ($item = mysql_fetch_array($result))
  33
+        $items[] = $item;
  34
+                
  35
+      return $items;
  36
+    }
  37
+        
  38
+    public function resolve($request) {          
  39
+      $where = array();
  40
+      foreach (array('artist' => 'artist.name', 'album' => 'album.name', 'track' => 'song.title') as $key => $value)
  41
+        if (!empty($request->{$key}))
  42
+          $where[] = sprintf("%s = '%s'", $value, mysql_real_escape_string($request->{$key}));
  43
+      $where = implode(' AND ', $where);
  44
+      
  45
+      $sql = "SELECT artist.name as artist, song.title as track, album.name as album, song.size, song.bitrate, song.time as duration, CONCAT('file://', song.file) as url
  46
+      FROM song LEFT JOIN album on song.album = album.id LEFT JOIN artist on song.artist = artist.id 
  47
+      WHERE $where LIMIT 100";
  48
+      
  49
+      $items =  $this->query($sql);
  50
+      
  51
+      if (!empty($items)){
  52
+        foreach ($items as &$item){            
  53
+          $item['score'] = 1; // TODO
  54
+          $item['source'] = 'Ampache';
  55
+        }
  56
+      }
  57
+      
  58
+      return $items;
  59
+    }
  60
+}
  61
+
  62
+include dirname(__FILE__) . '/ampache-resolver.conf';
  63
+$resolver = new AmpacheResolver($db, $prefix);
  64
+
  65
+//exit(print_r($resolver->resolve((object) array('artist' => 'Yeah Yeah Yeahs', 'track' => 'Heads Will Roll'))));
  66
+
  67
+$resolver->sendResponse($resolver->getSettings());
  68
+$resolver->handleRequest(fopen("php://STDIN",'r'));
  69
+

0 notes on commit 96404a9

Please sign in to comment.
Something went wrong with that request. Please try again.