News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
access to media files on a LAN server
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
access to media files on a LAN server

I recently spent a decent amount of time researching ways to stream media over a LAN server, and after wading through many sites talking mostly about Flash and other heavy options I eventually learned that some of the media players we all have installed already support streaming directly from a regular http/ftp link. For a few days I was playing around with mplayer and VLC, and it always came down to having to either copy and paste URLs or use a playlist that automatically starts playing.

So i decided to make a script that would bypass the need for a browser just to get a link and just run your chosen media player when you found what you wanted.

Note that this might not be suitable in any situation other than what I use it for, which is a local network, and it hasn't been tested for problems that might arise as a result of the server or any of the desired files being unavailable. Also note that it was written specifically to access one file at a time (i.e. a movie), not a playlist, and it DOES NOT SUPPORT SUBDIRECTORIES beyond what is listed in url[#] at this time. Subdirectories might actually break it, though so far they just seem to create a blank browser.

Requires a file host.."/lua_menu" which contains commands that add data to two tables, label and url. The format is:
label[1]="this is a label for dir 1"; url[1]="/this/is/the/dir/where/label1/files/live"
The URL must be a directory containing regular media files only (at this point), and if the host variable doesn't end with a slash, url must begin with a slash (url begins where host leaves off).

As always, bug reports and suggestions are welcome. I know I do sloppy work with tables, so if something better is suggested (while not making lua_menu more complicated to edit) I'd like that.

On a side note, it appears that Windows opens a cmd window when os.execute() is run. Is this because I used Progra~1 instead of trying harder to use the real path, or does that always happen with os.execute()?

Yet another note: the "srt" exception was added because I have some movies with srt subtitles...they work when I play the movies locally, but they serve no purpose when accessed through the network....one of these days I'm going to find out about serving subtitle files.

Code:
-- USER CONFIGURATION

--player="C:\\Progra~1\\SMPlayer\\smplayer.exe" -- Windows
player="mplayer" -- Linux
host="http://myhost/videos"

-- END USER CONFIGURATION

label={}; url={}
-- retrieve the menu from server
menufile,c,h=socket.http.request(host.."/lua_menu")
assert(loadstring(menufile))()

function get_menu()
box:clear()
for i,v in pairs(label) do
  box:add(v)
end
menu_up=1
end

function get_files()
box:clear()
body,code,header=socket.http.request(dir)
for l in string.gmatch(body,"<a href=\"(.-)\"") do
  if not string.find(l,"\.srt$") and not string.find(l,"\/") then
  box:add(l)
  end
end
menu_up=0
end

function play()
if box:value() > 0 and menu_up==0 then
  win:hide()
  Fl:check()
  os.execute(player.." "..dir.."/"..box:text(box:value()))
--  os.exit()
  win:show()
end
end

function menu_choice()
if box:value() > 0  and menu_up==1 then
dir=host..url[box:value()]
get_files()
end
end

ww,wh,bh=420,400,25
bw=ww/3
win=fltk:Fl_Window(ww,wh,"Movies")
box=fltk:Fl_Hold_Browser(0,0,ww,wh-bh); box:callback(menu_choice)
go=fltk:Fl_Button(0,wh-bh,bw,bh,"play"); go:callback(play)
fresh=fltk:Fl_Button(bw,wh-bh,bw,bh,"menu"); fresh:callback(get_menu)
no=fltk:Fl_Button(bw*2,wh-bh,bw,bh,"quit"); no:callback(function() os.exit() end)

--table.sort(menu)
get_menu()

--win:resizable(box)
win:show()
Fl:run()

01-10-2010 01:33 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
access to media files on a LAN server - mikshaw - 01-10-2010 01:33 PM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: