User(s) browsing this thread: 1 Guest(s)
Script for Random playlist
|
|
12-08-2008, 09:30 AM
(This post was last modified: 12-15-2008 02:39 AM by grahams.)
|
|||
|
|||
|
Script for Random playlist
Hi I created the following script to generate Random jsp playlist. It works when a ssh into my pch and run "# sh random.cgi". However I no cgi expert and I can not get it run when I call it from an html file. Could someone let me know what I'm missing, thanks in advance.
Most of the script is borrowed from the "Sleek" theme and it needs some of the commands that sleek installs. I'm writing this as a simple shuffle tool. html file Code: <a href="http://localhost.drives:8883/HARD_DISK/random.cgi">Shuffle Playlist</a><br>The script Code: #!/bin/shIf I can get the above to run from the pch screen I plan to add the following to start playback. Code: <center> |
|||
|
12-08-2008, 01:43 PM
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
Just to double check...did you give the cgi file 777 file attributes?
|
|||
|
12-09-2008, 03:10 AM
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
Thansk for the quick reply.
Yeah, tried setting chmod 777 via a direct ssh connection. I did the same with a cgi for the sleek theme and that still worked, so I don't think it's a permissions thing. Should what I did work? i.e. write a shell script and save it as an cgi. |
|||
|
12-09-2008, 03:58 AM
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
Does it run using
./random.cgi instead of sh random.cgi Oversight: Jukebox | FeedTime: Automatic nzbs |
|||
|
12-09-2008, 05:57 AM
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
For CGI scripts, you have to follow a certain format. First, output all HTML headers, one per line. Then, output a blank line. Then output your content. Most of the headers are taken care of by the web server, but one header -- the Content-type header -- MUST be written by your script. So, for example, my a simple script to play one file might look like:
#! /bin/sh echo "Content-type: text/plain"; echo ""; file="`echo $1 | sed s/%20/\ /g`" file="`echo $file | sed 's|file:/opt|file:///opt|'`" echo "Playing $file..." killall -HUP mono mono -single "$file" 2>&1 -dram 1 exit 0; |
|||
|
12-09-2008, 07:36 AM
(This post was last modified: 12-09-2008 07:47 AM by grahams.)
|
|||
|
|||
RE: Script for Random playlist - need CGI help
(12-09-2008 03:58 AM)ydrol Wrote: Does it run using yes ./random.cgi also works when I'm ssh'd in to the pch just found the script actually works via the remote on the pch, the "can not process" error is a false negetive. (12-09-2008 05:57 AM)curien Wrote: For CGI scripts, you have to follow a certain format. First, output all HTML headers, one per line. Then, output a blank line. Then output your content. Most of the headers are taken care of by the web server, but one header -- the Content-type header -- MUST be written by your script. So, for example, my a simple script to play one file might look like: Thanks. I found that my cgi script actually does create the a random playlist when invoked via the pch browser. However the pch reports that it couldn't be processed, when it clearly was. I cleaned up the script (?), but it still falsely reports it couldn't be processed. Code: #!/bin/shIs there a trick to make this clean? |
|||
|
12-10-2008, 03:20 AM
(This post was last modified: 12-10-2008 03:22 AM by curien.)
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
OK, I got it working. I took out the randomization part because I don't have rl compiled for my NMT, but it should be easy enough to stick in. A few things to note:
1. You were storing temporary files where you didn't need them. Just keep piping! 2. Sed's really cool. You can give it multiple commands in one go. If you notice, I'm doing two replacements with one invokation of the sed command. Way better than a sed + tr (plus, your tr was throwing away the newline characters, which makes a mess of the playlist file). 3. You have to craft the link to the playlist specially -- the NMT browser uses non-standard HTML attributes to tell it that the file is a playlist. OK, so you need to files. One static HTML file to link to the playlist generator, and one to generate the playlist. There are NO temporary file! random.html is simple enough: <a href="http://localhost.drives:8883/HARD_DISK/bin/random.cgi" pod="2">random.cgi</a> OK, now for random.cgi: #! /bin/sh echo Content-type: text/plain echo "" find /opt/sybhttpd/localhost.drives/HARD_DISK/Music/ -name "*.mp3" | sed 's#^\(.*\)/\([^/]*\)#\2|0|0|file://\1/\2#; s/$/|/' | rl exit 0; That's it! Happy randoming. |
|||
|
12-10-2008, 08:37 AM
|
|||
|
|||
RE: Script for Random playlist - need CGI help
(12-10-2008 03:20 AM)curien Wrote: OK, I got it working. I took out the randomization part because I don't have rl compiled for my NMT, but it should be easy enough to stick in. A few things to note: Thanks Curien Tried your script. It starts up the player, it buffers then fails to load. Good tip on the sed options. Thought I need to delete newlines for jsp playlists, but I don't. Now no longer using the tmp files. My script runs, but still has the error. Combined the randiomize and play into 1 html and added other audio files to the shuffling. Code: <center>Code: #!/bin/shNote the commented out line for mono. This worked well, shuffled the songs and then started playing and showed the embedded album covers. However when I stop playing I get a blank screen and only power cycling cures it. Is there a way to gracefully return to the last page or homepage? |
|||
|
12-10-2008, 01:15 PM
|
|||
|
|||
RE: Script for Random playlist - need CGI help
(12-10-2008 08:37 AM)grahams Wrote: Tried your script. It starts up the player, it buffers then fails to load. The syntax for your link is wrong. aod doesn't mean anything. You use vod="playlist" ONLY for video; for audio, use pod="2". See <a href="http://www.networkedmediatank.com/download/docs/Syabas_browser_tag_2007_v1.2.html">here</a> for details. I guess you can't have audio and video files in the same playlist. (12-10-2008 08:37 AM)grahams Wrote: My script runs, but still has the error. The NMT's browser shows that "page failed to load" (or whatever it is) error if the script doesn't return any content. In theory, the cgi program is supposed to actually print an HTML (or other type of) page. That's why I had my script just print the playlist instead of saving it to a file. If you do that, and link to the cgi correctly for an audio playlist, you just need to run one link (the playlist) to generate it and start playing. (12-10-2008 08:37 AM)grahams Wrote: Change that to: Code: <a href="http://localhost.drives:8883/HARD_DISK/shuffle.cgi" pod="2">Shuffle</a>You won't need the other link (to the jsp file) at all anymore. (12-10-2008 08:37 AM)grahams Wrote: Take out the redirection (ie, remove the "> /opt/sybhttpd/localhost.drives/HARD_DISK/Music/random.jsp" part). By printing the results to stdout, you're actually sending it straight to the NMT's browser (as if you saved to a file and then clicked on a link to that file). (12-10-2008 08:37 AM)grahams Wrote: Note the commented out line for mono. This worked well, shuffled the songs and then started playing and showed the embedded album covers. However when I stop playing I get a blank screen and only power cycling cures it. Is there a way to gracefully return to the last page or homepage? I'm currently trying to figure that out myself. |
|||
|
12-10-2008, 10:39 PM
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
Do you think that this script could be used to play music videos as well?
I have a single folder with almost 2,000 music videos (mkv, mov, avi, mpg, etc.) that this would be great for. Cheers |
|||
|
12-10-2008, 11:24 PM
|
|||
|
|||
|
RE: Script for Random playlist - need CGI help
Yes, you'd need to change the filter for the find command to include those file types instead of the music types. Also, grahams is using a program called rl -- which is a standard Unix command but isn't on the NMT by default -- to randomize the playlist. Without it, you get the files in the same order every time. I'm not sure where he got it, or he might have cross-compiled it himself.
Finally, you have to link to the script like this: Code: <a href="/HARD_DISK/script.cgi" vod="playlist">Play movies</a> |
|||
|
12-11-2008, 03:58 AM
(This post was last modified: 12-11-2008 04:05 AM by grahams.)
|
|||
|
|||
RE: Script for Random playlist - need CGI help
(12-10-2008 11:24 PM)curien Wrote: Yes, you'd need to change the filter for the find command to include those file types instead of the music types. Also, grahams is using a program called rl -- which is a standard Unix command but isn't on the NMT by default -- to randomize the playlist. Without it, you get the files in the same order every time. I'm not sure where he got it, or he might have cross-compiled it himself. I haven't tried building a random video playlist, but editing mp3 to avi etc. should work. I found the rl command from the sleek theme. Also the find command is very basic by default but the sleek theme provides a full version which my script needs for -iname etc. If I can get this to work well I'll try building an install script and include these commands. BTW. the Sleek theme provides a way to randomize music and video I believe, but the theme itself only works well on 16:9 HD screens. (12-10-2008 01:15 PM)curien Wrote: The syntax for your link is wrong. aod doesn't mean anything. You use vod="playlist" ONLY for video; for audio, use pod="2". See <a href="http://www.networkedmediatank.com/download/docs/Syabas_browser_tag_2007_v1.2.html">here</a> for details. Thanks again. I cut and pasted your code directly which uses pod="2" I'm guessing to cure the false error, I need to just get the cgi script to return something to the browser. |
|||
|
12-15-2008, 02:21 AM
|
|||
|
|||
RE: Script for Random playlist - need CGI help
(12-11-2008 03:58 AM)grahams Wrote: I haven't tried building a random video playlist, but editing mp3 to avi etc. should work. Success A little bit of trail and error, luck and lots of help from Curien. The following works well shuffle.hmtl Code: <center>shuffle.cgi Code: #!/bin/shCurien, I found aod or pod work fine. "playlist" was the missing piece. Now to figure out how to make this easy for others to install (needs rl & full find commands). |
|||
|
12-15-2008, 04:29 AM
|
|||
|
|||
|
RE: Script for Random playlist
Code: /opt/sybhttpd/localhost.drives/HARD_DISK/.user_homepage/bin/find /opt/sybhttpd/localhost.drives/HARD_DISK/Music/ -type f \( -iname "*.mp3" -o -iname "*.wma" -o -iname "*.flac" -o -iname "*.ogg" -o -iname "*.mpc" \) -printcan be Code: find /opt/sybhttpd/localhost.drives/HARD_DISK/Music/ -type f | egrep -i '\.(mp3|wma|flac|ogg|mpc)$'Oversight: Jukebox | FeedTime: Automatic nzbs |
|||
|
01-05-2009, 05:21 AM
|
|||
|
|||
RE: Script for Random playlist
(12-15-2008 04:29 AM)ydrol Wrote: Thanks, using egrep makes it a lot cleaner. |
|||
|
« Next Oldest | Next Newest »
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies: | Views: | Last Post | |
| [Apps] Bierdopje 4 NMT PHP script | SilverViper | 4 | 1,304 |
11-26-2012 04:57 PM Last Post: Djiest |
|
| PCH Audio playlist format? | Nono | 4 | 1,733 |
10-05-2011 10:10 PM Last Post: Nono |
|
| Need help debugging a simple script to enable NTFS write on HDD | user33 | 10 | 3,175 |
04-05-2011 06:05 PM Last Post: nuke12 |
|
| Help with Server Timeout Error running a script | hindibuff | 0 | 1,669 |
03-29-2011 06:21 AM Last Post: hindibuff |
|
| Executing a script on the server from the NMT? | johnk | 6 | 3,175 |
02-21-2011 10:59 PM Last Post: johnk |
|
| [AUDIO] lastfm script (bookmarks, auto-login, etc.) | mk11 | 81 | 35,205 |
10-09-2010 01:45 AM Last Post: opfeifer |
|
| help with auto unrar script. | kiranos | 0 | 1,764 |
05-15-2010 10:24 AM Last Post: kiranos |
|
| Launch script after playing a video | antro31 | 4 | 1,947 |
04-03-2010 06:32 PM Last Post: antro31 |
|
| Create mono playlist ? | kdavid | 0 | 1,265 |
03-16-2010 07:17 PM Last Post: kdavid |
|
| Scheduled playback script | kdavid | 0 | 968 |
03-16-2010 10:27 AM Last Post: kdavid |
|

Twitter
Facebook
NMT Wiki
Search
Member List
Help
A-400 [13 May 2013]

Script for Random playlist



![[+]](images/collapse_collapsed.gif)

