Welcome, Guest
Please Login or Register.    Lost Password?

Matching table result to a second table
(1 viewing) (1) Guest
Go to bottomPage: 12345
TOPIC: Matching table result to a second table
#20832
Re:Matching table result to a second table 5 Months, 2 Weeks ago  
Getting it to run independantly of Rainlendar would be great. I didn't know you could do that. Right now the input folders are defined in the skin file. This is all modified straight from the photo widget so I guess I'm not really writing it, I'm just changing it.

In the skin.xml file under:
<variables>
<variable name="Movie_folder" default="" type="folder" window="Movie" description="Defines the local folder which is scanned for movies." />

<variable name="Movie_menu" default="" type="folder" window="Movie" description="Defines the local folder which is scanned for photos." />


In the elements.xml file:
<elements>
<bitmap id="bitmap.movie.nopic" file="images/movie/movie-nopic.png" />


So when you add the widget and go to settings it is listed in the variables for you to choose where your 2 folders are. (Photo widget had one already.)

Since my last post I found a bug where the last file in each folder was not being read so I updated the code:

m = 1
p = 1
repeat
repeat
if g_Shadow4_Movie_MovieName[m] == g_Shadow4_Movie_PicName[p] then
table.insert(g_Shadow4_Movie_Link, g_Shadow4_Movie_Pic[p])
m = m + 1
p = 1
break
else p = p + 1
end
until p == (#g_Shadow4_Movie_Pic + 1)
if p >= #g_Shadow4_Movie_Pic then
table.insert(g_Shadow4_Movie_Link, "None")
p = 1
m = m + 1
end
until m == (#g_Shadow4_Movie_Name + 1)

The main problem with this code is that the movie file name and the picture file name must be exact (not the extension). This disappoints me because I wanted to add tv shows and they have different episode names. Not that big of a deal as I'm sure I can find a workaround, but figuring out how to get partial string matches would be awsome.

As for feeding it empty folders, I cannot test that yet as the script is only partially modified so far. I must first remove all traces of the old photo functions before trying.
SereneSavage
Junior Boarder
Posts: 28
graphgraph
User Offline Click here to see the profile of this user
Gender: Female Location: Canada
The administrator has disabled public write access.
 
#20846
Re:Matching table result to a second table 5 Months, 1 Week ago  
I have another question to anyone who may have knowledge.

Some of my urls don't open the movies. Those problem files contain apostrophes ('). If the file name is "Gilligan's Island", it will show the picture with the same name, it will show the name properly, but when I try to open the movie the button does nothing.
There is nothing wrong with the button, when I switch to another folder with files that have no ' in the title it works fine.

I read a little bit about how urls think ' means something special. I'm asking if there is a way to make Lua execute the url using the filename exactly as it is, without thinking ' is a special character.

Any suggestions?
SereneSavage
Junior Boarder
Posts: 28
graphgraph
User Offline Click here to see the profile of this user
Gender: Female Location: Canada
The administrator has disabled public write access.
 
#20847
Re:Matching table result to a second table 5 Months, 1 Week ago  
I'm not sure what the problem is, but if it is caused by the apostrophe you can "escape it" and see if that helps.

GSUB: replace string within a string. \' is the escape form of '
Code:

str = str:gsub("'", "\'"))    -- this does not work
str = str:gsub("\'", "\\\'"))       -- this will replace ' to \'

Jorge_Luis
Platinum Boarder
Posts: 792
graphgraph
User Offline Click here to see the profile of this user
Gender: Male My Rainlendar Skins Location: Argentina Birthday: 03/15
Last Edit: 2014/03/20 07:38 By Jorge_Luis.
The administrator has disabled public write access.
 
#20848
Re:Matching table result to a second table 5 Months, 1 Week ago  
I'm not sure this will work. If I understand correctly this will change the string to read Gilligan\\\s Island. If that is so, the filename on my hard drive is still Gilligan's Island.
Will a string that reads Gilligan\\\s Island be able to open a file that's named Gilligan's Island and be used as a proper url?
SereneSavage
Junior Boarder
Posts: 28
graphgraph
User Offline Click here to see the profile of this user
Gender: Female Location: Canada
The administrator has disabled public write access.
 
#20853
Re:Matching table result to a second table 5 Months, 1 Week ago  
After some test, I found the apostrophe not caused the problem.
Following is my part codes, You can refer :
Code:

  path = "D:\\Sharware\\Desktop\\WinSnap\\MyPic\\"
  file = "Ordinary's logo"
  url = "file://" .. path .. file .. ".png"
  for count = 1,16 do
    Rainlendar_SetElementValue(skin, "bitmap.movie.photo." .. count, "file", path .. file ..".png")
    Rainlendar_SetItemValue(window, "testskin.pic.".. count, "element", "bitmap.movie.photo.1")
  end
  Rainlendar_Redraw(0, window)
  -- following is for debug. if need, check the string of url
  -- Rainlendar_Message(url, 4)

