예제 #1
0
 /**
  * @param $youtubeUrl
  * @param $bitrate
  * @return bool|mixed|MyCurlFile
  */
 public function downloadMp3ByDirpy($youtubeUrl, $bitrate)
 {
     $this->log("------ Download MP3 by Dirpy.Com");
     $metadata = $this->getDirpyMp3Metadata($youtubeUrl, $bitrate);
     if ($metadata == null) {
         $this->log("ERROR: Not get meta data for link: " . $youtubeUrl);
         Yii::log("ERROR: Not get meta data for link: " . $youtubeUrl, CLogger::LEVEL_ERROR, "ProcessMp3");
         return false;
     }
     $url = $this->renderMP3DownloadLinkForDirpy($youtubeUrl, $metadata);
     $url = $this->baseDirpyURL . "/download" . $url . "&downloadToken=" . $this->getDownloadToken();
     //    $this->log("---- URL DOWNLOAD ${url}");
     $fileName = CVietnameseTools::makeCodeName($metadata['filename']) . '.mp3';
     $this->log("------ Downloading MP3");
     $response = $this->myCurl->download($url, $fileName);
     if ($response != false) {
         $folderSave = '/tmp/';
         $file = $folderSave . $fileName;
         $mp3File = new MP3File($file);
         $mp3Second = $mp3File->getDurationEstimate();
         $metadataTimeSecond = $this->getSecondOfTime($metadata['end_time']);
         $this->log("------ Checking duration mp3 file downloaded " . $mp3Second . " and compare with meta time " . $metadataTimeSecond);
         if ($mp3Second >= $metadataTimeSecond) {
             return $response;
         }
         return false;
     }
     return $response;
 }
예제 #2
0
파일: api.php 프로젝트: AKHXtern/poly
 public function set_d()
 {
     $sql = mysql_query("SELECT * FROM songs WHERE duration IS NULL");
     while ($res = mysql_fetch_assoc($sql)) {
         $mp3file = new MP3File('../assets/songs/' . $res['dir']);
         $d = $mp3file->getDuration();
         mysql_query("UPDATE songs SET duration='" . $d . "' WHERE id='" . $res['id'] . "' ");
     }
 }
