Example #1
0
 // STUPID IE
 $media_name = str_replace(array('?', '/', '\\'), "_", $media->f_file);
 $browser->downloadHeaders($media_name, $media->mime, false, $media->size);
 $fp = fopen(Core::conv_lc_file($media->file), 'rb');
 $bytesStreamed = 0;
 if (!is_resource($fp)) {
     debug_event('Play', "Error: Unable to open {$media->file} for downloading", '2');
     exit;
 }
 if (!$share_id) {
     if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
         debug_event('play', 'Registering download stats for {' . $media->get_stream_name() . '}...', '5');
         $sessionkey = $sid ?: Stream::get_session();
         $agent = Session::agent($sessionkey);
         $location = Session::get_geolocation($sessionkey);
         Stats::insert($type, $media->id, $uid, $agent, $location, 'download');
     }
 }
 // Check to see if we should be throttling because we can get away with it
 if (AmpConfig::get('rate_limit') > 0) {
     while (!feof($fp)) {
         echo fread($fp, round(AmpConfig::get('rate_limit') * 1024));
         $bytesStreamed += round(AmpConfig::get('rate_limit') * 1024);
         flush();
         sleep(1);
     }
 } else {
     fpassthru($fp);
 }
 fclose($fp);
 exit;
Example #2
0
 /**
  * set_played
  * this checks to see if the current object has been played
  * if not then it sets it to played. In any case it updates stats.
  * @param int $user
  * @param string $agent
  * @param array $location
  * @return boolean
  */
 public function set_played($user, $agent, $location)
 {
     Stats::insert('podcast', $this->podcast, $user, $agent, $location);
     Stats::insert('podcast_episode', $this->id, $user, $agent, $location);
     if ($this->played) {
         return true;
     }
     /* If it hasn't been played, set it! */
     Podcast_Episode::update_played(true, $this->id);
     return true;
 }
Example #3
0
 /**
  * set_played
  * this checks to see if the current object has been played
  * if not then it sets it to played. In any case it updates stats.
  * @param int $user
  * @param string $agent
  * @param array $location
  * @return boolean
  */
 public function set_played($user, $agent, $location)
 {
     Stats::insert('song', $this->id, $user, $agent, $location);
     Stats::insert('album', $this->album, $user, $agent, $location);
     Stats::insert('artist', $this->artist, $user, $agent, $location);
     if ($this->played) {
         return true;
     }
     /* If it hasn't been played, set it! */
     self::update_played(true, $this->id);
     return true;
 }
Example #4
0
 /**
  * set_played
  * this checks to see if the current object has been played
  * if not then it sets it to played. In any case it updates stats.
  * @param int $user
  * @param string $agent
  * @param array $location
  * @return boolean
  */
 public function set_played($user, $agent, $location)
 {
     Stats::insert('video', $this->id, $user, $agent, $location);
     if ($this->played) {
         return true;
     }
     /* If it hasn't been played, set it! */
     Video::update_played(true, $this->id);
     return true;
 }
Example #5
0
 /**
  * update_user_stats
  * updates the playcount mojo for this specific user
  */
 public function update_stats($song_id, $agent = '')
 {
     debug_event('user.class.php', 'Updating stats for {' . $song_id . '} {' . $agent . '}...', '5');
     $song_info = new Song($song_id);
     $song_info->format();
     $user = $this->id;
     if (!strlen($song_info->file)) {
         return false;
     }
     $this->set_preferences();
     // If pthreads available, we call save_songplay in a new thread to quickly return
     if (class_exists("Thread", false)) {
         debug_event('user.class.php', 'Calling save_songplay plugins in a new thread...', '5');
         $thread = new scrobbler_async($GLOBALS['user'], $song_info);
         if ($thread->start()) {
             //$thread->join();
         } else {
             debug_event('user.class.php', 'Error when starting the thread.', '1');
         }
     } else {
         User::save_songplay($GLOBALS['user'], $song_info);
     }
     // Do this last so the 'last played checks are correct'
     Stats::insert('song', $song_id, $user, $agent);
     Stats::insert('album', $song_info->album, $user, $agent);
     Stats::insert('artist', $song_info->artist, $user, $agent);
     return true;
 }