/** * update_single_item * updates a single album,artist,song from the tag data * this can be done by 75+ */ public static function update_single_item($type, $id) { // Because single items are large numbers of things too set_time_limit(0); $songs = array(); switch ($type) { case 'album': $album = new Album($id); $songs = $album->get_songs(); break; case 'artist': $artist = new Artist($id); $songs = $artist->get_songs(); break; case 'song': $songs[] = $id; break; } // end switch type foreach ($songs as $song_id) { $song = new Song($song_id); $info = self::update_media_from_tags($song, '', ''); if ($info['change']) { $file = scrub_out($song->file); echo "<dl>\n\t<dd>"; echo "<strong>{$file} " . T_('Updated') . "</strong>\n"; echo $info['text']; echo "\t</dd>\n</dl><hr align=\"left\" width=\"50%\" />"; flush(); } else { echo "<dl>\n\t<dd>"; echo "<strong>" . scrub_out($song->file) . "</strong><br />" . T_('No Update Needed') . "\n"; echo "\t</dd>\n</dl><hr align=\"left\" width=\"50%\" />"; flush(); } } // foreach songs self::gc(); }
foreach ($data as $value) { $media_ids[] = $value->id; } break; } // end switch on type break; case 'single_song': $media_ids[] = array('object_type' => 'song', 'object_id' => scrub_in($_REQUEST['song_id']), 'custom_play_action' => $_REQUEST['custom_play_action']); break; case 'single_video': $media_ids[] = array('object_type' => 'video', 'object_id' => scrub_in($_REQUEST['video_id'])); break; case 'artist': $artist = new Artist($_REQUEST['artist_id']); $songs = $artist->get_songs(); foreach ($songs as $song) { $media_ids[] = array('object_type' => 'song', 'object_id' => $song); } break; case 'artist_random': $artist = new Artist($_REQUEST['artist_id']); $media_ids = $artist->get_random_songs(); break; case 'album_random': $album = new Album($_REQUEST['album_id']); $media_ids = $album->get_random_songs(); break; case 'album': debug_event('stream.php', 'Playing/Adding all songs of album(s) {' . $_REQUEST['album_id'] . '}...', '5'); $albums_array = explode(',', $_REQUEST['album_id']);
/** * artist_songs * This returns the songs of the specified artist */ public static function artist_songs($input) { $artist = new Artist($input['filter']); $songs = $artist->get_songs(); // Set the offset XML_Data::set_offset($input['offset']); XML_Data::set_limit($input['limit']); ob_end_clean(); echo XML_Data::songs($songs); }
break; case 'album': debug_event('playlist', 'Adding all songs of album(s) {' . $item_id . '}...', '5'); $albums_array = explode(',', $item_id); foreach ($albums_array as $a) { $album = new Album($a); $asongs = $album->get_songs(); foreach ($asongs as $song_id) { $songs[] = $song_id; } } break; case 'artist': debug_event('playlist', 'Adding all songs of artist {' . $item_id . '}...', '5'); $artist = new Artist($item_id); $songs[] = $artist->get_songs(); break; case 'song_preview': case 'song': debug_event('playlist', 'Adding song {' . $item_id . '}...', '5'); $songs = explode(',', $item_id); break; case 'playlist': $pl = new Playlist($item_id); $songs = $pl->get_songs(); break; default: debug_event('playlist', 'Adding all songs of current playlist...', '5'); $objects = $GLOBALS['user']->playlist->get_items(); foreach ($objects as $object_data) { $type = array_shift($object_data);
case 'show': $artist = new Artist($_REQUEST['artist']); $artist->format(); if (AmpConfig::get('album_release_type')) { $multi_object_ids = $artist->get_albums($_REQUEST['catalog'], false, true); } else { $object_ids = $artist->get_albums($_REQUEST['catalog']); } $object_type = 'album'; require_once AmpConfig::get('prefix') . '/templates/show_artist.inc.php'; break; case 'show_all_songs': $artist = new Artist($_REQUEST['artist']); $artist->format(); $object_type = 'song'; $object_ids = $artist->get_songs(); require_once AmpConfig::get('prefix') . '/templates/show_artist.inc.php'; break; case 'update_from_tags': $type = 'artist'; $object_id = intval($_REQUEST['artist']); $target_url = AmpConfig::get('web_path') . "/artists.php?action=show&artist=" . $object_id; require_once AmpConfig::get('prefix') . '/templates/show_update_items.inc.php'; break; case 'match': case 'Match': $match = scrub_in($_REQUEST['match']); if ($match == "Browse" || $match == "Show_all") { $chr = ""; } else { $chr = $match;
/** * advanced * This processes the results of a post from a form and returns an * array of song items that were returned from said randomness */ public static function advanced($type, $data) { /* Figure out our object limit */ $limit = intval($data['random']); // Generate our matchlist /* If they've passed -1 as limit then get everything */ $limit_sql = ""; if ($data['random'] == "-1") { unset($data['random']); } else { $limit_sql = "LIMIT " . Dba::escape($limit); } $search_data = Search::clean_request($data); $search_info = false; if (count($search_data) > 1) { $search = new Search(null, $type); $search->parse_rules($search_data); $search_info = $search->to_sql(); } $sql = ""; switch ($type) { case 'song': $sql = "SELECT `song`.`id`, `size`, `time` " . "FROM `song` "; if ($search_info) { $sql .= $search_info['table_sql']; } if (AmpConfig::get('catalog_disable')) { $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`"; $sql .= " WHERE `catalog`.`enabled` = '1'"; } if ($search_info) { if (AmpConfig::get('catalog_disable')) { $sql .= ' AND ' . $search_info['where_sql']; } else { $sql .= ' WHERE ' . $search_info['where_sql']; } } break; case 'album': $sql = "SELECT `album`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `album` "; if (!$search_info || !$search_info['join']['song']) { $sql .= "LEFT JOIN `song` ON `song`.`album`=`album`.`id` "; } if ($search_info) { $sql .= $search_info['table_sql']; } if (AmpConfig::get('catalog_disable')) { $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`"; $sql .= " WHERE `catalog`.`enabled` = '1'"; } if ($search_info) { if (AmpConfig::get('catalog_disable')) { $sql .= ' AND ' . $search_info['where_sql']; } else { $sql .= ' WHERE ' . $search_info['where_sql']; } } $sql .= ' GROUP BY `album`.`id`'; break; case 'artist': $sql = "SELECT `artist`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `artist` "; if (!$search_info || !$search_info['join']['song']) { $sql .= "LEFT JOIN `song` ON `song`.`artist`=`artist`.`id` "; } if ($search_info) { $sql .= $search_info['table_sql']; } if (AmpConfig::get('catalog_disable')) { $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`"; $sql .= " WHERE `catalog`.`enabled` = '1'"; } if ($search_info) { if (AmpConfig::get('catalog_disable')) { $sql .= ' AND ' . $search_info['where_sql']; } else { $sql .= ' WHERE ' . $search_info['where_sql']; } } $sql .= ' GROUP BY `artist`.`id`'; break; } $sql .= " ORDER BY RAND() {$limit_sql}"; // Run the query generated above so we can while it $db_results = Dba::read($sql); $results = array(); $size_total = 0; $fuzzy_size = 0; $time_total = 0; $fuzzy_time = 0; while ($row = Dba::fetch_assoc($db_results)) { // If size limit is specified if ($data['size_limit']) { // Convert $new_size = $row['size'] / 1024 / 1024; // Only fuzzy 100 times if ($fuzzy_size > 100) { break; } // Add and check, skip if over size if ($size_total + $new_size > $data['size_limit']) { $fuzzy_size++; continue; } $size_total = $size_total + $new_size; $results[] = $row['id']; // If we are within 4mb of target then jump ship if ($data['size_limit'] - floor($size_total) < 4) { break; } } // if size_limit // If length really does matter if ($data['length']) { // base on min, seconds are for chumps and chumpettes $new_time = floor($row['time'] / 60); if ($fuzzy_time > 100) { break; } // If the new one would go over skip! if ($time_total + $new_time > $data['length']) { $fuzzy_time++; continue; } $time_total = $time_total + $new_time; $results[] = $row['id']; // If there are less then 2 min of free space return if ($data['length'] - $time_total < 2) { return $results; } } // if length does matter if (!$data['size_limit'] && !$data['length']) { $results[] = $row['id']; } } // end while results switch ($type) { case 'song': return $results; case 'album': $songs = array(); foreach ($results as $result) { $album = new Album($result); $songs = array_merge($songs, $album->get_songs()); } return $songs; case 'artist': $songs = array(); foreach ($results as $result) { $artist = new Artist($result); $songs = array_merge($songs, $artist->get_songs()); } return $songs; default: return false; } }
break; case 'album': foreach ($_REQUEST['id'] as $a) { $album = new Album($a); if (empty($name)) { $name = $album->name; } $asongs = $album->get_songs(); foreach ($asongs as $song_id) { $media_ids[] = $song_id; } } break; case 'artist': $artist = new Artist($_REQUEST['id']); $media_ids = $artist->get_songs(); $name = $artist->name; break; case 'browse': $id = scrub_in($_REQUEST['browse_id']); $browse = new Browse($id); $browse_media_ids = $browse->get_saved(); foreach ($browse_media_ids as $media_id) { switch ($_REQUEST['type']) { case 'album': $album = new Album($media_id); $media_ids = array_merge($media_ids, $album->get_songs()); break; case 'song': $media_ids[] = $media_id; break;