a pastebin project

Paste Description for class::mp3Data

A class that uses getid3 to retrieve information about an mp3 file.

class::mp3Data

  1. <?php
  2.         if (!class_exists("getID3") && file_exists(dirname(__FILE__)."/getid3/getid3.php")) { require_once(dirname(__FILE__)."/getid3/getid3.php"); }
  3.         if (!class_exists("getID3")) { die("Missing Required library, getid3"); }
  4.         // Requires getid3 - http://getid3.sourceforge.net/
  5.         // Allows retrieval of MP3 ID3 information, including Album Artwork via this simple interface.
  6.         // Sorry its not documented.
  7.         // @version 0.2
  8.         class mp3Data
  9.         {
  10.                 protected $getid3;
  11.                 protected $analyzed = FALSE;
  12.                 public $info;
  13.                 protected $error;
  14.                 public function __construct($filename = NULL)
  15.                 {
  16.                         $this->getid3 = new getID3;
  17.                         $this->getid3->encoding = 'UTF-8';
  18.                         $this->error = array();
  19.                         if ($filename !== NULL) { $this->analyze($filename); }
  20.                 }
  21.                 public function analyze($filename)
  22.                 {
  23.                         if(!file_exists($filename)) { $this->setError("File Doesn't Exist!");return FALSE; }
  24.                         if($this->getid3->Analyze($filename))
  25.                         {
  26.                                 getid3_lib::CopyTagsToComments($this->getid3->info);
  27.                         }
  28.                         $this->analyzed = TRUE;
  29.                         $this->info = $this->getid3->info["comments"];
  30.                         return TRUE;
  31.                 }
  32.                 public function getArt($id = 0)
  33.                 {
  34.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  35.                         if (!isset($this->getid3->info["id3v2"]["APIC"][$id]["data"])) { $this->setError("No Attached Picture with ID $id");return FALSE; }
  36.                         $img = imagecreatefromstring($this->getid3->info["id3v2"]["APIC"][$id]["data"]);
  37.                         return $img;
  38.                 }
  39.                 public function getArts()
  40.                 {
  41.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  42.                         if (!isset($this->getid3->info["id3v2"]["APIC"])) { $this->setError("No Attached Pictures");return FALSE; }
  43.                         $ra = array();
  44.                         foreach($this->getid3->info["id3v2"]["APIC"] as $v)
  45.                         {
  46.                                 $ra[] = imagecreatefromstring($v["data"]);
  47.                         }
  48.                         return $ra;
  49.                 }
  50.                 public function getInfo()
  51.                 {
  52.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  53.                         return $this->info;
  54.                 }
  55.                 public function getRawInfo()
  56.                 {
  57.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  58.                         return $this->getid3->info;
  59.                 }
  60.                 public function getName($id = 0)
  61.                 {
  62.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  63.                         return $this->info["title"][$id];
  64.                 }
  65.                 public function getNames()
  66.                 {
  67.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  68.                         return $this->info["title"];
  69.                 }
  70.                 public function getArtist($id = 0)
  71.                 {
  72.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  73.                         return $this->info["artist"][$id];
  74.                 }
  75.                 public function getArtists()
  76.                 {
  77.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  78.                         return $this->info["artist"];
  79.                 }
  80.                 public function getAlbum($id = 0)
  81.                 {
  82.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  83.                         return $this->info["album"][$id];
  84.                 }
  85.                 public function getAlbums()
  86.                 {
  87.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  88.                         return $this->info["album"];
  89.                 }
  90.                 public function getYear($id = 0)
  91.                 {
  92.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  93.                         return $this->info["year"][$id];
  94.                 }
  95.                 public function getYears($id = 0)
  96.                 {
  97.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  98.                         return $this->info["year"];
  99.                 }
  100.                 public function getGenre($id = 0)
  101.                 {
  102.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  103.                         return $this->info["genre"][$id];
  104.                 }
  105.                 public function getGenres()
  106.                 {
  107.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  108.                         return $this->info["genre"];
  109.                 }
  110.                 public function getTrack($id = 0)
  111.                 {
  112.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  113.                         return $this->info["track"][$id];
  114.                 }
  115.                 public function getTracks()
  116.                 {
  117.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  118.                         return $this->info["track"];
  119.                 }
  120.                 public function getComment($id = 0)
  121.                 {
  122.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  123.                         return $this->info["comments"][$id];
  124.                 }
  125.                 public function getComments()
  126.                 {
  127.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  128.                         return $this->info["comments"];
  129.                 }
  130.                 public function getLyric($id = 0)
  131.                 {
  132.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  133.                         return $this->info["unsynchronised_lyric"][$id];
  134.                 }
  135.                 public function getLyrics()
  136.                 {
  137.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  138.                         return $this->info["unsynchronised_lyric"];
  139.                 }
  140.                 public function getBand($id = 0)
  141.                 {
  142.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  143.                         return $this->info["band"][$id];
  144.                 }
  145.                 public function getBands()
  146.                 {
  147.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  148.                         return $this->info["band"];
  149.                 }
  150.                 public function getPublisher($id = 0)
  151.                 {
  152.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  153.                         return $this->info["publisher"][$id];
  154.                 }
  155.                 public function getPublishers()
  156.                 {
  157.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  158.                         return $this->info["publisher"];
  159.                 }
  160.                 public function getComposer($id = 0)
  161.                 {
  162.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  163.                         return $this->info["composer"][$id];
  164.                 }
  165.                 public function getComposers()
  166.                 {
  167.                         if (!$this->analyzed) { return $this->notAnalyzed(); }
  168.                         return $this->info["composer"];
  169.                 }
  170.                
  171.                 private function notAnalyzed()
  172.                 {
  173.                         $this->setError("Not Analyzed");
  174.                         return FALSE;
  175.                 }
  176.                 protected function setError($string)
  177.                 {
  178.                         $this->error[] = $string;
  179.                 }
  180.                 public function getError()
  181.                 {
  182.                         if (!count($this->error)) { return FALSE; }
  183.                         return $this->error[count($this->error)-1];
  184.                 }
  185.                 public function getErrors()
  186.                 {
  187.                         if(!count($this->error)) { return FALSE; }
  188.                         return $this->error;
  189.                 }
  190.         }
  191. ?>

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords.

fantasy-obligation