summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-08-02 18:03:11 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-08-02 18:03:11 +0200
commit2345c4c840a4571b9cbb0a021b4c49f9381875ce (patch)
tree9f13c360b6fde3ba9d501e370a57f11f024eaa9f
parent3fa8f8acc3c366c86765b76e4cf8cc2cf5916c5c (diff)
Add PLS playlist support for multipastes
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/file.php31
-rw-r--r--application/views/file/upload_form.php1
2 files changed, 32 insertions, 0 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index 8b08bdea8..35057f4eb 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -141,6 +141,11 @@ class File extends MY_Controller {
return $this->_tarball($id);
}
+ case "pls":
+ if ($is_multipaste) {
+ return $this->_generate_playlist($id);
+ }
+
default:
if ($is_multipaste) {
throw new \exceptions\UserInputException("file/download/invalid-action", "Invalid action \"".htmlspecialchars($lexer)."\"");
@@ -468,6 +473,32 @@ class File extends MY_Controller {
}
}
+ /**
+ * Generate a PLS v2 playlist
+ */
+ private function _generate_playlist($id)
+ {
+ $files = $this->mmultipaste->get_files($id);
+ $counter = 1;
+
+ $playlist = "[playlist]\n";
+ foreach ($files as $file) {
+ // only add audio/video files
+ $base = explode("/", $file['mimetype'])[0];
+ if (!($base === "audio" || $base === "video")) {
+ continue;
+ }
+
+ $url = site_url($file["id"]);
+ $playlist .= sprintf("File%d=%s\n", $counter++, $url);
+ }
+ $playlist .= sprintf("NumberOfEntries=%d\n", $counter - 1);
+ $playlist .= "Version=2\n";
+
+ $this->output->set_content_type('audio/x-scpls');
+ $this->output->set_output($playlist);
+ }
+
function _non_existent()
{
$this->data["title"] .= " - Not Found";
diff --git a/application/views/file/upload_form.php b/application/views/file/upload_form.php
index 8fc7b9f59..76d1a5cdb 100644
--- a/application/views/file/upload_form.php
+++ b/application/views/file/upload_form.php
@@ -110,6 +110,7 @@
<dt>/&lt;ID&gt;/qr</dt><dd>display a qr code containing a link to <span class="example">/&lt;ID&gt;/</span></dd>
<dt>/&lt;ID&gt;/info</dt><dd>display some information about the multipaste</dd>
<dt>/&lt;ID&gt;/tar</dt><dd>download a tarball of all files in the multipaste (files may be renamed to avoid conflicts)</dd>
+ <dt>/&lt;ID&gt;/pls</dt><dd>download a PLS playlist of all audio/video files in the multipaste</dd>
</dl>
</div>
<div class="col-lg-6">