function streamTrack() { $AlbumTrackID = $this->f3->get('PARAMS.AlbumTrackID'); $track = new AlbumTrack($this->db); $track->getById($AlbumTrackID); $filePath = $track->FileName; $this->utils->smartReadFile($filePath); }
function getTrackMetadata($id) { $AlbumTrackID = $this->f3->get('PARAMS.AlbumTrackID'); $track = new AlbumTrack($this->db); $track->getById($AlbumTrackID); $filePath = $track->FileName; $getID3 = new getID3(); $tags = $getID3->analyze($filePath); echo "<pre>"; echo print_r($tags, TRUE); echo "</pre>"; }
public function handleUpload($file, $uploadDir, $uploadType, $id) { $fileName = $this->f3->get('POST.name'); $fileBaseName = pathinfo($fileName, PATHINFO_FILENAME); $fileType = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $slugName = basename($file['name']); $slugBaseName = pathinfo($slugName, PATHINFO_FILENAME); $uploadDirFull = $this->docRoot . $uploadDir; $fileFullPath = $uploadDir . $slugName; if (!file_exists($uploadDirFull)) { $cmd = 'mkdir -p ' . $uploadDirFull; $output = shell_exec($cmd); } if ($this->debug) { $this->utils->debug(__METHOD__, $fileFullPath); $this->utils->debug(__METHOD__, $cmd); $this->utils->debug(__METHOD__, $output); } switch ($uploadType) { case "track": $track = new AlbumTrack($this->db); // Extract ID3 tags using getID3 engine $fileTypes = array("mp3", "flac"); if (in_array($fileType, $fileTypes)) { $getID3 = new getID3(); // Currently using tmp_name, actual file gets created after handler runs $tags = $getID3->analyze($file['tmp_name']); if ($this->debug) { $this->utils->debug(__METHOD__, $tags); } // See https://raw.githubusercontent.com/JamesHeinrich/getID3/master/structure.txt if (isset($tags['playtime_seconds'])) { $track->Length = $tags['playtime_seconds']; } if (isset($tags['audio'])) { $tag = $tags['audio']; $track->Bitrate = $tag['bitrate']; $track->BitrateMode = $tag['bitrate_mode']; $track->Codec = $tag['codec']; $track->Format = $tag['dataformat']; $track->Encoder = $tag['encoder']; $track->Lossless = $tag['lossless']; } if (isset($tags['tags']['id3v1'])) { $tag = $tags['tags']['id3v1']; $track->TrackName = $tag['title'][0]; $track->TrackNumber = $tag['track'][0]; } if (isset($tags['tags']['id3v2'])) { $tag = $tags['tags']['id3v2']; $track->TrackName = $tag['title'][0]; $track->TrackNumber = $tag['track_number'][0]; $track->DiscNumber = $tag['part_of_a_set'][0]; $track->Date = $tag['year'][0]; $track->Genre = $tag['genre'][0]; } if (isset($tags['tags']['vorbiscomment'])) { $tag = $tags['tags']['vorbiscomment']; $track->TrackName = $tag['title'][0]; $track->TrackNumber = $tag['tracknumber'][0]; $track->DiscNumber = $tag['discnumber'][0]; $track->Date = $tag['date'][0]; $track->Genre = $tag['genre'][0]; } if ($track->TrackName == null) { $track->TrackName = $fileBaseName; } } $track->ProductID = $id; $track->FileName = $fileFullPath; $track->Size = $file['size']; if ($this->debug) { $this->utils->debug(__METHOD__, $track->cast()); } $track->save(); echo $this->utils->successResponse($track, null); break; case "cover": // Currently using tmp_name, actual file gets created after handler runs $product = new Product($this->db); $product->getByUser($this->userID, $id); $product->ProductImage = $fileFullPath; if ($this->debug) { $this->utils->debug(__METHOD__, $product->cast()); } $product->update(); $source = $file['tmp_name']; $dest = $uploadDirFull . $slugBaseName . '_small' . '.' . $fileType; // Set WxH //$size = "400x250"; // Set width only $size = "400"; $output = $this->resizeImage($source, $dest, $size); if ($output == "") { echo $this->utils->successResponse($dest, null); } break; default: break; } }