예제 #1
0
파일: batch.lib.php 프로젝트: nioc/ampache
/**
 * get_media_files
 *
 * Takes an array of media ids and returns an array of the actual filenames
 *
 * @param    array    $media_ids    Media IDs.
 */
function get_media_files($media_ids)
{
    $media_files = array();
    $total_size = 0;
    foreach ($media_ids as $element) {
        if (is_array($element)) {
            if (isset($element['object_type'])) {
                $type = $element['object_type'];
                $id = $element['object_id'];
            } else {
                $type = array_shift($element);
                $id = array_shift($element);
            }
            $media = new $type($id);
        } else {
            $media = new Song($element);
        }
        if ($media->enabled) {
            $media->format();
            $total_size += sprintf("%.2f", $media->size / 1048576);
            $dirname = '';
            $parent = $media->get_parent();
            if ($parent != null) {
                $pobj = new $parent['object_type']($parent['object_id']);
                $pobj->format();
                $dirname = $pobj->get_fullname();
            }
            if (!array_key_exists($dirname, $media_files)) {
                $media_files[$dirname] = array();
            }
            array_push($media_files[$dirname], Core::conv_lc_file($media->file));
        }
    }
    return array($media_files, $total_size);
}
예제 #2
0
 /**
  * Get a song waveform.
  * @param int $song_id
  * @return binary|string|null
  */
 public static function get($song_id)
 {
     $song = new Song($song_id);
     $waveform = null;
     if ($song->id) {
         $song->format();
         $waveform = $song->waveform;
         if (!$waveform) {
             $catalog = Catalog::create_from_id($song->catalog);
             if ($catalog->get_type() == 'local') {
                 $transcode_to = 'wav';
                 $transcode_cfg = AmpConfig::get('transcode');
                 $valid_types = $song->get_stream_types();
                 if ($song->type != $transcode_to) {
                     $basedir = AmpConfig::get('tmp_dir_path');
                     if ($basedir) {
                         if ($transcode_cfg != 'never' && in_array('transcode', $valid_types)) {
                             $tmpfile = tempnam($basedir, $transcode_to);
                             $tfp = fopen($tmpfile, 'wb');
                             if (!is_resource($tfp)) {
                                 debug_event('waveform', "Failed to open " . $tmpfile, 3);
                                 return null;
                             }
                             $transcoder = Stream::start_transcode($song, $transcode_to);
                             $fp = $transcoder['handle'];
                             if (!is_resource($fp)) {
                                 debug_event('waveform', "Failed to open " . $song->file . " for waveform.", 3);
                                 return null;
                             }
                             do {
                                 $buf = fread($fp, 2048);
                                 fwrite($tfp, $buf);
                             } while (!feof($fp));
                             fclose($fp);
                             fclose($tfp);
                             Stream::kill_process($transcoder);
                             $waveform = self::create_waveform($tmpfile);
                             //$waveform = self::create_waveform("C:\\tmp\\test.wav");
                             @unlink($tmpfile);
                         } else {
                             debug_event('waveform', 'transcode setting to wav required for waveform.', '3');
                         }
                     } else {
                         debug_event('waveform', 'tmp_dir_path setting required for waveform.', '3');
                     }
                 } else {
                     $waveform = self::create_waveform($song->file);
                 }
             }
             if ($waveform) {
                 self::save_to_db($song_id, $waveform);
             }
         }
     }
     return $waveform;
 }
예제 #3
0
 public static function get_current_slideshow()
 {
     $songs = Song::get_recently_played($GLOBALS['user']->id);
     $images = array();
     if (count($songs) > 0) {
         $last_song = new Song($songs[0]['object_id']);
         $last_song->format();
         $images = self::get_images($last_song->f_artist);
     }
     return $images;
 }
예제 #4
0
/**
 * get_song_files
 *
 * Takes an array of song ids and returns an array of the actual filenames
 *
 * @param    array    $media_ids    Media IDs.
 */
function get_song_files($media_ids)
{
    $media_files = array();
    $total_size = 0;
    foreach ($media_ids as $element) {
        if (is_array($element)) {
            $type = array_shift($element);
            $media = new $type(array_shift($element));
        } else {
            $media = new Song($element);
        }
        if ($media->enabled) {
            $total_size += sprintf("%.2f", $media->size / 1048576);
            $media->format();
            $dirname = $media->f_album_full;
            //debug_event('batch.lib.php', 'Songs file {'.$media->file.'}...', '5');
            if (!array_key_exists($dirname, $media_files)) {
                $media_files[$dirname] = array();
            }
            array_push($media_files[$dirname], $media->file);
        }
    }
    return array($media_files, $total_size);
}
예제 #5
0
 /**
  * Get media javascript parameters.
  * @param \playable_item $item
  * @param string $force_type
  * @return string
  */
 public static function get_media_js_param($item, $force_type = '')
 {
     $js = array();
     foreach (array('title', 'author') as $member) {
         if ($member == "author") {
             $kmember = "artist";
         } else {
             $kmember = $member;
         }
         $js[$kmember] = $item->{$member};
     }
     $url = $item->url;
     $types = self::get_types($item, $force_type);
     $media = null;
     $urlinfo = Stream_URL::parse($url);
     $url = $urlinfo['base_url'];
     if ($urlinfo['id'] && Core::is_media($urlinfo['type'])) {
         $media = new $urlinfo['type']($urlinfo['id']);
     } else {
         if ($urlinfo['id'] && $urlinfo['type'] == 'song_preview') {
             $media = new Song_Preview($urlinfo['id']);
         } else {
             if (isset($urlinfo['demo_id'])) {
                 $democratic = new Democratic($urlinfo['demo_id']);
                 if ($democratic->id) {
                     $song_id = $democratic->get_next_object();
                     if ($song_id) {
                         $media = new Song($song_id);
                     }
                 }
             }
         }
     }
     if ($media != null) {
         $media->format();
         if ($urlinfo['type'] == 'song') {
             $js['artist_id'] = $media->artist;
             $js['album_id'] = $media->album;
             $js['replaygain_track_gain'] = $media->replaygain_track_gain;
             $js['replaygain_track_peak'] = $media->replaygain_track_peak;
             $js['replaygain_album_gain'] = $media->replaygain_album_gain;
             $js['replaygain_album_peak'] = $media->replaygain_album_peak;
         }
         $js['media_id'] = $media->id;
         if ($media->type != $types['real']) {
             $url .= '&transcode_to=' . $types['real'];
         }
         //$url .= "&content_length=required";
     }
     $js['filetype'] = $types['player'];
     $js['url'] = $url;
     if ($urlinfo['type'] == 'song') {
         $js['poster'] = $item->image_url;
     }
     debug_event("webplayer.class.php", "Return get_media_js_param {" . json_encode($js) . "}", 5);
     return json_encode($js);
 }
