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

This one works with mplayer, and probably smplayer.
For VLC, subflag=" --sub="..subtmp.." " should work.
In Media player Classic, apparently use subflag=" /sub "..subtmp.." " (might need extra quotes around the filename?)
I don't think Windows Media Player will work.

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" }

subtmp=os.tmpname()

function get_menu()
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,".*>([%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()
realfile=string.gsub(box:text(box:value()),"\t.*","")
subfile=string.gsub(realfile,"%.%w-$","%.srt")
if string.find(body,"<a href=\""..subfile.."\"") then
subdata,y,z=socket.http.request(dir.."/"..subfile)
my_filename=io.open(subtmp,"w")
if my_filename then
  my_filename:write(subdata)
  my_filename:close()
end
subflag=" -sub "..subtmp.." "
else subflag=" "
end
win:iconize()
Fl:check()
os.execute(player..subflag..dir.."/"..realfile)
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

function quit()
os.remove(subtmp)
os.exit()
end

ww,wh,bh=550,400,25
bw=ww/3
win=fltk:Fl_Double_Window(ww,wh,"Movies")
win:callback(quit)
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)
fltk:Fl_End()

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

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

02-01-2010 08:10 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 - 02-01-2010 08:10 AM

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

Forum Jump: