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
RE: access to media files on a LAN server

Ok, thanks, I'll try that. I noticed that using sys.spawn as I previously posted was causing murgaLua to crash after a series of 1) running the spawn command, 2) stopping the command, and then 3) sending an event to the murgaLua window. For now I've gone back to os.execute()

I did a bit of a rewrite to the original script today, although it's a little buggy. I dumped the menu file in favor of a couple of main menu items set within the script. I had made the menu file originally just because my videos directory already had an index.html file in its root for the lan website, but that file was a bit of a pain to parse in Lua. Now since this script is a more convenient way to play the files than by using a web browser, I got rid of the index.html file so all directories behave the same...just have to grab the "<a href=" strings.

The bugs come from not-fully-worked-out subdirectory support. At this point it looks like it's mostly working, with the browser hopefully keeping track of which item in the previous directory was selected...but I haven't tested it enough to know how reliable it is.

Code:
#!/usr/bin/env murgaLua

-- access media files on a file server & stream in a player
-- mikshaw 2010

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


ext= { "mp3", "ogg", "flac", "avi", "mp4", "mov", "divx", "flv",
"mkv", "asf", "mpg", "mpeg", "wmv", "wav" }

function get_menu()
box:clear()
box:add("videos/")
box:add("mp3/")
level=0
box:value(1)
end

function get_files()
box:clear()
body,code,header=socket.http.request(dir)
for l in string.gmatch(body,"<a href=\"(.-)\"") do
  if string.find(l,"\/$") then box:add(l) end
  for k,v in pairs(ext) do
    if string.find(string.lower(l),"%."..v) then
      box:add(l)
    end
  end
end
fresh:activate()
if not pos[level] then pos[level]=1 end
box:value(pos[level])
--print(pos[level],dir)
end

function play()
win:hide()
Fl:check()
--sys.spawn(player,{dir.."/"..box:text(box:value())}) --crashes
os.execute(player.." "..dir.."/"..box:text(box:value()))
win:show()
end

function go_back()
--pos[level]=box:value()
dir=string.gsub(dir,"/[^/]-/$","")
level=level-1
if host==dir then get_menu()
else
get_files()
end
end

function go_forward()
--pos[level]=box:value()
dir=dir.."/"..box:text(box:value())
level=level+1
get_files()
end

function dubbleclik()
if Fl:event() == fltk.FL_RELEASE and Fl:event_clicks() > 0 then
navigate()
end
end

function navigate()
if box:value() > 0 then
pos[level]=box:value()
  if box:text(box:value())=="../" then go_back()
  elseif string.find(box:text(box:value()),"\/$") then go_forward()
  else play() end
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(dubbleclik)
pack=fltk.Fl_Pack(0,wh-bh,wh,bh)
pack:type(1)
go=fltk:Fl_Return_Button(0,0,bw,bh,"Open"); go:callback(navigate)
fresh=fltk:Fl_Button(0,0,bw,bh,"&Menu"); fresh:callback(get_menu)
no=fltk:Fl_Button(0,0,bw,bh,"&Quit"); no:callback(function() os.exit() end)
fltk:Fl_End()

pos={}
pos[0]=1
dir=host
get_menu()

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

This post was last modified: 01-18-2010 03:46 PM by mikshaw.

01-18-2010 03:32 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
RE: access to media files on a LAN server - mikshaw - 01-18-2010 03:32 PM

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

Forum Jump: