4 public function __construct()
6 $cache = Config::main()->get('cache');
9 throw new Exception('Cache file not found');
11 $this->db = new PDO('sqlite:/'.$cache);
14 public function getRelativePath($id)
16 $media_dir = Config::main()->get('media_dir_A');
18 $sql = sprintf("SELECT path FROM details WHERE id = %d", $id);
19 $sth = $this->db->query($sql);
20 if ($sth === false) return null;
22 $row = $sth->fetchObject();
23 $path = substr($row->PATH, strlen($media_dir)+1);
27 public function findTitles($keyword)
29 $media_dir = Config::main()->get('media_dir_A');
30 $results = array('count' => 0, 'list' => []);
31 $sql = sprintf("SELECT id, path, title, timestamp, size FROM details WHERE path LIKE %s AND mime IS NOT NULL",
32 $this->db->quote('%'.$keyword.'%'));
34 $sth = $this->db->query($sql);
35 if ($sth === false) return $results;
38 while ($row = $sth->fetchObject()) {
39 $id = "{$row->TIMESTAMP}-{$row->SIZE}";
40 if (!array_key_exists($id, $seen)) {
45 $path = substr($row->PATH, strlen($media_dir)+1);
47 if (($pos = strrpos($path, '.')) > strlen($path)-10)
48 $path = substr($path, 0, $pos);
50 if (($pos = strpos($path, '/')) < 20) {
51 $section = substr($path, 0, $pos);
52 $path = substr($path, $pos+1);
55 if (!array_key_exists($section, $results['list']))
56 $results['list'][$section] = [];
58 $item = ['path' => dirname($path), 'name' => basename($path), 'title' => $row->TITLE];
59 if (array_key_exists('playlist', $_SESSION))
60 $item['id'] = $row->ID;
64 $results['list'][$section][] = $item;