Пример #1
0
function playlist_add($type, $itemid)
{
    global $mpd;
    if (inMpdMode()) {
        if (mpd_connect() == 0) {
            $output[] = "<li>Can't connect to MPD server</li>";
            $output[] = 0;
            $output[] = 'pl0';
            return $output;
        }
        switch ($type) {
            case 'song':
                // in MPD mode we talk to the MPD playlist...
                // so first we track down the actual song file
                // and then we queue it
                $foundtrack = mpdGetSongForId($itemid);
                if ($foundtrack == NULL) {
                    $output[] = "<li>MPD: could not find song</li>";
                    $output[] = 0;
                    $output[] = 'pl0';
                    return $output;
                }
                // now we should have $song_fname, which is all we need for pl_add
                $mpd->PLAdd($foundtrack['file']);
                // find our track in the playlist to get its song ID
                $id = -1;
                // make sure we notice when its wrong
                if (count($mpd->playlist) > 0) {
                    foreach ($mpd->playlist as $plsong) {
                        if ($plsong['file'] == $foundtrack['file']) {
                            $id = $plsong['Id'];
                        }
                    }
                }
                // generate a list item for this track
                $artist = $foundtrack['Artist'];
                $album = $foundtrack['Album'];
                $title = $foundtrack['Title'];
                $trackno = $foundtrack['Track'];
                $sec = (int) ($foundtrack['Time'] % 60);
                $min = (int) ($foundtrack['Time'] / 60);
                $length = $min . ":" . ($sec < 10 ? "0" : "") . $sec;
                $file = $foundtrack['File'];
                $output[] = "<li id=\"pl{$id}\" onmouseover=\"setBgcolor('pl" . $id . "','#FCF7A5'); return false;\" onmouseout=\"setBgcolor('pl" . $id . "','#f3f3f3'); return false;\"><a href=\"#\" onclick=\"movePLItem('up',this.parentNode); return false;\" title=\"Move Song Up in Playlist\"><img src=\"img/up.gif\" /></a> <a href=\"#\" onclick=\"movePLItem('down',this.parentNode); return false;\" title=\"Move Song Down in Playlist\"><img src=\"img/down.gif\" /></a> <a href=\"#\" onclick=\"plrem(this.parentNode.id); return false;\" title=\"Remove Song from Playlist\"><img src=\"img/rem.gif\" /></a> {$artist} - {$title}<p>Album: {$album}<br/>Track: {$trackno}<br/>{$length}</p></li>";
                $output[] = 1;
                $output[] = 'pl' . $id;
                return $output;
            case 'album':
                // add entire album in MPD mode...
                list($artist, $album) = mpdGetArtistAlbumForAlbumId($itemid);
                // now do a "find album XXX"
                // then filter for our artist
                if (!is_null($ar = $mpd->Find(MPD_SEARCH_ALBUM, $album))) {
                    // got results, iterate and filter for the right artist
                    if (count($ar) > 0) {
                        foreach ($ar as $track) {
                            if ($track['Artist'] == $artist) {
                                $localplaylist[] = $track;
                            }
                        }
                    }
                } else {
                    return NULL;
                }
                // let's do a bulk add
                if (count($localplaylist) > 0) {
                    foreach ($localplaylist as $plentry) {
                        $bulkadd[] = $plentry['file'];
                    }
                }
                $mpd->PLAddBulk($bulkadd);
                // Get the playlist and then generate HTML for this playlist
                // the reason we grab the playlist is that we need the songIDs
                // that were assigned by mpd.
                $items = '';
                $output = array();
                if (count($localplaylist) > 0) {
                    $nummpdsongs = count($mpd->playlist);
                    foreach ($localplaylist as $localplentry) {
                        // find our track in the playlist to get its song ID
                        // use small optimization to make sure we don't have to
                        // search from start of the list every time
                        $idx = 0;
                        $last_idx = 0;
                        $found = false;
                        if ($nummpdsongs > 0) {
                            do {
                                if ($mpd->playlist[$idx]['file'] == $localplentry['file']) {
                                    // got one, generate HTML for it
                                    $foundtrack = $mpd->playlist[$idx];
                                    $artist = $foundtrack['Artist'];
                                    $album = $foundtrack['Album'];
                                    $title = $foundtrack['Title'];
                                    $trackno = $foundtrack['Track'];
                                    $sec = (int) ($foundtrack['Time'] % 60);
                                    $min = (int) ($foundtrack['Time'] / 60);
                                    $length = $min . ":" . ($sec < 10 ? "0" : "") . $sec;
                                    $file = $foundtrack['File'];
                                    $id = $foundtrack['Id'];
                                    $output[] = 'pl' . $id;
                                    $items .= "<li id=\"pl{$id}\" onmouseover=\"setBgcolor('pl" . $id . "','#FCF7A5'); return false;\" onmouseout=\"setBgcolor('pl" . $id . "','#f3f3f3'); return false;\"><a href=\"#\" onclick=\"movePLItem('up',this.parentNode); return false;\" title=\"Move Song Up in Playlist\"><img src=\"img/up.gif\" /></a> <a href=\"#\" onclick=\"movePLItem('down',this.parentNode); return false;\" title=\"Move Song Down in Playlist\"><img src=\"img/down.gif\" /></a> <a href=\"#\" onclick=\"plrem(this.parentNode.id); return false;\" title=\"Remove Song from Playlist\"><img src=\"img/rem.gif\" /></a> {$artist} - {$title}<p>Album: {$album}<br/>Track: {$trackno}<br/>{$length}</p></li>";
                                    // administrative
                                    $lastidx = $idx;
                                    $found = true;
                                }
                                // try next entry, wraparound if necessary
                                $idx++;
                                if ($idx == $nummpdsongs) {
                                    $idx = 0;
                                }
                            } while ($idx != $last_idx && !$found);
                            // if we didn't find it... well tough!
                        }
                    }
                }
                $text[] = $items;
                $num[] = count($output);
                $text = array_merge($text, $num);
                $output = array_merge($text, $output);
                return $output;
            case 'playlist':
                // we're passed a playlist ID to load
                $playlists = $mpd->GetPlaylists();
                $pnum = count($playlists);
                if ($itemid >= 0 && $itemid < $pnum) {
                    $pname = $playlists[$itemid];
                    // load it
                    $mpd->PLClear();
                    // clear previous playlist first
                    $mpd->PLLoad($pname);
                }
                $output[0] = 1;
                return $output;
        }
    } else {
        mp3act_connect();
        switch ($type) {
            case 'song':
                $query = "INSERT INTO mp3act_playlist VALUES (NULL,{$itemid},{$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                mysql_query($query);
                $id = mysql_insert_id();
                $query = "SELECT mp3act_artists.artist_name, mp3act_artists.prefix,mp3act_albums.album_name,SEC_TO_TIME(mp3act_songs.length) AS length,mp3act_songs.name,mp3act_songs.track FROM mp3act_artists,mp3act_songs,mp3act_albums WHERE mp3act_songs.song_id={$itemid} AND mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_albums.album_id=mp3act_songs.album_id";
                $result = mysql_query($query);
                $row = mysql_fetch_array($result);
                $output[] = "<li id=\"pl{$id}\" onmouseover=\"setBgcolor('pl" . $id . "','#FCF7A5'); return false;\" onmouseout=\"setBgcolor('pl" . $id . "','#f3f3f3'); return false;\"><a href=\"#\" onclick=\"movePLItem('up',this.parentNode); return false;\" title=\"Move Song Up in Playlist\"><img src=\"img/up.gif\" /></a> <a href=\"#\" onclick=\"movePLItem('down',this.parentNode); return false;\" title=\"Move Song Down in Playlist\"><img src=\"img/down.gif\" /></a> <a href=\"#\" onclick=\"plrem(this.parentNode.id); return false;\" title=\"Remove Song from Playlist\"><img src=\"img/rem.gif\" /></a> {$row['prefix']} {$row['artist_name']} - {$row['name']}<p>Album: {$row['album_name']}<br/>Track: {$row['track']}<br/>{$row['length']}</p></li>";
                $output[] = 1;
                $output[] = 'pl' . $id;
                return $output;
            case 'album':
                $items = '';
                $output = array();
                $query = "SELECT mp3act_songs.song_id,mp3act_songs.name,mp3act_artists.artist_name,mp3act_artists.prefix,mp3act_albums.album_name,SEC_TO_TIME(mp3act_songs.length) AS length,mp3act_songs.name,mp3act_songs.track FROM mp3act_songs,mp3act_artists,mp3act_albums WHERE mp3act_songs.album_id={$itemid} AND mp3act_songs.artist_id=mp3act_artists.artist_id AND mp3act_albums.album_id=mp3act_songs.album_id ORDER BY track";
                $result = mysql_query($query);
                while ($row = mysql_fetch_array($result)) {
                    $query = "INSERT INTO mp3act_playlist VALUES(NULL," . $row['song_id'] . "," . $_SESSION['sess_userid'] . "," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                    mysql_query($query);
                    $id = mysql_insert_id();
                    $output[] = 'pl' . $id;
                    $items .= "<li id=\"pl{$id}\" onmouseover=\"setBgcolor('pl" . $id . "','#FCF7A5'); return false;\" onmouseout=\"setBgcolor('pl" . $id . "','#f3f3f3'); return false;\"><a href=\"#\" onclick=\"movePLItem('up',this.parentNode); return false;\" title=\"Move Song Up in Playlist\"><img src=\"img/up.gif\" /></a> <a href=\"#\" onclick=\"movePLItem('down',this.parentNode); return false;\" title=\"Move Song Down in Playlist\"><img src=\"img/down.gif\" /></a> <a href=\"#\" onclick=\"plrem(this.parentNode.id); return false;\" title=\"Remove Song from Playlist\"><img src=\"img/rem.gif\" /></a> {$row['prefix']} {$row['artist_name']} - {$row['name']}<p>Album: {$row['album_name']}<br/>Track: {$row['track']}<br/>{$row['length']}</p></li>";
                }
                $text[] = $items;
                $num[] = count($output);
                $text = array_merge($text, $num);
                $output = array_merge($text, $output);
                return $output;
            case 'playlist':
                clearPlaylist();
                $query = "SELECT * FROM mp3act_saved_playlists WHERE playlist_id={$itemid} LIMIT 1";
                $result = mysql_query($query);
                $row = mysql_fetch_array($result);
                $songs = explode(",", $row['playlist_songs']);
                foreach ($songs as $song) {
                    $query = "INSERT INTO mp3act_playlist VALUES(NULL,{$song},{$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                    mysql_query($query);
                }
                $output[0] = 1;
                return $output;
        }
    }
}
Пример #2
0
function playlist_add($type, $itemid)
{
    mp3act_connect();
    // get new id
    $query = "select count(*) as id from mp3act_playlist where " . playlistCondition();
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    $id = $row['id'];
    switch ($type) {
        case 'song':
            $query = "INSERT INTO mp3act_playlist VALUES ({$id},{$itemid},{$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
            mysql_query($query);
            $query = "SELECT mp3act_artists.artist_name, mp3act_artists.prefix,mp3act_albums.album_name,SEC_TO_TIME(mp3act_songs.length) AS length,mp3act_songs.name,mp3act_songs.track FROM mp3act_artists,mp3act_songs,mp3act_albums WHERE mp3act_songs.song_id={$itemid} AND mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_albums.album_id=mp3act_songs.album_id";
            $result = mysql_query($query);
            $row = mysql_fetch_array($result);
            $row['pl_id'] = $id;
            $output[] = createSongLI($row);
            $output[] = 1;
            $output[] = "pl{$id}";
            return $output;
            break;
        case 'album':
            $items = '';
            $output = array();
            $query = "SELECT mp3act_songs.song_id,mp3act_songs.name,mp3act_artists.artist_name,mp3act_artists.prefix,mp3act_albums.album_name,SEC_TO_TIME(mp3act_songs.length) AS length,mp3act_songs.name,mp3act_songs.track FROM mp3act_songs,mp3act_artists,mp3act_albums WHERE mp3act_songs.album_id={$itemid} AND mp3act_songs.artist_id=mp3act_artists.artist_id AND mp3act_albums.album_id=mp3act_songs.album_id ORDER BY track";
            $result = mysql_query($query);
            while ($row = mysql_fetch_array($result)) {
                $query = "INSERT INTO mp3act_playlist VALUES({$id}," . $row['song_id'] . "," . $_SESSION['sess_userid'] . "," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                mysql_query($query) or $items .= "Query ({$query}) failed: " . mysql_error();
                $output[] = "pl{$id}";
                $row['pl_id'] = $id;
                $items .= createSongLI($row);
                $id++;
            }
            $text[] = $items;
            $num[] = count($output);
            $text = array_merge($text, $num);
            $output = array_merge($text, $output);
            return $output;
            break;
        case 'playlist':
            clearPlaylist();
            $id = 0;
            $query = "SELECT * FROM mp3act_saved_playlists WHERE playlist_id={$itemid} LIMIT 1";
            $result = mysql_query($query);
            $row = mysql_fetch_array($result);
            $songs = explode(",", $row['playlist_songs']);
            foreach ($songs as $song) {
                $query = "INSERT INTO mp3act_playlist VALUES({$id},{$song},{$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                mysql_query($query);
                $id++;
            }
            $output[0] = 1;
            return $output;
            break;
    }
}
Пример #3
0
function getPlaylist($parameter)
{
    //retrait du parametre u pour réduire la taille du buffer
    $request = $_SESSION['mac'] . " status 0 10000 playlist_id:{$parameter} tags:agl\n";
    //echo "contenu requete getPlaylsit: $request";
    $mySqueezeCLI = new SqueezeCLI($request);
    $response = $mySqueezeCLI->receiveCLI();
    //echo "la reponse brut: $response \n";
    $response = decodeAscii($response);
    $indexPlaylist = split("playlist index:", $response);
    array_shift($indexPlaylist);
    //Clear de la variable de SESSION
    clearPlaylist();
    foreach ($indexPlaylist as $key => $value) {
        $id = get_string_between($indexPlaylist[$key], "id:", " title");
        $title = get_string_between($indexPlaylist[$key], "title:", " artist:");
        $artist = get_string_between($indexPlaylist[$key], "artist:", " genre:");
        $genre = get_string_between($indexPlaylist[$key], "genre:", " album:");
        $album = get_string_between($indexPlaylist[$key], "album:", " url:");
        $url = substr($indexPlaylist[$key], strrpos($indexPlaylist[$key], " url:"));
        $url = substr($url, 5);
        //echo "contenu de url: $url \n";
        // Attention ici est sauvegardée en session les url des titres de la current playlist, ils seront utilisés pour faire une copie de la playlist
        $_SESSION['currentPlaylist'][$key] = $url;
        echo "<ul class=\"title\" id=\"{$id}\">";
        echo "<li id=\"{$title}\">{$title}</li>";
        echo "<li id=\"{$artist}\">{$artist}</li>";
        echo "<li id=\"{$genre}\">{$genre}</li>";
        echo "<li id=\"{$album}\">{$album}</li>";
        echo "<img class=\"buttonDeleteTitle\" id=\"\" src=\"1_music/view/images/player/delete.png\">";
        echo "</ul>";
    }
}
Пример #4
0
                                     }
                                 } else {
                                     if ($setting[0] == "Open") {
                                         exec("open \"{$setting['1']}\"");
                                         return;
                                     } else {
                                         if ($setting[0] == "Reveal") {
                                             exec("open -R \"{$setting['1']}\"");
                                             return;
                                         } else {
                                             if ($setting[0] == "CLEAR_ALFRED_PLAYLIST") {
                                                 if ($setting[1] == "" || $setting[2] == "") {
                                                     displayNotificationWithArtwork("Alfred Playlist is not set", './images/warning.png', 'Error!');
                                                     return;
                                                 }
                                                 if (clearPlaylist($w, $setting[1], $setting[2])) {
                                                     displayNotificationWithArtwork('Alfred Playlist ' . $setting[2] . ' was cleared', getPlaylistArtwork($w, $setting[1], true), 'Clear Alfred Playlist');
                                                 }
                                                 return;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #5
0
function playlist_add($type, $itemid)
{
    mp3act_connect();
    switch ($type) {
        case 'song':
            $query = "INSERT INTO mp3act_playlist VALUES (NULL,{$itemid},{$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
            mysql_query($query);
            $id = mysql_insert_id();
            $query = "SELECT mp3act_artists.artist_name, mp3act_artists.prefix,mp3act_albums.album_name,SEC_TO_TIME(mp3act_songs.length) AS length,mp3act_songs.name,mp3act_songs.track FROM mp3act_artists,mp3act_songs,mp3act_albums WHERE mp3act_songs.song_id={$itemid} AND mp3act_artists.artist_id=mp3act_songs.artist_id AND mp3act_albums.album_id=mp3act_songs.album_id";
            $result = mysql_query($query);
            $row = mysql_fetch_array($result);
            $output[] = "<li id=\"pl{$id}\" onmouseover=\"setBgcolor('pl" . $id . "','#FCF7A5'); return false;\" onmouseout=\"setBgcolor('pl" . $id . "','#f3f3f3'); return false;\"><a href=\"#\" onclick=\"movePLItem('up',this.parentNode); return false;\" title=\"Move Song Up in Playlist\"><img src=\"img/up.gif\" /></a> <a href=\"#\" onclick=\"movePLItem('down',this.parentNode); return false;\" title=\"Move Song Down in Playlist\"><img src=\"img/down.gif\" /></a> <a href=\"#\" onclick=\"plrem(this.parentNode.id); return false;\" title=\"Remove Song from Playlist\"><img src=\"img/rem.gif\" /></a> {$row['prefix']} {$row['artist_name']} - {$row['name']}<p>Album: {$row['album_name']}<br/>Track: {$row['track']}<br/>{$row['length']}</p></li>";
            $output[] = 1;
            $output[] = 'pl' . $id;
            return $output;
            break;
        case 'album':
            $items = '';
            $output = array();
            $query = "SELECT mp3act_songs.song_id,mp3act_songs.name,mp3act_artists.artist_name,mp3act_artists.prefix,mp3act_albums.album_name,SEC_TO_TIME(mp3act_songs.length) AS length,mp3act_songs.name,mp3act_songs.track FROM mp3act_songs,mp3act_artists,mp3act_albums WHERE mp3act_songs.album_id={$itemid} AND mp3act_songs.artist_id=mp3act_artists.artist_id AND mp3act_albums.album_id=mp3act_songs.album_id ORDER BY track";
            $result = mysql_query($query);
            while ($row = mysql_fetch_array($result)) {
                $query = "INSERT INTO mp3act_playlist VALUES(NULL," . $row['song_id'] . "," . $_SESSION['sess_userid'] . "," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                mysql_query($query);
                $id = mysql_insert_id();
                $output[] = 'pl' . $id;
                $items .= "<li id=\"pl{$id}\" onmouseover=\"setBgcolor('pl" . $id . "','#FCF7A5'); return false;\" onmouseout=\"setBgcolor('pl" . $id . "','#f3f3f3'); return false;\"><a href=\"#\" onclick=\"movePLItem('up',this.parentNode); return false;\" title=\"Move Song Up in Playlist\"><img src=\"img/up.gif\" /></a> <a href=\"#\" onclick=\"movePLItem('down',this.parentNode); return false;\" title=\"Move Song Down in Playlist\"><img src=\"img/down.gif\" /></a> <a href=\"#\" onclick=\"plrem(this.parentNode.id); return false;\" title=\"Remove Song from Playlist\"><img src=\"img/rem.gif\" /></a> {$row['prefix']} {$row['artist_name']} - {$row['name']}<p>Album: {$row['album_name']}<br/>Track: {$row['track']}<br/>{$row['length']}</p></li>";
            }
            $text[] = $items;
            $num[] = count($output);
            $text = array_merge($text, $num);
            $output = array_merge($text, $output);
            return $output;
            break;
        case 'playlist':
            clearPlaylist();
            $query = "SELECT * FROM mp3act_saved_playlists WHERE playlist_id={$itemid} LIMIT 1";
            $result = mysql_query($query);
            $row = mysql_fetch_array($result);
            $songs = explode(",", $row['playlist_songs']);
            foreach ($songs as $song) {
                $query = "INSERT INTO mp3act_playlist VALUES(NULL,{$song},{$_SESSION['sess_userid']}," . ($_SESSION['sess_playmode'] == "streaming" ? 1 : 0) . ")";
                mysql_query($query);
            }
            $output[0] = 1;
            return $output;
            break;
    }
}
function playlist_add($type, $itemid)
{
    global $db;
    $output = array(0 => '', 1 => 0);
    if ('loadplaylist' == $type) {
        clearPlaylist();
        setcookie('mp3act_playlist_id', $itemid, time() + MYTH_PLAYLIST_SAVE_TIME);
        $output[0] = 1;
        return $output;
    }
    $pl = internalGetPlaylist();
    if (empty($pl['playlist_songs'])) {
        $songs = array();
        $new_length = 0;
        $new_songcount = 0;
    } else {
        $songs = explode(',', $pl['playlist_songs']);
        $new_length = $pl['length_in_secs'];
        $new_songcount = $pl['songcount'];
    }
    if ('playlist' == $type) {
        if (!empty($pl['playlist_id'])) {
            if (!internalPlaylistAddPlaylistCheck($pl['playlist_id'], $itemid)) {
                // Some sort of nasty circular dependency.
                $output[0] = 2;
                $output[1] = t('Sorry, but you cannot add this playlist as it would create a circular dependency.');
                return $output;
            }
        }
        $pl_add = internalGetPlaylist($itemid);
        if (empty($pl_add['playlist_id'])) {
            $output[0] = 2;
            $output[1] = t('An error occurred while adding your playlist.');
            return $output;
        }
        $new_songcount += $pl_add['songcount'];
        $new_length += $pl_add['length_in_secs'];
        $songs[] = -1 * $itemid;
        $id = md5(-1 * $itemid . mt_rand());
        $output[0] .= getHtmlPlaylistEntryPlaylist($id, $pl_add['playlist_name'], $pl_add['songcount'], $pl_add['length']);
        $output[1]++;
        $output[] = 'pl' . $id;
        internalUpdatePlaylist($songs, $new_songcount, $new_length);
        return $output;
    }
    $sql_itemid = $db->escape($itemid);
    $query = 'SELECT ms.song_id, mt.artist_name, ma.album_name,' . ' length AS length_in_secs, SEC_TO_TIME(ms.length/1000) AS length, ms.name, ms.track ' . 'FROM music_songs AS ms ' . 'LEFT JOIN music_artists AS mt ON ms.artist_id=mt.artist_id ' . 'LEFT JOIN music_albums AS ma ON ms.album_id=ma.album_id ' . 'WHERE ';
    switch ($type) {
        case 'song':
            $query .= 'ms.song_id=' . $sql_itemid;
            break;
        case 'album':
            $query .= 'ms.album_id=' . $sql_itemid;
            break;
        default:
            return $output;
    }
    $sh = $db->query($query . ' ORDER BY ms.track');
    if (!$sh) {
        return $output;
    }
    while ($row = $sh->fetch_array()) {
        $id = md5($row['song_id'] . mt_rand());
        $output[0] .= getHtmlPlaylistEntrySong($id, $row['artist_name'], $row['album_name'], $row['track'], $row['name'], $row['length']);
        $output[1]++;
        $output[] = 'pl' . $id;
        $songs[] = $row['song_id'];
        $new_length += $row['length_in_secs'];
        $new_songcount++;
    }
    $sh->finish();
    internalUpdatePlaylist($songs, $new_songcount, $new_length);
    return $output;
}