<?php
//
// ObsidianMusic
// a.k.a. amaroK Web Frontend 2.0
//
// Created 1/3/06
// Copyright (C) Ryan Loebs (ObsidianX) 2005/2006
// See LICENSE for GPL
//
// play.php - Generates the playlist file which is then sent to the user
// (Or nothing, or a tarball according to settings)
//
// {ARTIST};{LSONG};{CDATE}
///////////////////////////////////////
if(eregi("play.php", $_SERVER['PHP_SELF'])){
die("Cannot access directly.");
}
if(!$errorreporting){
error_reporting(0);
}
$download = false;
switch($playlist){
case 0:
// No output
header("Content-type: view/disabled");
header("Content-disposition: filename=no.play");
break;
case 1:
// PLS output
header("Content-type: audio/x-scpls");
header("Content-disposition: filename=playlist.pls");
$tpl->readTemplatesFromFile("pls.tpl");
break;
case 2:
// M3U output
header("Content-type: audio/x-mpegurl");
header("Content-disposition: filename=playlist.m3u");
$tpl->readTemplatesFromFile("m3u.tpl");
break;
case 3:
// Download song
$download = true;
require_once("inc/tar.class.php");
$tar = @new tar();
break;
}
// Only do this if the config isn't set to 0 - No Output
if($playlist){
switch(@$_GET['type']){
case "list":
if(!$download && count(@$_SESSION['plist'])){
$i = 1;
foreach($_SESSION['plist'] as $track_id){
$q = query(getquery("getfile", "", $track_id));
$res = fetch_assoc($q);
$length = $res['length']/1000;
$title = "$res[artistN] - $res[title]";
$file = "http://$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]?action=stream&sid=".$res['id'];
if($playlist == 1){
$tpl->addVar("list", "num", $i);
$i++;
}
$tpl->addVar("list", "file", $file);
$tpl->addVar("list", "length", $length);
$tpl->addVar("list", "title", $title);
$tpl->parseTemplate("list", "a");
}
if($playlist == 1){
$tpl->addVar("pls", "totalsongs", count($_SESSION['plist']));
}
$tpl->displayParsedTemplate();
}
else if(count(@$_SESSION['plist'])) {
foreach($_SESSION['plist'] as $track_id){
$q = query(getquery("getfile", "", $track_id));
$res = fetch_assoc($q);
$url = $res['url'];
$qd = query(getquery("getdevice", "", $res['deviceid']));
$resd = fetch_assoc($qd);
$url = $resd['lastmountpoint'].ltrim($url, '.');
$tar->addFile($url, FALSE) or die("Unable to add song to TAR archive!");
}
$tar->toTar("/tmp/obimusictmp.tar", FALSE) or die("Unable to save TAR archive to /tmp!");
header("Content-type: application/x-tar");
header("Content-disposition: filename=Playlist.tar");
echo file_get_contents("/tmp/obimusictmp.tar");
}
break;
case "album":
$q = query(getquery("getalbum", "", $_GET['album']));
while($songs = fetch_assoc($q)){
$album[] = $songs;
}
if(!$download && @$_GET['album']){
$i = 1;
foreach($album as $res){
$title = "$res[artistN] - $res[title]";
$length = $res['length']/1000;
$file = "http://$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]?action=stream&sid=".$res['id'];
if($playlist == 1){
$tpl->addVar("list", "num", $i);
$i++;
}
$tpl->addVar("list", "file", $file);
$tpl->addVar("list", "length", $length);
$tpl->addVar("list", "title", $title);
$tpl->parseTemplate("list", "a");
}
if($playlist == 1){
$tpl->addVar("pls", "totalsongs", count($album));
}
$tpl->displayParsedTemplate();
}
else if(@$_GET['album']){
foreach($album as $song){
$url = $song['url'];
$devid = $song['deviceid'];
$qd = query(getquery("getdevice", "", $devid));
$resd = fetch_assoc($qd);
$url = $resd['lastmountpoint'].ltrim($url, '.');
$tar->addFile($url, FALSE) or die("Unable to add song to TAR archive!");
}
$tar->toTar("/tmp/obimusictmp.tar", FALSE) or die("Unable to save TAR archive to /tmp!");
$qa = query(getquery("getalbumn", "", $_GET['album']));
$resa = fetch_assoc($qa);
$title = $resa['name'];
$title = ereg_replace("( )", "", $title);
header("Content-type: application/x-tar");
header("Content-disposition: filename=$title.tar");
echo file_get_contents("/tmp/obimusictmp.tar");
}
break;
default:
$q = query(getquery("getfile", "", $_GET['sid']));
$res = fetch_assoc($q);
$length = $res['length'];
$title = "$res[artistN] - $res[title]";
if(!$download && @$_GET['sid']){
$file = "http://$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]?action=stream&sid=".$_GET['sid'];
if($playlist == 1){
$tpl->addVar("list", "num", "1");
$tpl->addVar("pls", "totalsongs", "1");
}
$tpl->addVar("list", "file", $file);
$tpl->addVar("list", "length", $length);
$tpl->addVar("list", "title", $title);
$tpl->displayParsedTemplate();
}
else{
$url = $res['url'];
$qd = query(getquery("getdevice", "", $res['deviceid']));
$resd = fetch_assoc($qd);
$url = $resd['lastmountpoint'].ltrim($url, '.');
$tar->addFile($url, FALSE) or die("Unable to add song to TAR archive!");
$tar->toTar("/tmp/obimusictmp.tar", FALSE) or die("Unable to save TAR archive to /tmp!");
$title = ereg_replace("( )", "", $title);
header("Content-type: application/x-tar");
header("Content-disposition: filename=$title.tar");
echo file_get_contents("/tmp/obimusictmp.tar");
}
break;
}
}