How to generate a playlist with random tracks from Twonky

General discussion about the media server. Feature requests. Hints, tips and tricks.
Locked
User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag
How to generate a playlist with random tracks from Twonky

Post by phibertron » Fri Feb 08, 2013 12:13 am

These two java script examples are best used for:
Creating a playlist that will reside locally and pull content from Twonky Server
It will only exist locally and it in itself is not seen by the server

windows script to create a m3u playlist locally
windows script to create a wpl playlist locally

These two java script examples are best used for:
Creating a playlist that will reside on Twonky Server and be accessed with dlna
It will exist locally to the server and will be streamed by the server

windows script to create a m3u playlist on twonky server
windows script to create a wpl playlist on twonky server

The following is an example of how to schedule one of the above windows scripts
so that they can be run automatically for the creation of a random playlist of the day, hour, etc.

windows scheduled task to automate playlist script

These two java script examples are best used for:
Creating a playlist that will reside locally and pull content from Twonky Server
It will only exist locally and it in itself is not seen by the server

shell script to create a m3u playlist locally
shell script to create a wpl playlist locally

These two java script examples are best used for:
Creating a playlist that will reside on Twonky Server and be accessed with dlna
It will exist locally to the server and will be streamed by the server

shell script to create a m3u playlist on twonky server
shell script to create a wpl playlist on twonky server

The following is an example of how to schedule one of the above shell scripts
so that they can be run automatically for the creation of a random playlist of the day, hour, etc.

shell script scheduling to automate playlist script
.
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

windows script to create a m3u playlist locally

Post by phibertron » Fri Feb 08, 2013 12:16 am

Code: Select all

// Version 1.0
// The following jscript will create a m3u playlist locally, Random Playlist.m3u
// with 10 random songs from the following twonky server http://127.0.0.1:9000

// Connect to Twonky Server and get a list of all tracks
var xmlServerHttp = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
    xmlServerHttp.open("GET", "http://127.0.0.1:9000/json/feed/0$1$8", false);
    xmlServerHttp.send();

// Convert the response from Twonky Server
var myObject = eval('(' + xmlServerHttp.responseText + ')');

// Create and Open the Random Playlist for writing
var fso = new ActiveXObject("Scripting.FileSystemObject");
var myFile = fso.CreateTextFile("Random Playlist.m3u");  

// Add 10 Random Songs to the Playlist
for (var i=0;i<10;i++)
{ 
    var myRandom = Math.floor(Math.random()*myObject.containerContents.length);

    var mySong = myObject.containerContents[myRandom].link;

    myFile.WriteLine(mySong);
}

// Close the Random Playist
myFile.Close();
For Example:
The above script would produce the follwoing file "Random Playlist.m3u" as shown below
The path to where this file is saved can be changed in the above script
The playlist created is best used as a local file on you computer and not to be copied to the server
There are two example scripts that have examples for doing that later in this thread
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I3085.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I5645.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I5901.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I6912.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I5133.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I4877.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I2317.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I2317.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I3085.mp3
http ://127.0.0.1:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$8I5645.mp3
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

windows script to create a wpl playlist locally

Post by phibertron » Fri Feb 08, 2013 12:19 am

Code: Select all

// Version 1.0
// The following jscript will create a wpl playlist locally, Random Playlist.wpl
// with 10 random songs from the following twonky server http://127.0.0.1:9000

// Connect to Twonky Server and get a list of all tracks
var xmlServerHttp = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
    xmlServerHttp.open("GET", "http://127.0.0.1:9000/json/feed/0$1$8", false);
    xmlServerHttp.send();

// Convert the response from Twonky Server
var myObject = eval('(' + xmlServerHttp.responseText + ')');

// Create and Open the Random Playlist for writing
var fso = new ActiveXObject("Scripting.FileSystemObject");
var myFile = fso.CreateTextFile("Random Playlist.wpl"); 

// Write the head section to the playlist file
myFile.WriteLine('<?wpl version="1.0"?>');
myFile.WriteLine('<smil>');
myFile.WriteLine('<head>');
myFile.WriteLine('<meta name="Generator" content="Twonky"/>');
myFile.WriteLine('<meta name="ItemCount" content="10"/>');
myFile.WriteLine('<meta name="Type" content="M"/>');
myFile.WriteLine('<title>Random Playlist</title>');
myFile.WriteLine('</head>');
myFile.WriteLine('<body>');
myFile.WriteLine('<seq>');

// Add 10 Random Songs to the Playlist
for (var i=0;i<10;i++)
{ 
    var myRandom = Math.floor(Math.random()*myObject.containerContents.length);
    var mySong = '<media src="' + myObject.containerContents[myRandom].link + '"/>'
    myFile.WriteLine(mySong);
}

