Exemplo n.º 1
0
 function search($query)
 {
     require_once 'lib_collection.php';
     $l = OC_L10N::get('media');
     $app_name = (string) $l->t('Music');
     $artists = OC_MEDIA_COLLECTION::getArtists($query);
     $albums = OC_MEDIA_COLLECTION::getAlbums(0, $query);
     $songs = OC_MEDIA_COLLECTION::getSongs(0, 0, $query);
     $results = array();
     foreach ($artists as $artist) {
         $results[] = new OC_Search_Result($artist['artist_name'], '', OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
     }
     foreach ($albums as $album) {
         $artist = OC_MEDIA_COLLECTION::getArtistName($album['album_artist']);
         $results[] = new OC_Search_Result($album['album_name'], 'by ' . $artist, OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
     }
     foreach ($songs as $song) {
         $minutes = floor($song['song_length'] / 60);
         $secconds = $song['song_length'] % 60;
         $artist = OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
         $album = OC_MEDIA_COLLECTION::getalbumName($song['song_album']);
         $results[] = new OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$secconds}", OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
     }
     return $results;
 }
 public static function search_songs($params)
 {
     if (!self::checkAuth($params)) {
         echo "<root>\n\t<error code='400'>Invalid login</error>\n</root>";
         return;
     }
     $filter = $params['filter'];
     $artists = OC_MEDIA_COLLECTION::getArtists($filter);
     $albums = OC_MEDIA_COLLECTION::getAlbums(0, $filter);
     $songs = OC_MEDIA_COLLECTION::getSongs(0, 0, $filter);
     foreach ($artists as $artist) {
         $songs = array_merge($songs, OC_MEDIA_COLLECTION::getSongs($artist['artist_id']));
     }
     foreach ($albums as $album) {
         $songs = array_merge($songs, OC_MEDIA_COLLECTION::getSongs($album['album_artist'], $album['album_id']));
     }
     echo '<root>';
     foreach ($songs as $song) {
         self::printSong($song);
     }
     echo '</root>';
 }
     $path = $arguments['path'];
     echo OC_MEDIA_SCANNER::scanFolder($path);
     OC_DB::commit();
     flush();
     break;
 case 'scanFile':
     echo OC_MEDIA_SCANNER::scanFile($arguments['path']) ? 'true' : 'false';
     break;
 case 'get_artists':
     OC_JSON::encodedPrint(OC_MEDIA_COLLECTION::getArtists($arguments['search']));
     break;
 case 'get_albums':
     OC_JSON::encodedPrint(OC_MEDIA_COLLECTION::getAlbums($arguments['artist'], $arguments['search']));
     break;
 case 'get_songs':
     OC_JSON::encodedPrint(OC_MEDIA_COLLECTION::getSongs($arguments['artist'], $arguments['album'], $arguments['search']));
     break;
 case 'get_path_info':
     if (OC_Filesystem::file_exists($arguments['path'])) {
         $songId = OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
         if ($songId == 0) {
             unset($_SESSION['collection']);
             $songId = OC_MEDIA_SCANNER::scanFile($arguments['path']);
         }
         if ($songId > 0) {
             $song = OC_MEDIA_COLLECTION::getSong($songId);
             $song['artist'] = OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
             $song['album'] = OC_MEDIA_COLLECTION::getAlbumName($song['song_album']);
             OC_JSON::encodedPrint($song);
         }
     }
if (OC_User::checkPassword($user, $pass)) {
    OC_Util::setupFS($user);
    OC_MEDIA_COLLECTION::$uid = $user;
} else {
    exit;
}
if (isset($_POST['play']) and $_POST['play'] == 'true') {
    if (!isset($_POST['song'])) {
        exit;
    }
    $song = OC_MEDIA_COLLECTION::getSong($_POST['song']);
    $ftype = OC_Filesystem::getMimeType($song['song_path']);
    header('Content-Type:' . $ftype);
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . OC_Filesystem::filesize($song['song_path']));
    OC_Filesystem::readfile($song['song_path']);
}
$artist = isset($_POST['artist']) ? '%' . $_POST['artist'] . '%' : '';
$album = isset($_POST['album']) ? '%' . $_POST['album'] . '%' : '';
$song = isset($_POST['song']) ? $_POST['song'] : '';
$artist = OC_MEDIA_COLLECTION::getArtistId($artist);
$album = OC_MEDIA_COLLECTION::getAlbumId($album, $artist);
$songs = OC_MEDIA_COLLECTION::getSongs($artist, $album, $song);
$baseUrl = OC_Util::getServerURL() . OC_Helper::linkTo('media', 'tomahawk.php');
$results = array();
foreach ($songs as $song) {
    $results[] = (object) array('artist' => OC_MEDIA_COLLECTION::getArtistName($song['song_artist']), 'album' => OC_MEDIA_COLLECTION::getAlbumName($song['song_album']), 'track' => $song['song_name'], 'source' => 'ownCloud', 'mimetype' => OC_Filesystem::getMimeType($song['song_path']), 'extension' => substr($song['song_path'], strrpos($song['song_path'], '.')), 'url' => $baseUrl . '?play=true&song=' . $song['song_id'], 'bitrate' => round($song['song_id'] / $song['song_length'], 0), 'duration' => round($song['song_length'], 0), 'size' => $song['song_size'], 'score' => (double) 1.0);
}
OC_JSON::encodedPrint($results);