I made this alternative media streaming thing... Feedback?

Post Reply
pingnak
Posts: 4
Joined: Thu May 07, 2015 7:58 pm

I made this alternative media streaming thing... Feedback?

Post by pingnak » Thu May 07, 2015 8:12 pm

Free, open source, don't-give-a-fuck license, etc.

If you can configure the web server on a NAS, you can stream directly to HTML5 compatible browsers, and do 'HD', even if your NAS has a peanut for its brain.

It works if you can only click on files, too.

https://github.com/pingnak/videowebscript

https://github.com/pingnak/videowebscript/wiki

Basically tools and examples for generating a web UI on top of video and audio collections. Even supports various kinds of play lists for the audio. Highly customizable, too.

It doesn't *replace* DLNA. It's just way better than it on PCs, notebooks, tablets, phones, since you don't have to install any software on the device in order to play, and loading up the UI is super snappy.

The main requirement is web compatible media. If you already have MP4 files, the video is easy to use. You probably already have MP3 files. Since it's already in a format the client plays natively, the NAS doesn't need any brains on its end, to (in some cases BADLY) convert the streams on the fly.

Mijzelf
Posts: 6197
Joined: Mon Jun 16, 2008 10:45 am

Re: I made this alternative media streaming thing... Feedbac

Post by Mijzelf » Sat May 09, 2015 8:07 pm

Very nice! Thanks for sharing.

You didn't actually test this on a NAS, I guess? I never saw a NAS which runs bash, out of the box. They all use busybox sh.

