Commit eed43378 authored by SpinShare's avatar SpinShare

added mp3 support to api

parent 7f8bd609
...@@ -45,8 +45,19 @@ class APISongController extends AbstractController ...@@ -45,8 +45,19 @@ class APISongController extends AbstractController
$em->persist($result); $em->persist($result);
$em->flush(); $em->flush();
// TODO: This is a quick fix for mp3 support, swap with proper mp3 flag later on
$oggURL = $baseUrl."/uploads/audio/".$result->getFileReference()."_0.ogg";
$mp3URL = $baseUrl."/uploads/audio/".$result->getFileReference()."_0.mp3";
$oggHeaders = get_headers($oggURL);
if(stripos($oggHeaders[0],"200 OK")) {
$audioURL = $oggURL;
} else {
$audioURL = $mp3URL;
}
$data = $result->getJSON(); $data = $result->getJSON();
$data['paths']['ogg'] = $baseUrl."/uploads/audio/".$result->getFileReference()."_0.ogg"; $data['paths']['ogg'] = $audioURL;
$data['paths']['cover'] = $baseUrl."/uploads/thumbnail/".$result->getFileReference().".jpg"; $data['paths']['cover'] = $baseUrl."/uploads/thumbnail/".$result->getFileReference().".jpg";
$data['paths']['zip'] = $this->generateUrl('api.songs.download', array('id' => $result->getId()), UrlGeneratorInterface::ABSOLUTE_URL); $data['paths']['zip'] = $this->generateUrl('api.songs.download', array('id' => $result->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
...@@ -148,6 +159,7 @@ class APISongController extends AbstractController ...@@ -148,6 +159,7 @@ class APISongController extends AbstractController
$coverFiles = glob($this->getParameter('cover_path').DIRECTORY_SEPARATOR.$result->getFileReference().".png"); $coverFiles = glob($this->getParameter('cover_path').DIRECTORY_SEPARATOR.$result->getFileReference().".png");
$oggFiles = glob($this->getParameter('audio_path').DIRECTORY_SEPARATOR.$result->getFileReference()."_*.ogg"); $oggFiles = glob($this->getParameter('audio_path').DIRECTORY_SEPARATOR.$result->getFileReference()."_*.ogg");
$mp3Files = glob($this->getParameter('audio_path').DIRECTORY_SEPARATOR.$result->getFileReference()."_*.mp3");
$zip = new \ZipArchive; $zip = new \ZipArchive;
$zip->open($zipLocation.$zipName, \ZipArchive::CREATE); $zip->open($zipLocation.$zipName, \ZipArchive::CREATE);
...@@ -161,6 +173,12 @@ class APISongController extends AbstractController ...@@ -161,6 +173,12 @@ class APISongController extends AbstractController
$zip->addFile($oggFile, "AudioClips".DIRECTORY_SEPARATOR.$result->getFileReference()."_".$oggIndex.".ogg"); $zip->addFile($oggFile, "AudioClips".DIRECTORY_SEPARATOR.$result->getFileReference()."_".$oggIndex.".ogg");
} }
} }
if(count($mp3Files) > 0) {
foreach($mp3Files as $mp3File) {
$mp3Index = explode(".", explode("_", $mp3File)[2])[0];
$zip->addFile($mp3File, "AudioClips".DIRECTORY_SEPARATOR.$result->getFileReference()."_".$mp3Index.".mp3");
}
}
$zip->close(); $zip->close();
$response = new Response(file_get_contents($zipLocation.$zipName)); $response = new Response(file_get_contents($zipLocation.$zipName));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment