/** * save_songplay * This takes care of queueing and then submitting the tracks. */ public function save_songplay($song) { // Before we start let's pull the last song submitted by this user $previous = Stats::get_last_song($this->user_id); $diff = time() - $previous['date']; // Make sure it wasn't within the last min if ($diff < 60) { debug_event($this->name, 'Last song played within ' . $diff . ' seconds, not recording stats', '3'); return false; } if ($song->time < 30) { debug_event($this->name, 'Song less then 30 seconds not queueing', '3'); return false; } // Make sure there's actually a username and password before we keep going if (!$this->username || !$this->password) { debug_event($this->name, 'Username or password missing', '3'); return false; } // Create our scrobbler with everything this time and then queue it $scrobbler = new scrobbler($this->username, $this->password, $this->hostname, $this->port, $this->path, $this->challenge, 'turtle.libre.fm'); // Check to see if the scrobbling works if (!$scrobbler->queue_track($song->f_artist_full, $song->f_album_full, $song->title, time(), $song->time, $song->track)) { // Depending on the error we might need to do soemthing here return false; } // Go ahead and submit it now if (!$scrobbler->submit_tracks()) { debug_event($this->name, 'Error Submit Failed: ' . $scrobbler->error_msg, '3'); if ($scrobbler->reset_handshake) { debug_event($this->name, 'Re-running Handshake due to error', '1'); $this->set_handshake($this->user_id); // Try try again if ($scrobbler->submit_tracks()) { return true; } } return false; } debug_event($this->name, 'Submission Successful', '5'); return true; }
/** * save_songplay * This takes care of queueing and then submitting the tracks. */ public function save_mediaplay($song) { // Only support songs if (strtolower(get_class($song)) != 'song') { return false; } // Make sure there's actually a session before we keep going if (!$this->challenge) { debug_event($this->name, 'Session key missing', '5'); return false; } // Let's pull the last song submitted by this user $previous = Stats::get_last_song($this->user_id); $diff = time() - $previous['date']; // Make sure it wasn't within the last min if ($diff < 60) { debug_event($this->name, 'Last song played within ' . $diff . ' seconds, not recording stats', '3'); return false; } if ($song->time < 30) { debug_event($this->name, 'Song less then 30 seconds not queueing', '3'); return false; } // Create our scrobbler and then queue it $scrobbler = new scrobbler($this->api_key, $this->scheme, $this->api_host, $this->challenge, $this->secret); // Check to see if the scrobbling works by queueing song if (!$scrobbler->queue_track($song->f_artist_full, $song->f_album_full, $song->title, time(), $song->time, $song->track)) { return false; } // Go ahead and submit it now if (!$scrobbler->submit_tracks()) { debug_event($this->name, 'Error Submit Failed: ' . $scrobbler->error_msg, '3'); return false; } debug_event($this->name, 'Submission Successful', '5'); return true; }
/** * save_songplay * This takes care of queueing and then submitting the tracks. */ public function save_mediaplay($song) { // Only support songs if (strtolower(get_class($song)) != 'song') { return false; } // Before we start let's pull the last song submitted by this user $previous = Stats::get_last_song($this->user_id); $user = new User($this->user_id); $diff = time() - $previous['date']; // Make sure it wasn't within the last 10sec if ($diff < 10) { debug_event($this->name, 'Last song played within ' . $diff . ' seconds, not recording stats', '3'); return false; } // Make sure there's actually a server address before we keep going if (!$this->address) { debug_event($this->name, 'Server address missing', '3'); return false; } $message = str_replace("%user", $user->fullname, $this->message); $message = str_replace("%artist", $song->f_artist_full, $message); $message = str_replace("%album", $song->f_album_full, $message); $message = str_replace("%title", $song->title, $message); $growl = $this->get_growl(); $growl->notify('Now Playing', $message); debug_event($this->name, 'Submission Successful', '5'); return true; }