Ejemplo n.º 1
0
/**
 * addCurrentTrackToYourMusic function.
 *
 * @access public
 * @param mixed $w
 * @return void
 */
function addCurrentTrackToYourMusic($w)
{
    // get info on current song
    exec("./src/track_info.ksh 2>&1", $retArr, $retVal);
    if ($retVal != 0) {
        displayNotificationWithArtwork('AppleScript Exception: ' . htmlspecialchars($retArr[0]) . ' use spot_mini_debug command', './images/warning.png', 'Error!');
        exec("osascript -e 'tell application \"Alfred 2\" to search \"spot_mini_debug AppleScript Exception: " . htmlspecialchars($retArr[0]) . "\"'");
        return;
    }
    if (isset($retArr[0]) && substr_count($retArr[0], '▹') > 0) {
        $results = explode('▹', $retArr[0]);
        $tmp = explode(':', $results[4]);
        if ($tmp[1] == 'local') {
            //
            // Read settings from JSON
            //
            $settings = getSettings($w);
            $country_code = $settings->country_code;
            // local track, look it up online
            $query = 'track:' . strtolower(escapeQuery($results[0])) . ' artist:' . strtolower(escapeQuery($results[1]));
            $searchResults = searchWebApi($w, $country_code, $query, 'track', 1);
            if (count($searchResults) > 0) {
                // only one track returned
                $track = $searchResults[0];
                $artists = $track->artists;
                $artist = $artists[0];
                $album = $track->album;
                logMsg("Unknown track {$results['4']} / {$results['0']} / {$results['1']} replaced by track: {$track->uri} / {$track->name} / {$artist->name} / {$album->uri}");
                $results[4] = $track->uri;
            } else {
                logMsg("Could not find track: {$results['4']} / {$results['0']} / {$results['1']} ");
                displayNotificationWithArtwork('Local track ' . escapeQuery($results[0]) . ' has not online match', './images/warning.png', 'Error!');
                return;
            }
        }
        $tmp = explode(':', $results[4]);
        $ret = addTracksToYourMusic($w, $tmp[2], false);
        if (is_numeric($ret) && $ret > 0) {
            displayNotificationWithArtwork('' . escapeQuery($results[0]) . ' by ' . escapeQuery($results[1]) . ' added to Your Music', getTrackOrAlbumArtwork($w, $results[4], true), 'Add Current Track to Your Music');
        } elseif (is_numeric($ret) && $ret == 0) {
            displayNotificationWithArtwork('' . escapeQuery($results[0]) . ' by ' . escapeQuery($results[1]) . ' is already in Your Music', './images/warning.png');
        }
    } else {
        displayNotificationWithArtwork("No track is playing", './images/warning.png', 'Error!');
    }
}
Ejemplo n.º 2
0
         $ret = addTracksToYourMusic($w, getThePlaylistTracks($w, $playlist_uri), false);
         if ($userid != 'vdesabou') {
             stathat_ez_count('AlfredSpotifyMiniPlayer', 'add_or_remove', 1);
         }
         if (is_numeric($ret) && $ret > 0) {
             displayNotificationWithArtwork('Playlist ' . $playlist_name . ' added to Your Music', $playlist_artwork_path, 'Add Playlist to Your Music');
             return;
         } else {
             if (is_numeric($ret) && $ret == 0) {
                 displayNotificationWithArtwork('Playlist ' . $playlist_name . ' is already in Your Music', './images/warning.png', 'Error!');
                 return;
             }
         }
     } elseif ($album_uri != '') {
         $album_artwork_path = getTrackOrAlbumArtwork($w, $album_uri, true);
         $ret = addTracksToYourMusic($w, getTheAlbumTracks($w, $album_uri), false);
         if ($userid != 'vdesabou') {
             stathat_ez_count('AlfredSpotifyMiniPlayer', 'add_or_remove', 1);
         }
         if (is_numeric($ret) && $ret > 0) {
             displayNotificationWithArtwork('Album ' . $album_name . ' added to Your Music', $album_artwork_path, 'Add Album to Your Music');
             return;
         } else {
             if (is_numeric($ret) && $ret == 0) {
                 displayNotificationWithArtwork('Album ' . $album_name . ' is already in Your Music', './images/warning.png', 'Error!');
                 return;
             }
         }
     }
 } else {
     if ($setting[0] == "REMOVE_FROM_YOUR_MUSIC") {