To get your 'jukeboxscript.sh' running on my ZyXEL NAS540 I had to:
  • Change the SheBang to #!/bin/sh
  • Change the function headers:

    Code: Select all

    function uri_escape{
    to

    Code: Select all

    uri_escape() {
    (Which is still accepted by bash, btw)
  • Change the arguments of 'sort'. (On my box busybox sort doesn't support long arguments.). sort -u -i -f did the job.
  • pushd and popd are not supported at all. I added the functions to the script.

    Code: Select all

    pushd()
    {
    	pwd >>/tmp/$$.pushed
    	cd "$1"
    }
    
    popd()
    {
    	local last=$( tail -n 1 /tmp/$$.pushed )
    	sed -i '$ d' /tmp/$$.pushed
    	cd "$last"
    }
Further I had to manually edit the generated pages. For some reason there are a lot of spurious '%27' in the urls:

Code: Select all

<div class="index_entry" title="Play 08-A Fool Am I" style=''><a href="./Agnetha%20Fältskog%27/Jukebox.html?./08-A%20Fool%20Am%20I.mp3%27">08-A Fool Am I</a></div>
Some other possible problem: The script uses perl. My box happens to have that, but that is not common, for budget NAS boxes. Unfortunately my knowledge of perl is below usable, so I couldn't deduce what it actually does here. I wonder if it can be exchanged by sed and/or awk, which are both generally available. (The busybox versions, of course).

pingnak
Posts: 4
Joined: Thu May 07, 2015 7:58 pm

Re: I made this alternative media streaming thing... Feedbac

Post by pingnak » Sun May 10, 2015 1:43 am

Thank you!

I tested the 'served html from NAS' part extensively, but I never once thought to run the shell scripts directly on the NAS box.

Like the AIR apps, they were only designed and tested on PCs connected to the NAS (OS X and a VM with Ubuntu Linux). I suppose some kinda masochist could hypothetically run them directly on the NAS... because you apparently did just that :). They crawl through a couple of thousand files a minute on my slow, old DiskStation, over smb, which was 'fine' for me, because I don't have that many 'thousands' of anything.

I'll make most of your changes, test and commit soon-ish.

As for perl... well, I have a problem. Inserting the content into the files, inline, where those 'magic keys' exist.

I went to all the trouble to convert the long list of 'bits of html file', from earlier versions, into mostly one file, though I ended up dragging some of the CSS back out, because it was more convenient for 'customizing' it. I did all of that in the Adobe AIR apps first, then went back and tried to figure out how to do it in the shell script.

I use sed for most of my regex needs, but it doesn't work so well for multiline substitutions, like that. The only workable examples I found online to merge a file into another file on matches were based on 'perl one liners'. I suppose I could have just written the whole thing in perl or python, but I'd have to... learn perl or python.

As for the trailing %27, that's an apostrophe/single-quote. Something is probably working just subtly different in sed, or how sh is interpreting quotes. I think we could get away with removing that %27 from the uri_escape function, because all of my XML attributes are double-quoted (so a single quote in the path won't 'break' it).

Mijzelf
Posts: 6197
Joined: Mon Jun 16, 2008 10:45 am

Re: I made this alternative media streaming thing... Feedbac

Post by Mijzelf » Thu May 14, 2015 2:29 pm

Masochist? Running the script on the nas is actually easier. If I run it on my desktop I'll have to mount the volume first, as bash cannot handle smb:// links. And I tested it, it runs faster on my nas. Most time is spent scanning the directories, I guess, and so the extra network layer slows it down. And using a inotify script I can let the script run automatically when content is added.

Tested your new script, and now it worked flawlessly. Yet I have one suggestion about the push/popd part. That can be done automatically by

Code: Select all

mypushd() {
   ...
}

mypopd() {
 ...
}

PUSHD=pushd
POPD=popd
pushd / >/dev/null 2>&1 && popd >/dev/null || { 
    PUSHD="mypushd" 
    POPD="mypopd" 
}
This has to be executed before the 'set ...' commands, as pushd will fail when it doesn't exist.

pingnak
Posts: 4
Joined: Thu May 07, 2015 7:58 pm

Re: I made this alternative media streaming thing... Feedbac

Post by pingnak » Sun May 17, 2015 6:58 pm

I integrated your latest changes, but following your initial feedback, down the primrose path, I made python versions of the scripts, that I will be maintaining from now on. Python turned out to be 'easy', and it has the advantage of working on Windows, too (well, you still have to install python and add it to your path, but there's only the ONE thing to install and configure).

Python runs significantly faster, trivially does some internal parallelizing, and at least for Synology and WD EX4 boxes, it's present. It's no worse than expecting perl to be there, anyway.

I don't routinely log into my NAS through SSH. The smb/afp work just fine for me, and are part of my normal file system mounts. It's basically a couple of mouse clicks to get the 'media' folder mounted and open. I never doubted it would be faster on the NAS, but it's 'good enough' for me to be finished with 2700 mp4 files in 70 folders in a minute, with the video indexer, and 4000 mp3 files and play lists in 140 folders in another 'about a minute'. In both cases, it was about one or two seconds of actual CPU time. I've run it on USB hard drives and SD media plenty of times. My poor old, slow DiskStation....

The python scripts handle almost everything that the AIR/GUI thing did, including nicely formatting the mini TOC, and generating player pages from common play list formats encountered in the tree where it's run. It's hardly any longer than the original shell mess (or at least the initial version wasn't).

There's also a nicer video playback UI that behaves a little better in kiosk/presentation mode, so you can put it in full screen mode, and keep it that way. In situations where I ran it from the file system, Chrome (for instance) would never let me exclude the pages from their annoying little modal 'You clicked a full screen button and are now in full screen mode and I won't let you do anything until you click me!' notification popups. So making every video player 'full screen', and clicking that away when played got kind of old.

I re-arranged the project a bit, so you could pick from all of the templates with a minor script tweak. The previous default video player is in the 'templates/VideoWebScript/original' folder.

pingnak
Posts: 4
Joined: Thu May 07, 2015 7:58 pm

Re: I made this alternative media streaming thing... Feedbac

Post by pingnak » Sun May 17, 2015 8:04 pm

Surprisingly, it's about the same speed on my NAS, as on my desktop. The Music script is even slower, mostly due to the peanut brain in my DiskStation, and the numerous play lists, and my very inefficient (but nearly universal) play list import.

Post Reply