Bifurcation depuis
spip / medias
660 validations de retard le dépôt en amont.
-
brunobergot@gmail.com a rédigé
ref https://core.spip.net/issues/3693
brunobergot@gmail.com a rédigéref https://core.spip.net/issues/3693
write.id3v1.php 5,50 Kio
<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at http://getid3.sourceforge.net //
// or http://www.getid3.org //
// also https://github.com/JamesHeinrich/getID3 //
/////////////////////////////////////////////////////////////////
// See readme.txt for more details //
/////////////////////////////////////////////////////////////////
// //
// write.id3v1.php //
// module for writing ID3v1 tags //
// dependencies: module.tag.id3v1.php //
// ///
/////////////////////////////////////////////////////////////////
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
class getid3_write_id3v1
{
public $filename;
public $filesize;
public $tag_data;
public $warnings = array(); // any non-critical errors will be stored here
public $errors = array(); // any critical errors will be stored here
public function __construct() {
return true;
}
public function WriteID3v1() {
// File MUST be writeable - CHMOD(646) at least
if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) {
$this->setRealFileSize();
if (($this->filesize <= 0) || !getid3_lib::intValueSupported($this->filesize)) {
$this->errors[] = 'Unable to WriteID3v1('.$this->filename.') because filesize ('.$this->filesize.') is larger than '.round(PHP_INT_MAX / 1073741824).'GB';
return false;
}
if ($fp_source = fopen($this->filename, 'r+b')) {
fseek($fp_source, -128, SEEK_END);
if (fread($fp_source, 3) == 'TAG') {
fseek($fp_source, -128, SEEK_END); // overwrite existing ID3v1 tag
} else {
fseek($fp_source, 0, SEEK_END); // append new ID3v1 tag
}
$this->tag_data['track'] = (isset($this->tag_data['track']) ? $this->tag_data['track'] : (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : (isset($this->tag_data['tracknumber']) ? $this->tag_data['tracknumber'] : '')));
$new_id3v1_tag_data = getid3_id3v1::GenerateID3v1Tag(
(isset($this->tag_data['title'] ) ? $this->tag_data['title'] : ''),
(isset($this->tag_data['artist'] ) ? $this->tag_data['artist'] : ''),
(isset($this->tag_data['album'] ) ? $this->tag_data['album'] : ''),
(isset($this->tag_data['year'] ) ? $this->tag_data['year'] : ''),
(isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : ''),
(isset($this->tag_data['comment']) ? $this->tag_data['comment'] : ''),
(isset($this->tag_data['track'] ) ? $this->tag_data['track'] : ''));
fwrite($fp_source, $new_id3v1_tag_data, 128);
fclose($fp_source);
return true;
} else {
$this->errors[] = 'Could not fopen('.$this->filename.', "r+b")';
return false;
}
}
$this->errors[] = 'File is not writeable: '.$this->filename;
return false;
}
public function FixID3v1Padding() {
// ID3v1 data is supposed to be padded with NULL characters, but some taggers incorrectly use spaces