예제 #6
0
파일: index.php 프로젝트: ivan801/ampache
            $rtype = $type;
        }
        $oid = Random::get_single_song($rtype);
        if ($oid) {
            // Save this one in case we do a seek
            $_SESSION['random']['last'] = $oid;
        }
    } else {
        $oid = $_SESSION['random']['last'];
    }
}
// if random
if ($type == 'song') {
    /* Base Checks passed create the song object */
    $media = new Song($oid);
    $media->format();
} else {
    if ($type == 'song_preview') {
        $media = new Song_Preview($oid);
        $media->format();
    } else {
        $type = 'video';
        $media = new Video($oid);
        if (isset($_REQUEST['subtitle'])) {
            $subtitle = $media->get_subtitle_file($_REQUEST['subtitle']);
        }
        $media->format();
    }
}
if (!User::stream_control(array(array('object_type' => $type, 'object_id' => $media->id)))) {
    debug_event('UI::access_denied', 'Stream control failed for user ' . $GLOBALS['user']->username . ' on ' . $media->get_stream_name(), 3);
예제 #7
0
 private static function addPlaylistsItems(SimpleXMLElement $xml, $items, $itemIDName = 'playlistItemID')
 {
     foreach ($items as $item) {
         $xitem = null;
         if ($item['object_type'] == 'song') {
             $media = new Song($item['object_id']);
             $media->format();
             $xitem = self::addSong($xml, $media);
         } elseif ($item['object_type'] == 'video') {
             $media = Video::create_from_id($item['object_id']);
             $media->format();
             $xitem = self::addVideoExt($xml, $media);
         }
         if ($xitem != null) {
             if (isset($item['track_id'])) {
                 $xitem->addAttribute($itemIDName, $item['track_id']);
             }
         }
     }
 }
예제 #8
0
 /**
  * format
  * this function takes the object and reformats some values
  */
 public function format($details = true)
 {
     parent::format($details);
     if ($details) {
         if ($this->artist) {
             $artist = new Artist($this->artist);
             $artist->format();
             $this->f_artist = $artist->link;
         }
         if ($this->song) {
             $song = new Song($this->song);
             $song->format();
             $this->f_song = $song->f_link;
         }
     }
     return true;
 }
예제 #9
0
 protected static function _setCustomView($xml, $data)
 {
     foreach ($data as $key => $value) {
         foreach ($value as $id) {
             if ($key == 'artist') {
                 $artist = new Artist($id);
                 $artist->format();
                 self::addArtist($xml, $artist);
             } elseif ($key == 'album') {
                 $album = new Album($id);
                 $album->format();
                 self::addAlbum($xml, $album);
             } elseif ($key == 'song') {
                 $song = new Song($id);
                 $song->format();
                 self::addSong($xml, $song);
             }
         }
     }
 }
예제 #10
0
 /**
  * get_favorites
  * returns an array of your $type favorites
  */
 public function get_favorites($type)
 {
     $results = Stats::get_user(AmpConfig::get('popular_threshold'), $type, $this->id, 1);
     $items = array();
     foreach ($results as $r) {
         /* If its a song */
         if ($type == 'song') {
             $data = new Song($r['object_id']);
             $data->count = $r['count'];
             $data->format();
             $data->f_link;
             $items[] = $data;
         } elseif ($type == 'album') {
             $data = new Album($r['object_id']);
             //$data->count = $r['count'];
             $data->format();
             $items[] = $data;
         } elseif ($type == 'artist') {
             $data = new Artist($r['object_id']);
             //$data->count = $r['count'];
             $data->format();
             $data->f_name = $data->f_link;
             $items[] = $data;
         } elseif ($type == 'genre') {
             $data = new Genre($r['object_id']);
             //$data->count = $r['count'];
             $data->format();
             $data->f_name = $data->f_link;
             $items[] = $data;
         }
     }
     // end foreach
     return $items;
 }
예제 #11
0
 /**
  * load_recently_played
  * This loads in the recently played information and formats it up real nice like
  * @return array
  */
 public static function load_recently_played()
 {
     //FIXME: The time stuff should be centralized, it's currently in two places, lame
     $time_unit = array('', T_('seconds ago'), T_('minutes ago'), T_('hours ago'), T_('days ago'), T_('weeks ago'), T_('months ago'), T_('years ago'));
     $data = Song::get_recently_played();
     $results = array();
     foreach ($data as $item) {
         $client = new User($item['user']);
         $song = new Song($item['object_id']);
         $song->format();
         $amount = intval(time() - $item['date'] + 2);
         $final = '0';
         $time_place = '0';
         while ($amount >= 1) {
             $final = $amount;
             $time_place++;
             if ($time_place <= 2) {
                 $amount = floor($amount / 60);
             }
             if ($time_place == '3') {
                 $amount = floor($amount / 24);
             }
             if ($time_place == '4') {
                 $amount = floor($amount / 7);
             }
             if ($time_place == '5') {
                 $amount = floor($amount / 4);
             }
             if ($time_place == '6') {
                 $amount = floor($amount / 12);
             }
             if ($time_place > '6') {
                 $final = $amount . '+';
                 break;
             }
         }
         // end while
         $time_string = $final . ' ' . $time_unit[$time_place];
         $xml_array = array('title' => $song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album, 'link' => str_replace('&amp;', '&', $song->link), 'description' => $song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string, 'comments' => $client->username, 'pubDate' => date("r", $item['date']));
         $results[] = $xml_array;
     }
     // end foreach
     return $results;
 }
예제 #12
0
 public static function _musicChilds($prmPath, $prmQuery, $start, $count)
 {
     $mediaItems = array();
     $maxCount = 0;
     $queryData = array();
     parse_str($prmQuery, $queryData);
     $parent = 'amp://music' . $prmPath;
     $pathreq = explode('/', $prmPath);
     if ($pathreq[0] == '' && count($pathreq) > 0) {
         array_shift($pathreq);
     }
     switch ($pathreq[0]) {
         case 'artists':
             switch (count($pathreq)) {
                 case 1:
                     // Get artists list
                     //$artists = Catalog::get_artists();
                     //list($maxCount, $artists) = self::_slice($artists, $start, $count);
                     $artists = Catalog::get_artists(null, $count, $start);
                     list($maxCount, $artists) = array(999999, $artists);
                     foreach ($artists as $artist) {
                         $artist->format();
                         $mediaItems[] = self::_itemArtist($artist, $parent);
                     }
                     break;
                 case 2:
                     // Get artist's albums list
                     $artist = new Artist($pathreq[1]);
                     if ($artist->id) {
                         $album_ids = $artist->get_albums();
                         list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
                         foreach ($album_ids as $album_id) {
                             $album = new Album($album_id);
                             $album->format();
                             $mediaItems[] = self::_itemAlbum($album, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'albums':
             switch (count($pathreq)) {
                 case 1:
                     // Get albums list
                     //!!$album_ids = Catalog::get_albums();
                     //!!list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
                     $album_ids = Catalog::get_albums($count, $start);
                     list($maxCount, $album_ids) = array(999999, $album_ids);
                     foreach ($album_ids as $album_id) {
                         $album = new Album($album_id);
                         $album->format();
                         $mediaItems[] = self::_itemAlbum($album, $parent);
                     }
                     break;
                 case 2:
                     // Get album's songs list
                     $album = new Album($pathreq[1]);
                     if ($album->id) {
                         $song_ids = $album->get_songs();
                         list($maxCount, $song_ids) = self::_slice($song_ids, $start, $count);
                         foreach ($song_ids as $song_id) {
                             $song = new Song($song_id);
                             $song->format();
                             $mediaItems[] = self::_itemSong($song, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'songs':
             switch (count($pathreq)) {
                 case 1:
                     // Get songs list
                     $catalogs = Catalog::get_catalogs();
                     foreach ($catalogs as $catalog_id) {
                         $catalog = Catalog::create_from_id($catalog_id);
                         $songs = $catalog->get_songs();
                         list($maxCount, $songs) = self::_slice($songs, $start, $count);
                         foreach ($songs as $song) {
                             $song->format();
                             $mediaItems[] = self::_itemSong($song, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'playlists':
             switch (count($pathreq)) {
                 case 1:
                     // Get playlists list
                     $pl_ids = Playlist::get_playlists();
                     list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
                     foreach ($pl_ids as $pl_id) {
                         $playlist = new Playlist($pl_id);
                         $playlist->format();
                         $mediaItems[] = self::_itemPlaylist($playlist, $parent);
                     }
                     break;
                 case 2:
                     // Get playlist's songs list
                     $playlist = new Playlist($pathreq[1]);
                     if ($playlist->id) {
                         $items = $playlist->get_items();
                         list($maxCount, $items) = self::_slice($items, $start, $count);
                         foreach ($items as $item) {
                             if ($item['object_type'] == 'song') {
                                 $song = new Song($item['object_id']);
                                 $song->format();
                                 $mediaItems[] = self::_itemSong($song, $parent);
                             }
                         }
                     }
                     break;
             }
             break;
         case 'smartplaylists':
             switch (count($pathreq)) {
                 case 1:
                     // Get playlists list
                     $pl_ids = Search::get_searches();
                     list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
                     foreach ($pl_ids as $pl_id) {
                         $playlist = new Search($pl_id, 'song');
                         $playlist->format();
                         $mediaItems[] = self::_itemPlaylist($playlist, $parent);
                     }
                     break;
                 case 2:
                     // Get playlist's songs list
                     $playlist = new Search($pathreq[1], 'song');
                     if ($playlist->id) {
                         $items = $playlist->get_items();
                         list($maxCount, $items) = self::_slice($items, $start, $count);
                         foreach ($items as $item) {
                             if ($item['object_type'] == 'song') {
                                 $song = new Song($item['object_id']);
                                 $song->format();
                                 $mediaItems[] = self::_itemSong($song, $parent);
                             }
                         }
                     }
                     break;
             }
             break;
         default:
             $mediaItems[] = self::_musicMetadata('artists');
             $mediaItems[] = self::_musicMetadata('albums');
             $mediaItems[] = self::_musicMetadata('songs');
             $mediaItems[] = self::_musicMetadata('playlists');
             $mediaItems[] = self::_musicMetadata('smartplaylists');
             break;
     }
     if ($maxCount == 0) {
         $maxCount = count($mediaItems);
     }
     return array($maxCount, $mediaItems);
 }
예제 #13
0
 /**
  * set_flag
  * This function sets the user flag for the current object.
  * If no userid is passed in, we use the currently logged in user.
  */
 public function set_flag($flagged, $user_id = null)
 {
     if ($user_id === null) {
         $user_id = $GLOBALS['user']->id;
     }
     $user_id = intval($user_id);
     debug_event('Userflag', "Setting userflag for {$this->type} {$this->id} to {$flagged}", 5);
     if (!$flagged) {
         $sql = "DELETE FROM `user_flag` WHERE " . "`object_id` = ? AND " . "`object_type` = ? AND " . "`user` = ?";
         $params = array($this->id, $this->type, $user_id);
     } else {
         $sql = "REPLACE INTO `user_flag` " . "(`object_id`, `object_type`, `user`, `date`) " . "VALUES (?, ?, ?, ?)";
         $params = array($this->id, $this->type, $user_id, time());
         Useractivity::post_activity($user_id, 'userflag', $this->type, $this->id);
     }
     Dba::write($sql, $params);
     parent::add_to_cache('userflag_' . $this->type . '_user' . $user_id, $this->id, $flagged);
     // Forward flag to last.fm and Libre.fm (song only)
     if ($this->type == 'song') {
         $user = new User($user_id);
         $song = new Song($this->id);
         if ($song) {
             $song->format();
             foreach (Plugin::get_plugins('save_mediaplay') as $plugin_name) {
                 try {
                     $plugin = new Plugin($plugin_name);
                     if ($plugin->load($user)) {
                         $plugin->_plugin->set_flag($song, $flagged);
                     }
                 } catch (Exception $e) {
                     debug_event('user.class.php', 'Stats plugin error: ' . $e->getMessage(), '1');
                 }
             }
         }
     }
     return true;
 }
예제 #14
0
 /**
  * songs
  *
  * This returns an xml document from an array of song ids.
  * (Spiffy isn't it!)
  */
 public static function songs($songs, $playlist_data = '')
 {
     if (count($songs) > self::$limit or self::$offset > 0) {
         $songs = array_slice($songs, self::$offset, self::$limit);
     }
     Song::build_cache($songs);
     Stream::set_session($_REQUEST['auth']);
     $string = "";
     // Foreach the ids!
     foreach ($songs as $song_id) {
         $song = new Song($song_id);
         // If the song id is invalid/null or disabled
         if (!$song->id || !$song->enabled) {
             continue;
         }
         $song->format();
         $playlist_track_string = self::playlist_song_tracks_string($song, $playlist_data);
         $tag_string = self::tags_string(Tag::get_top_tags('song', $song_id));
         $rating = new Rating($song_id, 'song');
         $art_url = Art::url($song->album, 'album', $_REQUEST['auth']);
         $string .= "<song id=\"" . $song->id . "\">\n" . "\t<title><![CDATA[" . $song->title . "]]></title>\n" . "\t<artist id=\"" . $song->artist . '"><![CDATA[' . $song->get_artist_name() . "]]></artist>\n" . "\t<album id=\"" . $song->album . '"><![CDATA[' . $song->get_album_name() . "]]></album>\n";
         if ($song->albumartist) {
             $string .= "\t<albumartist id=\"" . $song->albumartist . "\"><![CDATA[" . $song->get_album_artist_name() . "]]></albumartist>\n";
         }
         $string .= $tag_string . "\t<filename><![CDATA[" . $song->file . "]]></filename>\n" . "\t<track>" . $song->track . "</track>\n" . $playlist_track_string . "\t<time>" . $song->time . "</time>\n" . "\t<year>" . $song->year . "</year>\n" . "\t<bitrate>" . $song->bitrate . "</bitrate>\n" . "\t<rate>" . $song->rate . "</rate>\n" . "\t<mode>" . $song->mode . "</mode>\n" . "\t<mime>" . $song->mime . "</mime>\n" . "\t<url><![CDATA[" . Song::play_url($song->id, '', 'api') . "]]></url>\n" . "\t<size>" . $song->size . "</size>\n" . "\t<mbid>" . $song->mbid . "</mbid>\n" . "\t<album_mbid>" . $song->album_mbid . "</album_mbid>\n" . "\t<artist_mbid>" . $song->artist_mbid . "</artist_mbid>\n" . "\t<albumartist_mbid>" . $song->albumartist_mbid . "</albumartist_mbid>\n" . "\t<art><![CDATA[" . $art_url . "]]></art>\n" . "\t<preciserating>" . ($rating->get_user_rating() ?: 0) . "</preciserating>\n" . "\t<rating>" . ($rating->get_user_rating() ?: 0) . "</rating>\n" . "\t<averagerating>" . ($rating->get_average_rating() ?: 0) . "</averagerating>\n" . "\t<composer>" . $song->composer . "</composer>\n" . "\t<channels>" . $song->channels . "</channels>\n" . "\t<comment><![CDATA[" . $song->comment . "]]></comment>\n";
         $string .= "\t<publisher><![CDATA[" . $song->label . "]]></publisher>\n" . "\t<language>" . $song->language . "</language>\n" . "\t<replaygain_album_gain>" . $song->replaygain_album_gain . "</replaygain_album_gain>\n" . "\t<replaygain_album_peak>" . $song->replaygain_album_peak . "</replaygain_album_peak>\n" . "\t<replaygain_track_gain>" . $song->replaygain_track_gain . "</replaygain_track_gain>\n" . "\t<replaygain_track_peak>" . $song->replaygain_track_peak . "</replaygain_track_peak>\n";
         foreach ($song->tags as $tag) {
             $string .= "\t<genre><![CDATA[" . $tag['name'] . "]]></genre>\n";
         }
         $string .= "</song>\n";
     }
     // end foreach
     return self::_header() . $string . self::_footer();
 }
예제 #15
0
파일: song.class.php 프로젝트: nioc/ampache
 /**
  * write_id3_for_song
  * Write id3 metadata to the file for the excepted song id
  * @param int $song_id
  */
 public static function write_id3_for_song($song_id)
 {
     $song = new Song($song_id);
     if ($song->id) {
         $song->format();
         $song->write_id3();
     }
 }
예제 #16
0
 /**
  * get
  * This functions returns an array containing information about
  * The songs that httpQ currently has in its playlist. This must be
  * done in a standardized fashion
  */
 public function get()
 {
     /* Get the Current Playlist */
     $list = $this->_httpq->get_tracks();
     if (!$list) {
         return array();
     }
     $songs = explode("::", $list);
     foreach ($songs as $key => $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $key;
         $data['raw'] = $entry;
         $url_data = $this->parse_url($entry);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $song = new Song($url_data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry['file']);
                 $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%{$filename}' " . "UNION ALL " . "SELECT `id`,'radio' AS `type` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     $media = new $row['type']($row['id']);
                     $media->format();
                     switch ($row['type']) {
                         case 'song':
                             $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist;
                             $data['link'] = $media->f_link;
                             break;
                         case 'radio':
                             $frequency = $media->frequency ? '[' . $media->frequency . ']' : '';
                             $site_url = $media->site_url ? '(' . $media->site_url . ')' : '';
                             $data['name'] = "{$media->name} {$frequency} {$site_url}";
                             $data['link'] = $media->site_url;
                             break;
                     }
                     // end switch on type
                 } else {
                     $data['name'] = basename($data['raw']);
                     $data['link'] = basename($data['raw']);
                 }
                 break;
         }
         // end switch on primary key type
         $data['track'] = $key + 1;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
예제 #17
0
 /**
  * exports the catalog
  * it exports all songs in the database to the given export type.
  */
 public static function export($type, $catalog_id = '')
 {
     // Select all songs in catalog
     $params = array();
     if ($catalog_id) {
         $sql = 'SELECT `id` FROM `song` ' . "WHERE `catalog`= ? " . 'ORDER BY `album`, `track`';
         $params[] = $catalog_id;
     } else {
         $sql = 'SELECT `id` FROM `song` ORDER BY `album`, `track`';
     }
     $db_results = Dba::read($sql, $params);
     switch ($type) {
         case 'itunes':
             echo xml_get_header('itunes');
             while ($results = Dba::fetch_assoc($db_results)) {
                 $song = new Song($results['id']);
                 $song->format();
                 $xml = array();
                 $xml['key'] = $results['id'];
                 $xml['dict']['Track ID'] = intval($results['id']);
                 $xml['dict']['Name'] = $song->title;
                 $xml['dict']['Artist'] = $song->f_artist_full;
                 $xml['dict']['Album'] = $song->f_album_full;
                 $xml['dict']['Total Time'] = intval($song->time) * 1000;
                 // iTunes uses milliseconds
                 $xml['dict']['Track Number'] = intval($song->track);
                 $xml['dict']['Year'] = intval($song->year);
                 $xml['dict']['Date Added'] = date("Y-m-d\\TH:i:s\\Z", $song->addition_time);
                 $xml['dict']['Bit Rate'] = intval($song->bitrate / 1000);
                 $xml['dict']['Sample Rate'] = intval($song->rate);
                 $xml['dict']['Play Count'] = intval($song->played);
                 $xml['dict']['Track Type'] = "URL";
                 $xml['dict']['Location'] = Song::play_url($song->id);
                 echo xoutput_from_array($xml, 1, 'itunes');
                 // flush output buffer
             }
             // while result
             echo xml_get_footer('itunes');
             break;
         case 'csv':
             echo "ID,Title,Artist,Album,Length,Track,Year,Date Added,Bitrate,Played,File\n";
             while ($results = Dba::fetch_assoc($db_results)) {
                 $song = new Song($results['id']);
                 $song->format();
                 echo '"' . $song->id . '","' . $song->title . '","' . $song->f_artist_full . '","' . $song->f_album_full . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year . '","' . date("Y-m-d\\TH:i:s\\Z", $song->addition_time) . '","' . $song->f_bitrate . '","' . $song->played . '","' . $song->file . "\n";
             }
             break;
     }
     // end switch
 }
예제 #18
0
         }
         $results[] = array('type' => T_('Albums'), 'link' => $album->link, 'label' => $a_title, 'value' => $album->f_title, 'rels' => $album->f_artist, 'image' => Art::url($album->id, 'album', null, 10));
     }
 }
 if ($target == 'anywhere' || $target == 'title') {
     $searchreq = array('limit' => $limit, 'type' => 'song', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'title');
     $sres = Search::run($searchreq);
     // Litmit not reach, new search with another operator
     if (count($sres) < $limit) {
         $searchreq['limit'] = $limit - count($sres);
         $searchreq['rule_1_operator'] = '0';
         $sres = array_unique(array_merge($sres, Search::run($searchreq)));
     }
     foreach ($sres as $id) {
         $song = new Song($id);
         $song->format(false);
         $results[] = array('type' => T_('Songs'), 'link' => $song->link, 'label' => $song->f_title_full, 'value' => $song->f_title_full, 'rels' => $song->f_artist_full, 'image' => Art::url($song->album, 'album', null, 10));
     }
 }
 if ($target == 'anywhere' || $target == 'playlist_name') {
     $searchreq = array('limit' => $limit, 'type' => 'playlist', 'rule_1_input' => $search, 'rule_1_operator' => '2', 'rule_1' => 'name');
     $sres = Search::run($searchreq);
     // Litmit not reach, new search with another operator
     if (count($sres) < $limit) {
         $searchreq['limit'] = $limit - count($sres);
         $searchreq['rule_1_operator'] = '0';
         $sres = array_unique(array_merge($sres, Search::run($searchreq)));
     }
     foreach ($sres as $id) {
         $playlist = new Playlist($id);
         $playlist->format(false);
예제 #19
0
 public static function library_metadata($params)
 {
     $r = Plex_XML_Data::createLibContainer();
     $n = count($params);
     if ($n > 0) {
         $key = $params[0];
         $id = Plex_XML_Data::getAmpacheId($key);
         if ($n == 1) {
             // Should we check that files still exists here?
             $checkFiles = $_REQUEST['checkFiles'];
             if (Plex_XML_Data::isArtist($key)) {
                 $artist = new Artist($id);
                 $artist->format();
                 Plex_XML_Data::addArtist($r, $artist);
             } elseif (Plex_XML_Data::isAlbum($key)) {
                 $album = new Album($id);
                 $album->format();
                 Plex_XML_Data::addAlbum($r, $album);
             } elseif (Plex_XML_Data::isTrack($key)) {
                 $song = new Song($id);
                 $song->format();
                 Plex_XML_Data::addSong($r, $song);
             }
         } else {
             $subact = $params[1];
             if ($subact == "children") {
                 if (Plex_XML_Data::isArtist($key)) {
                     $artist = new Artist($id);
                     $artist->format();
                     Plex_XML_Data::setArtistRoot($r, $artist);
                 } else {
                     if (Plex_XML_Data::isAlbum($key)) {
                         $album = new Album($id);
                         $album->format();
                         Plex_XML_Data::setAlbumRoot($r, $album);
                     }
                 }
             } elseif ($subact == "thumb") {
                 if ($n == 3) {
                     // Ignore thumb id as we can only have 1 thumb
                     $art = null;
                     if (Plex_XML_Data::isArtist($key)) {
                         $art = new Art($id, "artist");
                     } else {
                         if (Plex_XML_Data::isAlbum($key)) {
                             $art = new Art($id, "album");
                         } else {
                             if (Plex_XML_Data::isTrack($key)) {
                                 $art = new Art($id, "song");
                             }
                         }
                     }
                     if ($art != null) {
                         $art->get_db();
                         if (!isset($size)) {
                             self::setHeader($art->raw_mime);
                             echo $art->raw;
                         } else {
                             $dim = array();
                             $dim['width'] = $size;
                             $dim['height'] = $size;
                             $thumb = $art->get_thumb($dim);
                             self::setHeader($art->thumb_mime);
                             echo $thumb['thumb'];
                         }
                         exit;
                     }
                 }
             }
         }
     }
     Plex_XML_Data::setContainerSize($r);
     self::apiOutput($r->asXML());
 }
예제 #20
0
 public static function library_metadata($params)
 {
     $r = Plex_XML_Data::createLibContainer();
     $n = count($params);
     $litem = null;
     $createMode = $_SERVER['REQUEST_METHOD'] == 'POST';
     $editMode = $_SERVER['REQUEST_METHOD'] == 'PUT';
     if ($n > 0) {
         $key = $params[0];
         $id = Plex_XML_Data::getAmpacheId($key);
         if ($editMode) {
             self::check_access(50);
         }
         if ($n == 1) {
             // Should we check that files still exists here?
             $checkFiles = $_REQUEST['checkFiles'];
             $extra = $_REQUEST['includeExtra'];
             if (Plex_XML_Data::isArtist($key)) {
                 $litem = new Artist($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name', 'summary' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addArtist($r, $litem);
             } elseif (Plex_XML_Data::isAlbum($key)) {
                 $litem = new Album($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name', 'year' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addAlbum($r, $litem);
             } elseif (Plex_XML_Data::isTrack($key)) {
                 $litem = new Song($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addSong($r, $litem);
             } elseif (Plex_XML_Data::isTVShow($key)) {
                 $litem = new TVShow($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name', 'year' => null, 'summary' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addTVShow($r, $litem);
             } elseif (Plex_XML_Data::isTVShowSeason($key)) {
                 $litem = new TVShow_Season($id);
                 $litem->format();
                 Plex_XML_Data::addTVShowSeason($r, $litem);
             } elseif (Plex_XML_Data::isVideo($key)) {
                 $litem = Video::create_from_id($id);
                 if ($editMode) {
                     $dmap = array('title' => null, 'year' => null, 'originallyAvailableAt' => 'release_date', 'originalTitle' => 'original_name', 'summary' => null);
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 $litem->format();
                 $subtype = strtolower(get_class($litem));
                 if ($subtype == 'tvshow_episode') {
                     Plex_XML_Data::addEpisode($r, $litem, true);
                 } elseif ($subtype == 'movie') {
                     Plex_XML_Data::addMovie($r, $litem, true);
                 }
             } elseif (Plex_XML_Data::isPlaylist($key)) {
                 $litem = new Playlist($id);
                 $litem->format();
                 if ($editMode) {
                     $dmap = array('title' => 'name');
                     $litem->update(self::get_data_from_map($dmap));
                 }
                 Plex_XML_Data::addPlaylist($r, $litem);
             }
         } else {
             $subact = $params[1];
             if ($subact == "children") {
                 if (Plex_XML_Data::isArtist($key)) {
                     $litem = new Artist($id);
                     $litem->format();
                     Plex_XML_Data::setArtistRoot($r, $litem);
                 } else {
                     if (Plex_XML_Data::isAlbum($key)) {
                         $litem = new Album($id);
                         $litem->format();
                         Plex_XML_Data::setAlbumRoot($r, $litem);
                     } else {
                         if (Plex_XML_Data::isTVShow($key)) {
                             $litem = new TVShow($id);
                             $litem->format();
                             Plex_XML_Data::setTVShowRoot($r, $litem);
                         } else {
                             if (Plex_XML_Data::isTVShowSeason($key)) {
                                 $litem = new TVShow_Season($id);
                                 $litem->format();
                                 Plex_XML_Data::setTVShowSeasonRoot($r, $litem);
                             }
                         }
                     }
                 }
             } elseif ($subact == "thumbs" || $subact == "posters" || $subact == "arts" || $subact == 'backgrounds') {
                 $kind = Plex_XML_Data::getPhotoKind($subact);
                 if ($createMode) {
                     // Upload art
                     $litem = Plex_XML_Data::createLibraryItem($key);
                     if ($litem != null) {
                         $uri = Plex_XML_Data::getMetadataUri($key) . '/' . Plex_XML_Data::getPhotoPlexKind($kind) . '/' . $key;
                         if (is_a($litem, 'video')) {
                             $type = 'video';
                         } else {
                             $type = get_class($litem);
                         }
                         $art = new Art($litem->id, $type, $kind);
                         $raw = file_get_contents("php://input");
                         $art->insert($raw);
                         header('Content-Type: text/html');
                         echo $uri;
                         exit;
                     }
                 }
                 Plex_XML_Data::addPhotos($r, $key, $kind);
             } elseif ($subact == "thumb" || $subact == "poster" || $subact == "art" || $subact == "background") {
                 if ($n == 3) {
                     $kind = Plex_XML_Data::getPhotoKind($subact);
                     // Ignore art id as we can only have 1 thumb
                     $art = null;
                     if (Plex_XML_Data::isArtist($key)) {
                         $art = new Art($id, "artist", $kind);
                     } else {
                         if (Plex_XML_Data::isAlbum($key)) {
                             $art = new Art($id, "album", $kind);
                         } else {
                             if (Plex_XML_Data::isTrack($key)) {
                                 $art = new Art($id, "song", $kind);
                             } else {
                                 if (Plex_XML_Data::isTVShow($key)) {
                                     $art = new Art($id, "tvshow", $kind);
                                 } else {
                                     if (Plex_XML_Data::isTVShowSeason($key)) {
                                         $art = new Art($id, "tvshow_season", $kind);
                                     } else {
                                         if (Plex_XML_Data::isVideo($key)) {
                                             $art = new Art($id, "video", $kind);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($art != null) {
                         $art->get_db();
                         ob_clean();
                         if (!isset($size)) {
                             self::setHeader($art->raw_mime);
                             echo $art->raw;
                         } else {
                             $dim = array();
                             $dim['width'] = $size;
                             $dim['height'] = $size;
                             $thumb = $art->get_thumb($dim);
                             self::setHeader($art->thumb_mime);
                             echo $thumb['thumb'];
                         }
                         exit;
                     }
                 }
             }
         }
     }
     if ($litem != null) {
         $catalog_ids = $litem->get_catalogs();
         if (count($catalog_ids) > 0) {
             $catalog = Catalog::create_from_id($catalog_ids[0]);
             Plex_XML_Data::addCatalogIdentity($r, $catalog);
         }
     }
     Plex_XML_Data::setContainerSize($r);
     self::apiOutputXml($r->asXML());
 }
예제 #21
0
 /**
  * get_songs
  * This functions returns an array containing information about
  * the songs that MPD currently has in its playlist. This must be
  * done in a standardized fashion
  */
 public function get()
 {
     // If we don't have the playlist yet, pull it
     if (!isset($this->_mpd->playlist)) {
         $this->_mpd->RefreshInfo();
     }
     /* Get the Current Playlist */
     $playlist = $this->_mpd->playlist;
     foreach ($playlist as $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $entry['Pos'];
         $data['raw'] = $entry['file'];
         $url_data = $this->parse_url($entry['file']);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $data['oid'] = $url_data['oid'];
                 $song = new Song($data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry['file']);
                 $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%{$filename}' " . "UNION ALL " . "SELECT `id`,'live_stream' AS `type` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     $media = new $row['type']($row['id']);
                     $media->format();
                     switch ($row['type']) {
                         case 'song':
                             $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist;
                             $data['link'] = $media->f_link;
                             break;
                         case 'live_stream':
                             $frequency = $media->frequency ? '[' . $media->frequency . ']' : '';
                             $site_url = $media->site_url ? '(' . $media->site_url . ')' : '';
                             $data['name'] = "{$media->name} {$frequency} {$site_url}";
                             $data['link'] = $media->site_url;
                             break;
                     }
                     // end switch on type
                 } else {
                     $data['name'] = T_('Unknown');
                     $data['link'] = '';
                 }
                 break;
         }
         // end switch on primary key type
         /* Optional Elements */
         $data['track'] = $entry['Pos'] + 1;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
예제 #22
0
?>
</th>
                <th class="cel_drag essential"></th>
            </tr>
        </thead>
        <tbody id="sortableplaylist_<?php 
echo $playlist->id;
?>
">
            <?php 
foreach ($object_ids as $object) {
    if (!is_array($object)) {
        $object = (array) $object;
    }
    $libitem = new Song($object['object_id']);
    $libitem->format();
    $playlist_track = $object['track'];
    ?>
                    <tr class="<?php 
    echo UI::flip_class();
    ?>
" id="track_<?php 
    echo $object['track_id'];
    ?>
">
                        <?php 
    require AmpConfig::get('prefix') . '/templates/show_playlist_song_row.inc.php';
    ?>
                    </tr>
            <?php 
}
예제 #23
0
 /**
  * get
  * This functions returns an array containing information about
  * The songs that vlc currently has in it's playlist. This must be
  * done in a standardized fashion
  * Warning ! if you got files in vlc medialibary those files will be sent to the php xml parser
  * to, not to your browser but still this can take a lot of work for your server.
  * The xml files of vlc need work, not much documentation on them....
  */
 public function get()
 {
     /* Get the Current Playlist */
     $list = $this->_vlc->get_tracks();
     if (!$list) {
         return array();
     }
     $counterforarray = 0;
     // here we look if there are song in the playlist when media libary is used
     if ($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri']) {
         while ($list['node']['node'][0]['leaf'][$counterforarray]) {
             $songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
             $songid[] = $list['node']['node'][0]['leaf'][$counterforarray]['attr']['id'];
             $counterforarray++;
         }
         // if there is only one song look here,and media libary is used
     } elseif ($list['node']['node'][0]['leaf']['attr']['uri']) {
         $songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf']['attr']['uri'], ENT_NOQUOTES);
         $songid[] = $list['node']['node'][0]['leaf']['attr']['id'];
     } elseif ($list['node']['node']['leaf'][$counterforarray]['attr']['uri']) {
         while ($list['node']['node']['leaf'][$counterforarray]) {
             $songs[] = htmlspecialchars_decode($list['node']['node']['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
             $songid[] = $list['node']['node']['leaf'][$counterforarray]['attr']['id'];
             $counterforarray++;
         }
     } elseif ($list['node']['node']['leaf']['attr']['uri']) {
         $songs[] = htmlspecialchars_decode($list['node']['node']['leaf']['attr']['uri'], ENT_NOQUOTES);
         $songid[] = $list['node']['node']['leaf']['attr']['id'];
     } else {
         return array();
     }
     $counterforarray = 0;
     foreach ($songs as $key => $entry) {
         $data = array();
         /* Required Elements */
         $data['id'] = $songid[$counterforarray];
         // id number of the files in the vlc playlist, needed for other operations
         $data['raw'] = $entry;
         $url_data = $this->parse_url($entry);
         switch ($url_data['primary_key']) {
             case 'oid':
                 $data['oid'] = $url_data['oid'];
                 $song = new Song($data['oid']);
                 $song->format();
                 $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
                 $data['link'] = $song->f_link;
                 break;
             case 'demo_id':
                 $democratic = new Democratic($url_data['demo_id']);
                 $data['name'] = T_('Democratic') . ' - ' . $democratic->name;
                 $data['link'] = '';
                 break;
             case 'random':
                 $data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
                 $data['link'] = '';
                 break;
             default:
                 /* If we don't know it, look up by filename */
                 $filename = Dba::escape($entry);
                 $sql = "SELECT `name` FROM `live_stream` WHERE `url`='{$filename}' ";
                 $db_results = Dba::read($sql);
                 if ($row = Dba::fetch_assoc($db_results)) {
                     //if stream is known just send name
                     $data['name'] = htmlspecialchars(substr($row['name'], 0, 50));
                 } elseif (strncmp($entry, 'http', 4) == 0) {
                     $data['name'] = htmlspecialchars("(VLC stream) " . substr($entry, 0, 50));
                 } else {
                     $getlast = explode("/", $entry);
                     $lastis = count($getlast) - 1;
                     $data['name'] = htmlspecialchars("(VLC local) " . substr($getlast[$lastis], 0, 50));
                 }
                 // end if loop
                 break;
         }
         // end switch on primary key type
         $data['track'] = $key + 1;
         $counterforarray++;
         $results[] = $data;
     }
     // foreach playlist items
     return $results;
 }
예제 #24
0
 /**
  * insert
  * This takes the string representation of an image and inserts it into
  * the database. You must also pass the mime type.
  * @param string $source
  * @param string $mime
  * @return boolean
  */
 public function insert($source, $mime = '')
 {
     // Disabled in demo mode cause people suck and upload p**n
     if (AmpConfig::get('demo_mode')) {
         return false;
     }
     // Check to make sure we like this image
     if (!self::test_image($source)) {
         debug_event('Art', 'Not inserting image, invalid data passed', 1);
         return false;
     }
     // Default to image/jpeg if they don't pass anything
     $mime = $mime ? $mime : 'image/jpeg';
     // Blow it away!
     $this->reset();
     if (AmpConfig::get('write_id3_art')) {
         if ($this->type == 'album') {
             $album = new Album($this->uid);
             debug_event('Art', 'Inserting image Album ' . $album->name . ' on songs.', 5);
             $songs = $album->get_songs();
             foreach ($songs as $song_id) {
                 $song = new Song($song_id);
                 $song->format();
                 $id3 = new vainfo($song->file);
                 $data = $id3->read_id3();
                 if (isset($data['tags']['id3v2'])) {
                     $image_from_tag = '';
                     if (isset($data['id3v2']['APIC'][0]['data'])) {
                         $image_from_tag = $data['id3v2']['APIC'][0]['data'];
                     }
                     if ($image_from_tag != $source) {
                         $ndata = array();
                         $ndata['APIC']['data'] = $source;
                         $ndata['APIC']['mime'] = $mime;
                         $ndata = array_merge($ndata, $song->get_metadata());
                         $id3->write_id3($ndata);
                     }
                 }
             }
         }
     }
     $dimensions = Core::image_dimensions($source);
     $width = intval($dimensions['width']);
     $height = intval($dimensions['height']);
     $sizetext = 'original';
     if (!self::check_dimensions($dimensions)) {
         return false;
     }
     if (AmpConfig::get('album_art_store_disk')) {
         self::write_to_dir($source, $sizetext, $this->type, $this->uid, $this->kind);
         $source = null;
     }
     // Insert it!
     $sql = "INSERT INTO `image` (`image`, `mime`, `size`, `width`, `height`, `object_type`, `object_id`, `kind`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
     Dba::write($sql, array($source, $mime, $sizetext, $width, $height, $this->type, $this->uid, $this->kind));
     return true;
 }
예제 #25
0
 public static function addSimilarSongs($xml, $similar_songs)
 {
     $xsimilar = $xml->addChild("similarSongs");
     foreach ($similar_songs as $similar_song) {
         $song = new Song($similar_song['id']);
         $song->format();
         if ($song->id) {
             self::addSong($xsimilar, $song);
         }
     }
 }
예제 #26
0
    ++$thcount;
    ?>
            <th class="cel_drag essential"></th>
        <?php 
}
?>
        </tr>
    </thead>
    <tbody id="sortableplaylist_<?php 
echo $browse->get_filter('album');
?>
">
        <?php 
foreach ($object_ids as $song_id) {
    $song = new Song($song_id);
    $song->format();
    ?>
            <tr class="<?php 
    echo UI::flip_class();
    ?>
" id="song_<?php 
    echo $song->id;
    ?>
">
                <?php 
    require AmpConfig::get('prefix') . '/templates/show_song_row.inc.php';
    ?>
            </tr>
        <?php 
}
?>
예제 #27
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;
 }