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

I think I fixed the navigation glitches.
Also now displays file size, although it is dependent upon having a server directory listing that puts the filesize in a <td class="s"> tag, since I couldn't think of another way to parse it. For now I'm just hoping it's not specific to lighttpd, but I may need to find a better way to do it.
EDIT: It appears that Apache doesn't use tables for directory listings, so I'm definitely going to need a new solution for file sizes. Seems to have been easier than I thought:
filesize=string.gsub(l,".*>([%d%.]-[KMG])<.*","%1")
I wouldn't be surprised if this is still not universal, but it will at least work for more than just lighttpd servers.

I moved the buttons off the visible interface, since there is already keyboard and double-click behavior to handle the same tasks as clicking the buttons.

EDIT2: fixed the ext loop to search for the extension at the end of the string, and to break if it matches.

EDIT3: It seems that having the main menu being dictated by the script is silly, when the server can easily just set up a "media" directory. Please bear with me...I'm not an expert with web servers, and things are likely to change a lot from week to week =o)
It's now set up so that there is a plain directory structure starting with "host", and what the server wants to do from that point is the server's problem.

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/media"


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

function get_menu()
--box:clear()
--box:add("video/")
--box:add("audio/")
level=0
dir=host
get_files()
box:remove(1) -- get rid of the ../
while pos[1] do table.remove(pos) end
box:value(pos[level])
end

function get_files()
box:clear()
body,code,header=socket.http.request(dir)
for l in string.gmatch(body,"<a href=.-\n") do
filename=string.gsub(l,"<a href=\"(.-)\".*","%1")
--filesize=string.gsub(l,".*<td class=\"s\">(.-)</td>.*","%1")
filesize=string.gsub(l,".*>([%d%.]-[KMG])<.*","%1")
  if string.find(filename,"\/$") then box:add(filename) end
  for k,v in pairs(ext) do
    if string.find(string.lower(filename),"%."..v.."$") then
      box:add(filename.."\t"..filesize)
      break
    end
  end
end
fresh:activate()
if not pos[level] then pos[level]=1 end
box:value(pos[level])
end

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

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

function go_forward()
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=550,400,25
bw=ww/3
win=fltk:Fl_Double_Window(ww,wh,"Movies")
box=fltk:Fl_Hold_Browser(0,0,ww,wh); box:callback(dubbleclik)
box:column_widths({ww-100,100,0})
pack=fltk.Fl_Pack(0,wh,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
get_menu()

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

This post was last modified: 01-19-2010 02:25 PM by mikshaw.

01-19-2010 04:25 AM
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-19-2010 04:25 AM

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

Forum Jump: