mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 11:59:56 +02:00
Added ability to export catalog to iTunes database
Fixed sql error when creating catalog
This commit is contained in:
parent
b1d25fc28f
commit
cbda7ff555
5 changed files with 158 additions and 33 deletions
56
admin/export.php
Normal file
56
admin/export.php
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (c) 2001 - 2007 Ampache.org
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License v2
|
||||||
|
as published by the Free Software Foundation.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once '../lib/init.php';
|
||||||
|
|
||||||
|
if (!Access::check('interface','100')) {
|
||||||
|
access_denied();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Switch on Action */
|
||||||
|
switch ($_REQUEST['action']) {
|
||||||
|
case 'export':
|
||||||
|
|
||||||
|
// This may take a while
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
$catalog = new Catalog($_REQUEST['export_catalog']);
|
||||||
|
|
||||||
|
header("Content-Transfer-Encoding: binary");
|
||||||
|
header("Cache-control: public");
|
||||||
|
|
||||||
|
switch($_REQUEST['export_format']) {
|
||||||
|
case 'itunes':
|
||||||
|
header("Content-Type: application/itunes+xml; charset=utf-8");
|
||||||
|
header("Content-Disposition: attachment; filename=\"itunes.xml\"");
|
||||||
|
$catalog->export('itunes');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
show_header();
|
||||||
|
require_once Config::get('prefix') . '/templates/show_export.inc.php';
|
||||||
|
show_footer();
|
||||||
|
break;
|
||||||
|
} // end switch on action
|
||||||
|
?>
|
|
@ -247,8 +247,8 @@ class Catalog {
|
||||||
if (!$key) { $key = ' '; } //FIXME
|
if (!$key) { $key = ' '; } //FIXME
|
||||||
|
|
||||||
// Ok we're good to go ahead and insert this record
|
// Ok we're good to go ahead and insert this record
|
||||||
$sql = "INSERT INTO `catalog` (`name`,`path`,`catalog_type`,`rename_pattern`,`sort_pattern`,`gather_types`,`key`) " .
|
$sql = "INSERT INTO `catalog` (`name`,`path`,`add_path`,`catalog_type`,`rename_pattern`,`sort_pattern`,`gather_types`,`key`) " .
|
||||||
"VALUES ('$name','$path','$catalog_type','$rename_pattern','$sort_pattern','$gather_types','$key')";
|
"VALUES ('$name','$path','','$catalog_type','$rename_pattern','$sort_pattern','$gather_types','$key')";
|
||||||
$db_results = Dba::query($sql);
|
$db_results = Dba::query($sql);
|
||||||
|
|
||||||
$insert_id = Dba::insert_id();
|
$insert_id = Dba::insert_id();
|
||||||
|
@ -2367,39 +2367,52 @@ class Catalog {
|
||||||
@discussion it exports all songs in the database to the given export type.
|
@discussion it exports all songs in the database to the given export type.
|
||||||
*/
|
*/
|
||||||
function export($type){
|
function export($type){
|
||||||
|
|
||||||
if ($type=="itunes"){
|
|
||||||
|
|
||||||
$sql = "SELECT id FROM song ORDER BY album";
|
|
||||||
$db_results = mysql_query($sql, dbh());
|
|
||||||
|
|
||||||
while ($results = mysql_fetch_array($db_results)) {
|
// Select all songs in catalog
|
||||||
$song = new Song($results['id']);
|
if($this->id) {
|
||||||
$song->format_song();
|
$sql = "SELECT id FROM song WHERE catalog = '$this->id' ORDER BY album,track";
|
||||||
|
} else {
|
||||||
$xml = array();
|
$sql = "SELECT id FROM song ORDER BY album,track";
|
||||||
$xml['key']= $results['id'];
|
|
||||||
$xml['dict']['Track ID']= $results['id'];
|
|
||||||
$xml['dict']['Name'] = utf8_encode($song->title);
|
|
||||||
$xml['dict']['Artist'] = utf8_encode($song->f_artist_full);
|
|
||||||
$xml['dict']['Album'] = utf8_encode($song->f_album_full);
|
|
||||||
$xml['dict']['Genre'] = $song->f_genre;
|
|
||||||
$xml['dict']['Total Time'] = $song->time;
|
|
||||||
$xml['dict']['Track Number'] = $song->track;
|
|
||||||
$xml['dict']['Year'] = $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'] = $song->rate;
|
|
||||||
$xml['dict']['Play Count'] = $song->played;
|
|
||||||
$xml['dict']['Track Type'] = "URL";
|
|
||||||
$xml['dict']['Location'] = $song->get_url();
|
|
||||||
|
|
||||||
$result .= xml_from_array($xml,1,'itunes');
|
|
||||||
}
|
}
|
||||||
return $result;
|
$db_results = Dba::query($sql);
|
||||||
|
|
||||||
|
if ($type=="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']['Genre'] = $song->f_genre;
|
||||||
|
$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->get_url();
|
||||||
|
|
||||||
|
echo xml_from_array($xml,1,'itunes');
|
||||||
|
|
||||||
|
// flush output buffer
|
||||||
|
ob_flush();
|
||||||
|
flush();
|
||||||
|
|
||||||
|
} // while result
|
||||||
|
|
||||||
|
echo xml_get_footer('itunes');
|
||||||
|
|
||||||
|
} // itunes
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} // export
|
} // export
|
||||||
|
|
||||||
} // end of catalog class
|
} // end of catalog class
|
||||||
|
|
|
@ -899,7 +899,7 @@ function xml_from_array($array,$callback=0,$type='') {
|
||||||
else {
|
else {
|
||||||
if ($key == "key"){
|
if ($key == "key"){
|
||||||
$string .= "\t\t<$key>$value</$key>\n";
|
$string .= "\t\t<$key>$value</$key>\n";
|
||||||
} elseif (is_numeric($value)) {
|
} elseif (is_int($value)) {
|
||||||
$string .= "\t\t\t<key>$key</key><integer>$value</integer>\n";
|
$string .= "\t\t\t<key>$key</key><integer>$value</integer>\n";
|
||||||
} elseif ($key == "Date Added") {
|
} elseif ($key == "Date Added") {
|
||||||
$string .= "\t\t\t<key>$key</key><date>$value</date>\n";
|
$string .= "\t\t\t<key>$key</key><date>$value</date>\n";
|
||||||
|
|
55
templates/show_export.inc.php
Normal file
55
templates/show_export.inc.php
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (c) 2001 - 2007 Ampache.org
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; version 2
|
||||||
|
of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
show_box_top(_('Export Catalog')); ?>
|
||||||
|
<form name="duplicates" action="<?php echo Config::get('web_path'); ?>/admin/export.php?action=export" method="post" enctype="multipart/form-data" >
|
||||||
|
<table cellspacing="0" cellpadding="3">
|
||||||
|
<tr>
|
||||||
|
<td valign="top"><strong><?php echo _('Catalog'); ?>:</strong></td>
|
||||||
|
<td>
|
||||||
|
<select id="export_catalog" name="export_catalog" width="150" style="width: 150px">
|
||||||
|
<option value="">(all)</option>
|
||||||
|
<?php
|
||||||
|
$catalog_ids = Catalog::get_catalogs();
|
||||||
|
foreach ($catalog_ids as $cat_id) {
|
||||||
|
$cat = new Catalog($cat_id);
|
||||||
|
?>
|
||||||
|
<option value="<?php echo $cat->id; ?>" <?php if($_REQUEST['export_catalog']==$cat->id) echo "selected=\"selected\"" ?>><?php echo $cat->name; ?></option>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign="top"><strong><?php echo _('Format'); ?>:</strong></td>
|
||||||
|
<td>
|
||||||
|
<select id="export_format" name="export_format" width="150" style="width: 150px">
|
||||||
|
<option value="itunes" <?php if($_REQUEST['export_format']=='itunes') echo "selected=\"selected\"" ?>>iTunes</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<div class="formValidation">
|
||||||
|
<input type="submit" value="<?php echo _('Export'); ?>" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<?php show_box_bottom(); ?>
|
|
@ -25,6 +25,7 @@
|
||||||
<li id="sb_admin_ot_ClearNowPlaying"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_now_playing"><?php echo _('Clear Now Playing'); ?></a></li>
|
<li id="sb_admin_ot_ClearNowPlaying"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_now_playing"><?php echo _('Clear Now Playing'); ?></a></li>
|
||||||
<li id="sb_admin_ot_ClearCatStats"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_stats"><?php echo _('Clear Stats'); ?></a></li>
|
<li id="sb_admin_ot_ClearCatStats"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_stats"><?php echo _('Clear Stats'); ?></a></li>
|
||||||
<li id="sb_admin_ot_ManageFlagged"><a href="<?php echo $web_path; ?>/admin/flag.php"><?php echo _('Manage Flagged'); ?></a></li>
|
<li id="sb_admin_ot_ManageFlagged"><a href="<?php echo $web_path; ?>/admin/flag.php"><?php echo _('Manage Flagged'); ?></a></li>
|
||||||
|
<li id="sb_admin_ot_Export"><a href="<?php echo $web_path; ?>/admin/export.php"><?php echo _('Export'); ?></a></li>
|
||||||
<?php if (Config::get('shoutbox')) { ?>
|
<?php if (Config::get('shoutbox')) { ?>
|
||||||
<li id="sb_admin_ot_ManageShoutbox"><a href="<?php echo $web_path; ?>/shout.php?action=show_manage"><?php echo _('Manage Shoutbox'); ?></a></li>
|
<li id="sb_admin_ot_ManageShoutbox"><a href="<?php echo $web_path; ?>/shout.php?action=show_manage"><?php echo _('Manage Shoutbox'); ?></a></li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue