Jump to content

Add XML tags to specific tracks?


Graxeon

Recommended Posts

The code (below) is called with something like "file.php?s=nature&e=2"

 

<?php

$alternate = 'Alternate Video';

$car1 = array('http://domain.com/car1.flv');
$car2 = array('http://domain.com/car2.flv');
$car3 = array('http://domain.com/car3.flv');

$nature1 = array("http://domain.com/nature1-1.flv",
 "http://domain.com/nature1-2.flv",
 "http://domain.com/nature1-3.flv",
 "http://domain.com/nature1-4.flv");

$nature2 = array("http://domain.com/nature2-1.flv",
 "http://domain.com/nature2-2.flv",
 "http://domain.com/nature2-3.flv",
 "http://domain.com/nature2-4.flv");

$stickman1 = 'http://domain.com/stickman1.flv';
$stickman2 = 'http://domain.com/stickman2.flv';
$stickman3 = 'http://domain.com/stickman3.flv';

$annotation = $_GET['s'];
$var = $annotation . $_GET['e'];
$locations = $$var;

switch($annotation)
{
 case 'car':
   $image = 'http://domain.com/car.png';
   $info = 'http://domain.com/car.html';
   $title = 14;
   break;
 case 'nature':
   $image = "http://domain.com/nature.png";
   $info = "http://domain.com/nature.html";
   $title = 91;
   break;
 case 'stickman':
   $image = 'http://domain.com/stickman.png';
   $info = 'http://domain.com/stickman.html';
   $title = 43;
   break;
}
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$xml .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . PHP_EOL;
$xml .= '<trackList>' . PHP_EOL;
$xml .= '<track>' . PHP_EOL;
$xml .= '<annotation>' . $annotation . '</annotation>' . PHP_EOL;
$xml .= '<location>' . $image . '</location>' . PHP_EOL;
$xml .= '<title>' . $title . '</title>' . PHP_EOL;
$xml .= '<info>' . $info . '</info>' . PHP_EOL;
$xml .= '</track>' . PHP_EOL;

foreach($locations as $location)
{
 $xml .= '<track>' . PHP_EOL;
 $xml .= '<annotation>' . $alternate . '</annotation>' . PHP_EOL;
 $xml .= '<location>' . $location . '</location>' . PHP_EOL;
 $xml .= '<title>' . $title . '</title>' . PHP_EOL;
 $xml .= '<info>' . $info . '</info>' . PHP_EOL;
 $xml .= "<meta rel='type'>video</meta>" . PHP_EOL;
 $xml .= '</track>' . PHP_EOL;
}
 $xml .= '</trackList>' . PHP_EOL;
 $xml .= '</playlist>' . PHP_EOL;

$time = $_SERVER['REQUEST_TIME'];
$handle = fopen('lists/' . $time . 'file.xml', 'w');
fwrite($handle, $xml);
fclose($handle);

header('Location: lists/'. $time . 'file.xml');

?>

 

However...some of the categories (car1/car2/nature1/nature2/stickman1/stickman2) have extra "<location>" tags that act like videos that are split into more than 1 part.

 

So let's say that I have "video.flv", but I split that video into 3 parts: videop1.flv, videop2.flv, and videop3.flv. In an XML playlist, it would be displayed like this:

 

<track>
<title></title>
<location>http://domain.com/videop1.flv</location>
<meta rel='location1'>http://domain.com/videop2.flv</meta>
<meta rel='location2'>http://domain.com/videop3.flv</meta>
<annotation></annotation>
<info></info>
</track>

 

However, not all of the videos are split into parts like that. So I need a way of getting all of the extra "location#s" outputted whenever I call the script. Why? Because some playlists are like this:

 

//This first track has 1 video split into 2 separate files
<track>
<title></title>
<location>http://domain.com/video1p1.flv</location>
<meta rel='location1'>http://domain.com/video1p2.flv</meta>
<annotation></annotation>
<info></info>
</track>

//This second track has 5 parts to it. Notice how the "location#" part is not the same as the actual part of the videos (location1 goes with p2, location2 goes with p3, etc). Also note that there can be an infinite number of "location#s".
<track>
<title></title>
<location>http://domain.com/video2p1.flv</location>
<meta rel='location1'>http://domain.com/video2p2.flv</meta>
<meta rel='location2'>http://domain.com/video2p3.flv</meta>
<meta rel='location3'>http://domain.com/video2p4.flv</meta>
<meta rel='location4'>http://domain.com/video2p5.flv</meta>
<annotation></annotation>
<info></info>
</track>

//This third track has just 1 video file in it
<track>
<title></title>
<location>http://domain.com/video3.flv</location>
<annotation></annotation>
<info></info>
</track>

 

So can someone help me with this, please?

 

 

On another note:

 

Is there a way of automatically deleting the XML files that are generated RIGHT AFTER it finishes loading the XML file (meaning the user is viewing the full XML file)? My host doesn't allow me to make any type of "refresher" (something like a script that deletes the generated XML files every 3 minutes...it has to be done per user interaction).

 

If there isn't any way of doing this...then it's ok, I can delete them by hand...I just didn't want the XML files to clutter up my space xD. I'm more worried about the "location#s" thing than this.

 

Thanks again :).

Link to comment
https://forums.phpfreaks.com/topic/146048-add-xml-tags-to-specific-tracks/
Share on other sites

Here is my attempt at this (doesn't work though)

 

Example request:

 

"file.php?s=boat&e=1&l=yes"

 

<?php
$boat1s1 ()
{
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
echo '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . PHP_EOL;
echo '<trackList>' . PHP_EOL;
echo '<track>' . PHP_EOL;
echo '<annotation>' . $annotation . '</annotation>' . PHP_EOL;
echo '<location>' . $image . '</location>' . PHP_EOL;
echo "<meta rel='location1'>http://domain.com/boat1s1.flv</location>" . PHP_EOL;
echo '<title>' . $title . '</title>' . PHP_EOL;
echo '<info>' . $info . '</info>' . PHP_EOL;
echo '</track>'
}

$boat1s2 ()
{
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
echo '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . PHP_EOL;
echo '<trackList>' . PHP_EOL;
echo '<track>' . PHP_EOL;
echo '<annotation>' . $annotation . '</annotation>' . PHP_EOL;
echo '<location>' . $image . '</location>' . PHP_EOL;
echo "<meta rel='location1'>http://domain.com/boat1s2.flv</location>" . PHP_EOL;
echo '<title>' . $title . '</title>' . PHP_EOL;
echo '<info>' . $info . '</info>' . PHP_EOL;
echo '</track>' . PHP_EOL;
}

$boat1 = array("$boat1s1",
 "$boat1s2");

$alternate = 'Alternate Video';

$car1 = array('http://domain.com/car1.flv');
$car2 = array('http://domain.com/car2.flv');
$car3 = array('http://domain.com/car3.flv');

$nature1 = array("http://domain.com/nature1-1.flv",
 "http://domain.com/nature1-2.flv",
 "http://domain.com/nature1-3.flv",
 "http://domain.com/nature1-4.flv");

$nature2 = array("http://domain.com/nature2-1.flv",
 "http://domain.com/nature2-2.flv",
 "http://domain.com/nature2-3.flv",
 "http://domain.com/nature2-4.flv");

$stickman1 = 'http://domain.com/stickman1.flv';
$stickman2 = 'http://domain.com/stickman2.flv';
$stickman3 = 'http://domain.com/stickman3.flv';

$extraLs = $_GET['l'];
$annotation = $_GET['s'];
$var = $annotation . $_GET['e'];
$locations = $$var;

switch($annotation)
{
 case 'car':
   $image = 'http://domain.com/car.png';
   $info = 'http://domain.com/car.html';
   $title = 14;
   break;
 case 'boat':
   $image = 'http://domain.com/boat.png';
   $info = 'http://domain.com/boat.html';
   $title = 1;
   break;
 case 'nature':
   $image = "http://domain.com/nature.png";
   $info = "http://domain.com/nature.html";
   $title = 91;
   break;
 case 'stickman':
   $image = 'http://domain.com/stickman.png';
   $info = 'http://domain.com/stickman.html';
   $title = 43;
   break;
}

if ($extraLs==yes) 
{
$xml = $boat1
}

if ($extraLs==no) 
{
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$xml .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . PHP_EOL;
$xml .= '<trackList>' . PHP_EOL;
$xml .= '<track>' . PHP_EOL;
$xml .= '<annotation>' . $annotation . '</annotation>' . PHP_EOL;
$xml .= '<location>' . $image . '</location>' . PHP_EOL;
$xml .= '<title>' . $title . '</title>' . PHP_EOL;
$xml .= '<info>' . $info . '</info>' . PHP_EOL;
$xml .= '</track>' . PHP_EOL;

foreach($locations as $location)
{
 $xml .= '<track>' . PHP_EOL;
 $xml .= '<annotation>' . $alternate . '</annotation>' . PHP_EOL;
 $xml .= '<location>' . $location . '</location>' . PHP_EOL;
 $xml .= '<title>' . $title . '</title>' . PHP_EOL;
 $xml .= '<info>' . $info . '</info>' . PHP_EOL;
 $xml .= "<meta rel='type'>video</meta>" . PHP_EOL;
 $xml .= '</track>' . PHP_EOL;
}
 $xml .= '</trackList>' . PHP_EOL;
 $xml .= '</playlist>' . PHP_EOL;
}

$time = $_SERVER['REQUEST_TIME'];
$handle = fopen('lists/' . $time . 'file.xml', 'w');
fwrite($handle, $xml);
fclose($handle);

header('Location: lists/'. $time . 'file.xml');

?>

 

I did the "$boat1s# () {}" thing wrong...I know. But could someone help me out with this one? I think it could work. If it can...can someone clean it up so the script repeats all of the code like it does for the "if $extraLs == no"?

 

 

P.S. That's how the switches should be on the first post, btw. The editor messed up somehow :/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.