summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2008-01-12 10:11:48 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2008-01-12 10:11:48 +0000
commit40a6aaea253631c6e54cd28bc957ada5d12e6e39 (patch)
tree1a20fe1898d4205beef633f6b25e0c15f38b19a6
parentd709751a3f5cf3fdf5b4036ef1486b14df6a646d (diff)
downloadampache-40a6aaea253631c6e54cd28bc957ada5d12e6e39.tar.gz
ampache-40a6aaea253631c6e54cd28bc957ada5d12e6e39.tar.bz2
ampache-40a6aaea253631c6e54cd28bc957ada5d12e6e39.zip
fixed write flags script, actually kinda sorta works again (Thx tomatopi)
-rw-r--r--bin/write_tags.inc75
-rwxr-xr-xdocs/CHANGELOG2
-rw-r--r--lib/class/flag.class.php54
3 files changed, 90 insertions, 41 deletions
diff --git a/bin/write_tags.inc b/bin/write_tags.inc
index 90eb95ad..99a938ae 100644
--- a/bin/write_tags.inc
+++ b/bin/write_tags.inc
@@ -1,7 +1,7 @@
<?php
/*
- Copyright 2001 - 2007 Ampache.org
+ Copyright 2001 - 2008 Ampache.org
All Rights Reserved
This program is free software; you can redistribute it and/or
@@ -32,64 +32,65 @@ $prefix = realpath($path . '/../');
require_once $prefix . '/lib/init.php';
// This is all broken currently so just jump ship
-echo "Writting of Tags to files is not currently supported by Getid3() exiting...\n";
-exit;
+echo "Writting of Tags to files is not currently supported by Getid3() use at your own risk.\n";
+flush();
-// Include getID3 libs, including the ability to write tags
-$getID3 = new getID3();
-getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . "write.php", __FILE__);
-
-$tagWriter = new getid3_writetags();
+require_once Config::get('prefix') . '/modules/getid3/write.vorbis.php';
+require_once Config::get('prefix') . '/modules/getid3/write.apetag.php';
+require_once Config::get('prefix') . '/modules/getid3/write.flac.php';
$flag = new Flag();
-$flaggedIds = $flag->get_approved();
+$flagged_ids = Flag::get_approved();
+
+if (!count($flagged_ids)) {
+ echo "No Flagged Songs Found, exiting...\n";
+ exit;
+}
// Loop through every song that has an approved flag
-foreach($flaggedIds as $flagged){
+foreach($flagged_ids as $flagged){
- $info = new Flag($flagged);
- $song = new Song($info->object_id);
- $tagWriter->filename = $song->file;
+ $flag = new Flag($flagged);
+ $song = new Song($flag->object_id);
// Decide on what type of tag format to use, base on song type(a better way maybe?)
switch($song->type){
case 'mp3':
case 'mp2':
case 'mp1':
- $tagFormats = array('id3v1','id3v2.3','ape');
+ $tagWriter = new getid3_write_apetag($song->file);
+ Flag::fill_tags( &$tagWriter, &$song, 'comment' );
break;
case 'ogg':
- $tagFormats = array('vorbiscomment');
+ $tagWriter = new getid3_write_vorbis($song->file);
+ Flag::fill_tags( &$tagWriter, &$song, 'comment' );
break;
case 'flac':
- $tagFormats = array('metaflac');
+ $tagWriter = new getid3_write_flac($song->file);
+ Flag::fill_tags( &$tagWriter, &$song, 'comment' );
break;
default:
- $tagFormats = array();
+ echo 'No Tag';
} // end switch
-
- // Set all of the attributes for the tag to be written(All pulled from the song object)
- $tagWriter->tagformats = $tagFormats;
- $tagData['title'][] = $song->title;
- $tagData['date'][] = $song->year;
- $tagData['year'][] = $song->year;
- $tagData['comment'][] = $song->comment;
- $tagData['size'][] = $song->size;
- $tagData['time'][] = $song->time;
- $tagData['album'][] = $song->get_album_name();
- $tagData['artist'][] = $song->get_artist_name();
- $tagData['genre'][] = $song->get_genre_name();
- $tagData['track'][] = $song->track;
- $tagWriter->tag_data = $tagData;
- // Write out the tag
- if(!$tagWriter->WriteTags()){
- //Pump out an error if it dies
- var_dump($tagWriter->errors);
+ if ( isset($tagWriter) ) {
+
+ // Write out the tag
+ try {
+ $tagWriter->write();
+ echo 'Updated song ' . $song->title . ' by ' . $song->get_artist_name() . "\n";
+ flush();
+ $flag->delete();
+ }
+ catch ( Exception $e ) {
+ print_r( $e->message() );
+ }
}
- // Either way remove the flag cause we have no idea what's happened
- $info->delete_flag();
+ // Unset objects between iterations. getID3 seems to need this
+ unset($tagWriter,$song,$flag);
+
}
+
?>
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 893e7cc7..86c17457 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.4-Beta2
+ - Implemented a semi-working write_tags.inc script limited by getid3()
+ support (Thx tomatopi)
- Added limit option to the XML API
- Fixed an issue where inline song editing wouldn't update the song
title (Thx profner)
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php
index 28d7313a..9cc7c1a8 100644
--- a/lib/class/flag.class.php
+++ b/lib/class/flag.class.php
@@ -137,17 +137,17 @@ class Flag {
* get_approved
* This returns an array of approved flagged songs
*/
- function get_approved() {
+ public static function get_approved() {
- $sql = "SELECT id FROM flagged WHERE approved='1'";
- $db_results = mysql_query($sql,dbh());
+ $sql = "SELECT `id` FROM `flagged` WHERE `approved`='1'";
+ $db_results = Dba::query($sql);
/* Default the results array */
$results = array();
/* While it */
- while ($r = mysql_fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
@@ -302,6 +302,52 @@ class Flag {
} // validate_flag
+ /**
+ * fill_tags
+ * This is used by the write_tags script.
+ */
+ public static function fill_tags( $tagWriter, $song, $type = 'comment' ) {
+
+ // Set all of the attributes for the tag to be written(All pulled from the song object)
+ // Use a function since ID3v1, ID3v2, and vorbis/flac/ape are different
+ switch ($type) {
+ case 'comment':
+ $tagWriter->comments['title'] = $song->title;
+ $tagWriter->comments['date'] = $song->year;
+ $tagWriter->comments['year'] = $song->year;
+ $tagWriter->comments['comment'] = $song->comment;
+ $tagWriter->comments['size'] = $song->size;
+ $tagWriter->comments['time'] = $song->time;
+ $tagWriter->comments['album'] = $song->get_album_name();
+ $tagWriter->comments['artist'] = $song->get_artist_name();
+ $tagWriter->comments['genre'] = $song->get_genre_name();
+ $tagWriter->comments['track'] = $song->track;
+ break;
+ case 'id3v1':
+ $tagWriter->title = $song->title;
+ $tagWriter->year = $song->year;
+ $tagWriter->comment = $song->comment;
+ $tagWriter->artist = $song->get_artist_name();
+ $tagWriter->album = $song->get_album_name();
+ $tagWriter->genre = $song->get_genre_name();
+ $tagWriter->track = $song->track;
+ unset($tagWriter->genre_id);
+ break;
+ case 'id3v2':
+ $tagWriter->title = $song->title;
+ $tagWriter->year = $song->year;
+ $tagWriter->comment = $song->comment;
+ $tagWriter->artist = $song->get_artist_name();
+ $tagWriter->album = $song->get_album_name();
+ $tagWriter->genre = $song->get_genre_name();
+ $tagWriter->track = $song->track;
+ unset($tagWriter->genre_id);
+ break;
+ } // end switch on type
+
+ } // fill_tags
+
+
} //end of flag class
?>