// Write the tail section to the playlist file
myFile.WriteLine('</seq>');
myFile.WriteLine('</body>');
myFile.WriteLine('</smil>');

// Close the Random Playist
myFile.Close();
For Example:
The above script would produce the follwoing file "Random Playlist.wpl" as shown below
The path to where this file is saved can be changed in the above script
The playlist created is best used as a local file on you computer and not to be copied to the server
There are two example scripts that have examples for doing that later in this thread
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Twonky"/>
<meta name="ItemCount" content="10"/>
<meta name="Type" content="M"/>
<title>Random Playlist</title>
</head>
<body>
<seq>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I3085.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I5645.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I5901.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I6912.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I5133.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I4877.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I2317.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I2317.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I3085.mp3"/>
<media src="http://127.0.0.1:9000/disk/DLNA-PNMP3-O ... 8I5645.mp3"/>
</seq>
</body>
</smil>
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

windows script to create a m3u playlist on twonky server

Post by phibertron » Fri Feb 08, 2013 12:22 am

Code: Select all

// Version 1.0
// The following jscript will create a m3u server playlist, \\TwonkyServer\ShareName\Random Playlist.m3u
// with 10 random songs from the following twonky server http://TwonkyServer:9000

// Connect to Twonky Server and get a list of all tracks
var xmlServerHttp = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
    xmlServerHttp.open("GET", "http://TwonkyServer:9000/json/feed/0$1$8", false);
    xmlServerHttp.send();

// Convert the response from Twonky Server
var myObject = eval('(' + xmlServerHttp.responseText + ')');

// Create and Open the Random Playlist for writing
var fso = new ActiveXObject("Scripting.FileSystemObject");
var myFile = fso.CreateTextFile("\\\\TwonkyServer\\ShareName\\Random Playlist.m3u");  

// Add 10 Random Songs to the Playlist
for (var i=0;i<10;i++)
{ 
    var myRandom = Math.floor(Math.random()*myObject.containerContents.length);

    var mySong = myObject.containerContents[myRandom].filename;

    myFile.WriteLine(mySong);
}

// Close the Random Playist
myFile.Close();
For Example:
The above script would produce the follwoing file "Random Playlist.m3u" as shown below
The path to where this file is saved can be changed in the above script
The playlist created is best used as a playlist on the server and not your local computer
There are two example scripts that have examples for doing that previously in this thread
D:\shares\Music\Metallica\Master of Puppets.mp3
D:\shares\Music\Black Sabbath\War Pigs.mp3
D:\shares\Music\System of a Down\Chop Suey.mp3
D:\shares\Music\Megadeth\Holy Wars The Punishment Due.mp3
D:\shares\Music\X Japan\Art of Life.mp3
D:\shares\Music\Judas Priest\Painkiller.mp3
D:\shares\Music\Iron Maiden\The Trooper.mp3
D:\shares\Music\Antim Grahan\Forever Winter.mp3
D:\shares\Music\Dio\Holy Diver.mp3
D:\shares\Music\Ozzy Osbourne\Crazy Train.mp3
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

windows script to create a wpl playlist on twonky server

Post by phibertron » Fri Feb 08, 2013 12:25 am

Code: Select all

// Version 1.0
// The following jscript will create a wpl server playlist, \\TwonkyServer\ShareName\Random Playlist.wpl
// with 10 random songs from the following twonky server http://TwonkyServer:9000

// Connect to Twonky Server and get a list of all tracks
var xmlServerHttp = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
    xmlServerHttp.open("GET", "http://127.0.0.1:9000/json/feed/0$1$8", false);
    xmlServerHttp.send();

// Convert the response from Twonky Server
var myObject = eval('(' + xmlServerHttp.responseText + ')');

// Create and Open the Random Playlist for writing
var fso = new ActiveXObject("Scripting.FileSystemObject");
var myFile = fso.CreateTextFile("\\\\TwonkyServer\\ShareName\\Random Playlist.wpl"); 

// Write the head section to the playlist file
myFile.WriteLine('<?wpl version="1.0"?>');
myFile.WriteLine('<smil>');
myFile.WriteLine('<head>');
myFile.WriteLine('<meta name="Generator" content="Twonky"/>');
myFile.WriteLine('<meta name="ItemCount" content="10"/>');
myFile.WriteLine('<meta name="Type" content="M"/>');
myFile.WriteLine('<title>Random Playlist</title>');
myFile.WriteLine('</head>');
myFile.WriteLine('<body>');
myFile.WriteLine('<seq>');

// Add 10 Random Songs to the Playlist
for (var i=0;i<10;i++)
{ 
    var myRandom = Math.floor(Math.random()*myObject.containerContents.length);
    var mySong = '<media src="' + myObject.containerContents[myRandom].filename + '"/>'
    myFile.WriteLine(mySong);
}