anoob
Platinum Boarder
Posts: 500
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: TaiChung, Taiwan, R.O.C. Birthday: 02/12
The administrator has disabled public write access.
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com
 
#20877
Re:Matching table result to a second table 5 Months, 1 Week ago  
SereneSavage wrote:
Nilfred your second post made my head explode.
"return string.match(path, "(.-)([^\\/]-)(%.?[^%.\\/]*)$")"
What?!? Really?
I think table merging/reordering is a little over my head for now.

LOL, well, hope this time I better explained what that function do; so You don't have to look inside
As I said, here You are the hash way...
This hashed version is hard to sort, so is not sorted anymore:
Code:

--
-- Hash approach explained
--

-- For debug purposes insert/remove --/--- below:
--[[
local function Rainlendar_Log( line )
  print(line)
end
--]]

--
-- Split Linux and Windows paths
--
-- Input: (string) A well formed full path to a file
-- Return: (array) { folder, filename without extension, extension with dot }
local function Movies_SplitPath(path)
  return string.match(path, "(.-)([^\\/]-)(%.?[^%.\\/]*)$")
end
-- Return shit if input is also shit or there is no dot

local A = {
"Finding Nemo.avi", 
"Ice Age.flv", 
"Shrek.mp4", 
"The Little Mermaid.mpg", 
"The Wizard of Oz.mkv",
}

local B = {
"Finding Nemo.bmp", 
"Shrek.jpg", 
"The Little Mermaid.gif", 
"The Wizard of Oz.png", 
"Picture Not Found.jpg"
}

local hA = {}
local hB = {}

--
-- Convert arrays A and B to hashes
--
local function Movies_Array2Hash()
  local path, file, extension

  -- Convert list B to a hash of array
  for i = 1, #B do
    path, file, extension = Movies_SplitPath(B[i])
    hB[file:lower()] = { path, file, extension }
  end

  -- Convert list A to a hash of array
  Rainlendar_Log("=== Movies start conversion ===")
  for i = 1, #A do
    path, file, extension = Movies_SplitPath(A[i])
    hA[file:lower()] = { path, file, extension }
    if hB[file:lower()] == nil then 
      hB[file:lower()] = {"", "Picture Not Found", ".jpg"}
    end
    -- Exploit this loop for debug output
    Rainlendar_Log(table.concat(hA[file:lower()]) .. " = " .. table.concat(hB[file:lower()]))
  end
  Rainlendar_Log("==== Movies end conversion ====")
end

--
-- List all available items to debug log
--
local function Movies_ListAllMoviesToLog()
  for file, path in pairs(hA) do 
    Rainlendar_Log(table.concat(path) .. " = " .. table.concat(hB[file]))
  end
end

--
-- Return a picture path for a movie
--
local function Movies_SearchForMovie(file)
  -- local path, file, extension = Movies_SplitPath(title)
  if hA[file:lower()] == nil then 
    return table.concat({"", "Picture Not Found", ".jpg"})
  else
    return table.concat(hB[file:lower()])
  end
end

Movies_Array2Hash()

Movies_ListAllMoviesToLog()
Rainlendar_Log("Movies search result: " .. Movies_SearchForMovie("sHrEk"))


I copy functions names from Jorge_Luis code for the sake of comparability.
Result:
Code:

=== Movies start conversion ===
Finding Nemo.avi = Finding Nemo.bmp
Ice Age.flv = Picture Not Found.jpg
Shrek.mp4 = Shrek.jpg
The Little Mermaid.mpg = The Little Mermaid.gif
The Wizard of Oz.mkv = The Wizard of Oz.png
==== Movies end conversion ====
Shrek.mp4 = Shrek.jpg
The Little Mermaid.mpg = The Little Mermaid.gif
Ice Age.flv = Picture Not Found.jpg
Finding Nemo.avi = Finding Nemo.bmp
The Wizard of Oz.mkv = The Wizard of Oz.png
Movies search result: Shrek.jpg


It do the same as my other code, but It's shorter and It do not sort the result, indeed It random sort the list

When I said "run outside of Rainlendar" is for debug purposes, I should have said "run in a terminal output", because I test my lua scripts in terminal first.

I still can't find where dirtree() is defined, but better I ask You for the output of dirtree() and work from there. As You defined A and B in your first post.
Nilfred
Junior Boarder
Posts: 23
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: Argentina
The administrator has disabled public write access.
 
Go to topPage: 12345
get the latest posts directly to your desktop