コード例 #1
0
ファイル: menu.php プロジェクト: jfloff/.dotfiles
/**
 * mainMenu function.
 *
 * @access public
 * @param mixed $w
 * @param mixed $query
 * @param mixed $settings
 * @param mixed $db
 * @param mixed $update_in_progress
 * @return void
 */
function mainMenu($w, $query, $settings, $db, $update_in_progress)
{
    $words = explode('▹', $query);
    $kind = $words[0];
    $all_playlists = $settings->all_playlists;
    $is_alfred_playlist_active = $settings->is_alfred_playlist_active;
    $radio_number_tracks = $settings->radio_number_tracks;
    $now_playing_notifications = $settings->now_playing_notifications;
    $max_results = $settings->max_results;
    $alfred_playlist_uri = $settings->alfred_playlist_uri;
    $alfred_playlist_name = $settings->alfred_playlist_name;
    $country_code = $settings->country_code;
    $last_check_update_time = $settings->last_check_update_time;
    $oauth_client_id = $settings->oauth_client_id;
    $oauth_client_secret = $settings->oauth_client_secret;
    $oauth_redirect_uri = $settings->oauth_redirect_uri;
    $oauth_access_token = $settings->oauth_access_token;
    $oauth_expires = $settings->oauth_expires;
    $oauth_refresh_token = $settings->oauth_refresh_token;
    $display_name = $settings->display_name;
    $userid = $settings->userid;
    $echonest_api_key = $settings->echonest_api_key;
    $quick_mode = $settings->quick_mode;
    ////////
    //
    // MAIN MENU
    //////////////
    $getCounters = 'select * from counters';
    try {
        $stmt = $db->prepare($getCounters);
        $counters = $stmt->execute();
        $counter = $stmt->fetch();
    } catch (PDOException $e) {
        handleDbIssuePdoXml($db);
        return;
    }
    $all_tracks = $counter[0];
    $yourmusic_tracks = $counter[1];
    $all_artists = $counter[2];
    $yourmusic_artists = $counter[3];
    $all_albums = $counter[4];
    $yourmusic_albums = $counter[5];
    $nb_playlists = $counter[6];
    if ($update_in_progress == true) {
        $in_progress_data = $w->read('update_library_in_progress');
        $update_library_in_progress_words = explode('▹', $in_progress_data);
        $elapsed_time = time() - $update_library_in_progress_words[3];
        if (startsWith($update_library_in_progress_words[0], 'Init')) {
            $w->result(null, $w->data() . '/update_library_in_progress', 'Initialization phase since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(0), 'Waiting for Spotify servers to return required data', './images/update_in_progress.png', 'no', null, '');
        } else {
            if ($update_library_in_progress_words[0] == 'Refresh Library') {
                $type = 'playlists';
            } elseif ($update_library_in_progress_words[0] == 'Artists') {
                $type = 'artists';
            } else {
                $type = 'tracks';
            }
            if ($update_library_in_progress_words[2] != 0) {
                $w->result(null, $w->data() . '/update_library_in_progress', $update_library_in_progress_words[0] . ' update in progress since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(intval($update_library_in_progress_words[1]) / intval($update_library_in_progress_words[2])), $update_library_in_progress_words[1] . '/' . $update_library_in_progress_words[2] . ' ' . $type . ' processed so far. Currently processing <' . $update_library_in_progress_words[4] . '>', './images/update_in_progress.png', 'no', null, '');
            } else {
                $w->result(null, $w->data() . '/update_library_in_progress', $update_library_in_progress_words[0] . ' update in progress since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(0), 'No ' . $type . ' processed so far', './images/update_in_progress.png', 'no', null, '');
            }
        }
    }
    $quick_mode_text = '';
    if ($quick_mode) {
        $quick_mode_text = ' ● ⚡ Quick Mode is active';
    }
    if ($all_playlists == true) {
        $w->result(null, '', 'Search for music in "Your Music" and your ' . $nb_playlists . ' playlists', 'Begin typing at least 3 characters to start search in your ' . $all_tracks . ' tracks' . $quick_mode_text, './images/search.png', 'no', null, '');
    } else {
        $w->result(null, '', 'Search for music in "Your Music" only', 'Begin typing at least 3 characters to start search in your ' . $yourmusic_tracks . ' tracks' . $quick_mode_text, './images/search_scope_yourmusic_only.png', 'no', null, '');
    }
    $w->result(null, '', 'Current Track', 'Display current track information and browse various options', './images/current_track.png', 'no', null, 'Current Track▹');
    $w->result(null, '', 'Play Queue', 'Get the current play queue. Always use the workflow to launch tracks, otherwise play queue will be empty', './images/play_queue.png', 'no', null, 'Play Queue▹');
    $w->result(null, serialize(array('', '', '', '', '', '', '', 'lookup_current_artist', '', '', '', '', '', '', '', '')), 'Lookup Current Artist online', array('☁︎ Query all albums/tracks from current artist online..', 'alt' => 'Not Available', 'cmd' => 'Not Available', 'shift' => 'Not Available', 'fn' => 'Not Available', 'ctrl' => 'Not Available'), './images/online_artist.png', 'yes', '');
    $w->result(null, '', 'Search online', '☁︎ You can search tracks, artists, albums and playlists online, i.e not in your library', './images/online.png', 'no', null, 'Search Online▹');
    if ($is_alfred_playlist_active == true) {
        if ($alfred_playlist_name != "") {
            $title = 'Alfred Playlist ● ' . $alfred_playlist_name;
            $w->result(null, '', $title, 'Choose one of your playlists and add tracks, album, playlist to it directly from the workflow', './images/alfred_playlist.png', 'no', null, 'Alfred Playlist▹');
        } else {
            $title = 'Alfred Playlist ● not set';
            $w->result(null, '', $title, 'Choose one of your playlists and add tracks, album, playlist to it directly from the workflow', './images/alfred_playlist.png', 'no', null, 'Alfred Playlist▹Set Alfred Playlist▹');
        }
    }
    $w->result(null, '', 'Playlists', 'Browse by playlist' . ' (' . $nb_playlists . ' playlists)', './images/playlists.png', 'no', null, 'Playlist▹');
    $w->result(null, '', 'Your Music', 'Browse Your Music' . ' (' . $yourmusic_tracks . ' tracks ● ' . $yourmusic_albums . '  albums ● ' . $yourmusic_artists . ' artists)', './images/yourmusic.png', 'no', null, 'Your Music▹');
    if ($all_playlists == true) {
        $w->result(null, '', 'Artists', 'Browse by artist' . ' (' . $all_artists . ' artists)', './images/artists.png', 'no', null, 'Artist▹');
        $w->result(null, '', 'Albums', 'Browse by album' . ' (' . $all_albums . ' albums)', './images/albums.png', 'no', null, 'Album▹');
    } else {
        $w->result(null, '', 'Artists in "Your Music"', 'Browse by artist' . ' (' . $yourmusic_artists . ' artists)', './images/artists.png', 'no', null, 'Artist▹');
        $w->result(null, '', 'Albums in "Your Music"', 'Browse by album' . ' (' . $yourmusic_albums . ' albums)', './images/albums.png', 'no', null, 'Album▹');
    }
    //$w->result(null, '', 'Charts', 'Browse charts', './images/numbers.png', 'no', null, 'Charts▹');
    $w->result(null, '', 'Browse', 'Browse Spotify by categories, as in the Spotify player’s “Browse” tab', './images/browse.png', 'no', null, 'Browse▹');
    if ($is_alfred_playlist_active == true) {
        $alfred_playlist_state = 'Alfred Playlist';
    } else {
        $alfred_playlist_state = 'Your Music';
    }
    if ($all_playlists == true) {
        $w->result(null, '', 'Settings', 'User='******', Search scope=<All>, Max results=<' . $max_results . '>, Controlling <' . $alfred_playlist_state . '>, Radio tracks=<' . $radio_number_tracks . '>', './images/settings.png', 'no', null, 'Settings▹');
    } else {
        $w->result(null, '', 'Settings', 'User='******', Search scope=<Your Music>, Max results=<' . $max_results . '>, Controlling <' . $alfred_playlist_state . '>, Radio tracks=<' . $radio_number_tracks . '>', './images/settings.png', 'no', null, 'Settings▹');
    }
}
コード例 #2
0
ファイル: main.php プロジェクト: bycEEE/env
        echo $w->toxml();
        return;
    }
}
//
// check for download artworks in progress
$download_artworks_in_progress = false;
if (file_exists($w->data() . '/download_artworks_in_progress')) {
    $in_progress_data = $w->read('download_artworks_in_progress');
    $download_artworks_in_progress_words = explode('▹', $in_progress_data);
    $elapsed_time = time() - $download_artworks_in_progress_words[3];
    $download_artworks_in_progress = true;
    if ($download_artworks_in_progress_words[2] != 0) {
        $w->result(null, $w->data() . '/download_artworks_in_progress', $download_artworks_in_progress_words[0] . ' in progress since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(intval($download_artworks_in_progress_words[1]) / intval($download_artworks_in_progress_words[2])), $download_artworks_in_progress_words[1] . '/' . $download_artworks_in_progress_words[2] . ' artworks processed so far (empty artworks can be seen until full download is complete)', './images/artworks.png', 'no', null, '');
    } else {
        $w->result(null, $w->data() . '/download_artworks_in_progress', $download_artworks_in_progress_words[0] . ' in progress since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(0), 'No artwork processed so far (empty artworks can be seen until full download is complete)', './images/artworks.png', 'no', null, '');
    }
}
//
// Read settings from JSON
//
$settings = getSettings($w);
$all_playlists = $settings->all_playlists;
$is_alfred_playlist_active = $settings->is_alfred_playlist_active;
$radio_number_tracks = $settings->radio_number_tracks;
$now_playing_notifications = $settings->now_playing_notifications;
$max_results = $settings->max_results;
$alfred_playlist_uri = $settings->alfred_playlist_uri;
$alfred_playlist_name = $settings->alfred_playlist_name;
$country_code = $settings->country_code;
$last_check_update_time = $settings->last_check_update_time;