// Write the tail section to the playlist file
myFile.WriteLine('</seq>');
myFile.WriteLine('</body>');
myFile.WriteLine('</smil>');

// Close the Random Playist
myFile.Close();
For Example:
The above script would produce the follwoing file "Random Playlist.wpl" as shown below
The path to where this file is saved can be changed in the above script
The playlist created is best used as a playlist on the server and not your local computer
There are two example scripts that have examples for doing that previously in this thread
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Twonky"/>
<meta name="ItemCount" content="10"/>
<meta name="Type" content="M"/>
<title>Random Playlist</title>
</head>
<body>
<seq>
<media src="D:\shares\Music\Metallica\Master of Puppets.mp3"/>
<media src="D:\shares\Music\Black Sabbath\War Pigs.mp3"/>
<media src="D:\shares\Music\System of a Down\Chop Suey.mp3"/>
<media src="D:\shares\Music\Megadeth\Holy Wars The Punishment Due.mp3"/>
<media src="D:\shares\Music\X Japan\Art of Life.mp3"/>
<media src="D:\shares\Music\Judas Priest\Painkiller.mp3"/>
<media src="D:\shares\Music\Iron Maiden\The Trooper.mp3"/>
<media src="D:\shares\Music\Antim Grahan\Forever Winter.mp3"/>
<media src="D:\shares\Music\Dio\Holy Diver.mp3"/>
<media src="D:\shares\Music\Ozzy Osbourne\Crazy Train.mp3"/>
</seq>
</body>
</smil>
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

windows scheduled task to automate playlist script

Post by phibertron » Fri Feb 08, 2013 12:33 am

Schedule Task 1.jpg
Schedule Task 1.jpg (52.39KiB)Viewed 16185 times
Schedule Task 2.jpg
Schedule Task 2.jpg (33.79KiB)Viewed 16185 times
Schedule Task 3.jpg
Schedule Task 3.jpg (14.42KiB)Viewed 16185 times
Schedule Task 4.jpg
Schedule Task 4.jpg (13.27KiB)Viewed 16185 times
Schedule Task 5.jpg
Schedule Task 5.jpg (12.39KiB)Viewed 16185 times
Schedule Task 6.jpg
Schedule Task 6.jpg (12.4KiB)Viewed 16185 times
Schedule Task 7.jpg
Schedule Task 7.jpg (14.51KiB)Viewed 16185 times
Schedule Task 8.jpg
Schedule Task 8.jpg (19.29KiB)Viewed 16185 times
Schedule Task 9.jpg
Schedule Task 9.jpg (53.94KiB)Viewed 16185 times
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

shell script to create a m3u playlist locally

Post by phibertron » Fri Feb 08, 2013 12:37 am

Code: Select all

forthcoming shell script m3u on the to do list
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

shell script to create a wpl playlist locally

Post by phibertron » Fri Feb 08, 2013 12:40 am

Code: Select all

forthcoming shell script wpl on the to do list
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

shell script to create a m3u playlist on twonky server

Post by phibertron » Fri Feb 08, 2013 12:46 am

Code: Select all

forthcoming shell script m3u on the to do list
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

shell script to create a wpl playlist on twonky server

Post by phibertron » Fri Feb 08, 2013 2:33 am

Code: Select all

forthcoming shell script wpl on the to do list
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

shell script scheduling to automate playlist script

Post by phibertron » Fri Feb 08, 2013 2:40 am

shell scheduled task on the to do list
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: How to generate a playlist with random tracks from Twonk

Post by phibertron » Fri Feb 08, 2013 3:06 am

Notes:

- the next version will eliminate the possibility of random duplicates

- if doing this in a native shell script was easy, I would do it, else you need addons

- I have always had better luck with WPL playlists, why I dont know, maybe its me

- When a playlist is added to the music share, this is where it will show up
Untitled.jpg
Untitled.jpg (20.43KiB)Viewed 16171 times
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

User avatar
phibertron
Posts:1566
Joined:Sun Jan 30, 2011 5:52 pm
AV Hardware:Hardware
========
WHS - HP Ex495
PS3
XBOX 360
iTouch - Gen 2 and Gen 3
PSP - 3000

Encoders
========
Handbrake
x264
ffmpeg
mencoder

Tagging
======
mp3tag

Re: How to generate a playlist with random tracks from Twonk

Post by phibertron » Tue Feb 12, 2013 3:31 am

thread is still in progress of being posted
I will make a closing post when its done
thanks
viewtopic.php?f=2&t=10627
viewtopic.php?f=2&t=9353
viewtopic.php?f=2&t=9408
viewtopic.php?f=2&t=9416
viewtopic.php?f=2&t=9424
viewtopic.php?f=2&t=9364
viewtopic.php?f=2&t=9497

Locked