예제 #3
0
function crear()
{
    set_time_limit(0);
    $ruta = "musica";
    $GLOBALS['contador'] = 1;
    //Empesamos la estructura del archivo xml
    $xml = new DomDocument('1.0');
    $playlist = $xml->createElement('albumList');
    $playlist = $xml->appendChild($playlist);
    // comprobamos si lo que nos pasan es un direcotrio
    if (is_dir($ruta)) {
        // Abrimos el directorio y comprobamos que
        if ($aux = opendir($ruta)) {
            while (($archivo = readdir($aux)) !== false) {
                // Si quisieramos mostrar todo el contenido del directorio pondríamos lo siguiente:
                // echo '<br />' . $file . '<br />';
                // Pero como lo que queremos es mostrar todos los archivos excepto "." y ".."
                if ($archivo != "." && $archivo != "..") {
                    $ruta_completa = $ruta . '/' . $archivo;
                    //echo "Esto: ".$ruta_completa."<br>";
                    if (is_dir($ruta_completa)) {
                        // Abrimos la nueva carpeta, esta sera el nombre del album
                        if ($aux2 = opendir($ruta_completa)) {
                            //echo "Folder: ".$archivo."<br>";
                            //Aui se empiezan a crear los albums
                            $libro = $xml->createElement('album');
                            //se empieza a iterar desde el album
                            $libro = $playlist->appendChild($libro);
                            $autor = $xml->createElement('albumID', "{$GLOBALS['contador']}");
                            $autor = $libro->appendChild($autor);
                            $titulo = $xml->createElement('albumTitle', htmlspecialchars(utf8_encode($archivo)));
                            $titulo = $libro->appendChild($titulo);
                            $anio = $xml->createElement('albumArtist', 'unknown');
                            $anio = $libro->appendChild($anio);
                            //$albumFolder = $xml->createElement('albumFolder','../data/ACDC/Back In Black/');//No se aun que es esto,parece ser la ubicacion de las imagenes
                            $albumFolder = $xml->createElement('albumFolder', '/images');
                            $albumFolder = $libro->appendChild($albumFolder);
                            $albumTracks = $xml->createElement('albumTracks');
                            //Empieza la lista de canciones
                            $albumTracks = $libro->appendChild($albumTracks);
                            $no_cancion = 1;
                            while (($archivo2 = readdir($aux2)) !== false) {
                                if ($archivo2 != "." && $archivo != "..") {
                                    $ruta_completa2 = $ruta_completa . '/' . $archivo2;
                                    if (is_dir($ruta_completa2)) {
                                    } else {
                                        if (substr("{$ruta_completa2}", -3, 3) == "mp3") {
                                            //El sistema solo soporta archivos con expencion mp3
                                            $track = $xml->createElement('track');
                                            $track = $albumTracks->appendChild($track);
                                            $trackID = $xml->createElement('trackID', "{$no_cancion}");
                                            $trackID = $track->appendChild($trackID);
                                            $trackFile = $xml->createElement('trackFile', htmlspecialchars(utf8_encode($ruta_completa2)));
                                            //Ubicacion del archivo
                                            $trackFile = $track->appendChild($trackFile);
                                            $trackTitle = $xml->createElement('trackTitle', htmlspecialchars(utf8_encode($archivo2)));
                                            //Nombre del archivo
                                            $trackTitle = $track->appendChild($trackTitle);
                                            $trackArtist = $xml->createElement('trackArtist', "Unknow");
                                            $trackArtist = $track->appendChild($trackArtist);
                                            //Calcular el timpo de la cancion
                                            $mp3file = new MP3File(htmlspecialchars($ruta_completa2));
                                            $duration2 = $mp3file->getDuration();
                                            //(slower) for VBR (or CBR)
                                            $trackLengh = $xml->createElement('trackLengh', MP3File::formatTime($duration2));
                                            $trackLengh = $track->appendChild($trackLengh);
                                            $trackFileSize = $xml->createElement('trackFileSize', formatSizeUnits(filesize(htmlspecialchars($ruta_completa2))));
                                            //Tamaño del archivo
                                            $trackFileSize = $track->appendChild($trackFileSize);
                                            //echo "Ubicacion del archivo: ".$ruta_completa2."<br>";
                                            $GLOBALS['contador']++;
                                            $no_cancion++;
                                        }
                                    }
                                    //Termina else carga de archivos
                                }
                            }
                            //Esto va despues del while
                            $albumTracksCount = $xml->createElement('albumTracksCount', $no_cancion - 1);
                            $albumTracksCount = $libro->appendChild($albumTracksCount);
                            $no_cancion = 1;
                            $albumCover = $xml->createElement('albumCover', "images/disco.jpg");
                            $albumCover = $libro->appendChild($albumCover);
                            closedir($aux2);
                        }
                    } else {
                        //No son carpetas, por lo tanto no mostramos nada
                    }
                }
            }
            closedir($aux);
        }
    }
    //Creamos el archivo
    $xml->formatOutput = true;
    $el_xml = $xml->saveXML();
    $xml->save('xml/playlistAllAlbums.xml');
}
//super important. Prevents 10 from immedeatly following 1.
$totalBeats = count($beats);
$storyLayers = substr($beats[$totalBeats - 1], 0, 2);
//hack way to get number of layers. Works with '01 - 99' layers or stories >10 layers.
//Will need to replace the above with a RegExp expression search (remove all non numerical characters) later.
for ($j = 1; $j <= $storyLayers + 1; $j++) {
    $totalBeats = count($beats);
    natsort($beats);
    for ($i = 1; $i <= $totalBeats; $i++) {
        if (substr($beats[$i], 0, 2) == $j) {
            //needs all files to be 01,02,03,04
            $row = [];
            //empty the array.
            $row['mp3'] = $beats[$i];
            //assign the filename.
            $mp3file = new MP3File($storyPath . "/" . $beats[$i]);
            $duration = $mp3file->getDuration();
            //(slower) for VBR (or CBR)
            $row['duration'] = $duration;
            $story[$j - 1][] = $row;
            // $story[$j-1][] = $beats[$i];
            //unset($beats[$i]);//This Doesn't Work.
        }
    }
}
// $cartesianProduct = cartesian($story);
// $cartesianSum = array();
// for ($q = 0; $q<count($cartesianProduct); $q++){
//   $sum = 0;
//   $path = "";
//   for ($w = 0; $w<count($cartesianProduct[$q]); $w++){