It is currently May 17th, 2024, 7:10 am

Possibility? Now Playing Art gird

Get help with creating, editing & fixing problems with skins
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Possibility? Now Playing Art gird

Post by Lightz39 »

I was looking at some lua and it doesn't seem like it will be too too hard to copy a file. It seems it can copy and move fairly easily. Then again, I don't know lua.

But basically what I think I will need to do is

Grab the file path of the album art from PlayerType=Cover. Copy that file to a folder inside the skin called "AlbumArt". Have it be called 0. If 0 is there 1. If 1 is there 2. Etc...up to 24. Once it reaches 24 it can start overwriting from 0 up. This sounds like it could be hard for a noob.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Possibility? Now Playing Art gird

Post by Kaelri »

I think this may help you. It's a method for reading a file in Lua and saving it to a new location. (Thanks to my fellow devs for setting me straight on some IO functions.) The example uses "1.png" as the original file, and "2.png" as the new file. 2.png does not have to exist before you run the function.

Code: Select all

local OpenImagePath = SKIN:MakePathAbsolute('1.png')
local OpenImageFile = io.open(OpenImagePath, 'rb')
local OpenImageData = OpenImageFile:read('*all')
OpenImageFile:close()

local SaveImagePath = SKIN:MakePathAbsolute('2.png')
local SaveImageFile = io.open(SaveImagePath, 'wb')
SaveImageFile:write(OpenImageData)
SaveImageFile:close()
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Possibility? Now Playing Art gird

Post by Lightz39 »

Excellent, this is a start. If this ever gets completed I can release it as an example along side my skin and those who chipped in will get credit.

EDIT: An example of what it will look like hopefully. Thinking about it you could use this for more than just the "Nothing is going on" image. You can make it big enough to be a wallpaper. You could have it be just a stationary updated image. Etc...

Image
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Possibility? Now Playing Art gird

Post by Lightz39 »

Kaelri wrote:I think this may help you. It's a method for reading a file in Lua and saving it to a new location. (Thanks to my fellow devs for setting me straight on some IO functions.) The example uses "1.png" as the original file, and "2.png" as the new file. 2.png does not have to exist before you run the function.

Code: Select all

local OpenImagePath = SKIN:MakePathAbsolute('1.png')
local OpenImageFile = io.open(OpenImagePath, 'rb')
local OpenImageData = OpenImageFile:read('*all')
OpenImageFile:close()

local SaveImagePath = SKIN:MakePathAbsolute('2.png')
local SaveImageFile = io.open(SaveImagePath, 'wb')
SaveImageFile:write(OpenImageData)
SaveImageFile:close()
Couple questions. First I want to understand this so is this opening the file in binary mode, looking at it and before it closes saves a copy to another location?

Second like the others suggested when I change the song it takes the image path and puts it in a variable. What do I do in the script to take that variable and use it for the image path?

Example: I change the song and my variable "Artpath" is updated to say Artpath=C:\Users\Tyler\AppData\Local\Temp\jpg91D1.tmp

Now looking at that lua code I assume where you have OpenImagePath and SaveImagePath I put the folders I want to look in and save to. How do I make it so it knows the file I want to open is "jpg91D1.tmp". Since the file name changes periodically I'll have to have the variable updateable.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Possibility? Now Playing Art gird

Post by Kaelri »

Lightz39 wrote:Couple questions. First I want to understand this so is this opening the file in binary mode, looking at it and before it closes saves a copy to another location?
Close. What it does is open the file in binary mode, save the raw binary data as a variable (technically a string) in Lua, close the file, then open the new file location (in "write" mode) and write the same data to the new file. The result is the same, but it's helpful to understand the concepts behind "open," "read," "write" and "close."[/quote]
Lightz39 wrote:Second like the others suggested when I change the song it takes the image path and puts it in a variable. What do I do in the script to take that variable and use it for the image path?
That would be GetVariable('VariableName'). If the path comes from a measure like NowPlaying, you can also skip the variable and use Measure:GetStringValue().

See the manual for more detailed information.
Lightz39 wrote:Now looking at that lua code I assume where you have OpenImagePath and SaveImagePath I put the folders I want to look in and save to. How do I make it so it knows the file I want to open is "jpg91D1.tmp". Since the file name changes periodically I'll have to have the variable updateable.
With variables and measures, Lua will always use the current value at the time that it "gets" the value. So if the GetVariable or GetStringValue is placed in the "Update" function, the value in Lua will be updated each time the Script measure updates, just as if you were using a dynamic variable on a regular measure.
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Possibility? Now Playing Art gird

Post by Lightz39 »

I'm starting to understand now. Thank you. Hopefully this little project gets me on the right track to learning more of this stuff.
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Possibility? Now Playing Art gird

Post by Lightz39 »

I need some help with the lua script. This is what i've come up with so far. Not sure if its correct or not. Still trying to wrap my head around this stuff.

Code: Select all

function Initialize()
   FilePath = SKIN:GetMeasure('mAlbumArt')
end

fuction Update()
   FilePath:GetStringValue()
   local OpenImagePath = SKIN:MakePathAbsolute('FilePath')
   local OpenImageFile = io.open(OpenImagePath, 'rb')
   local OpenImageData = OpenImageFile:read('*all')
OpenImageFile:close()

local SaveImagePath = SKIN:MakePathAbsolute('C:\Users\Tyler\Documents\Rainmeter\Skins\Album Grid\Album Art\0.png')
local SaveImageFile = io.open(SaveImagePath, 'wb')
SaveImageFile:write(OpenImageData)
SaveImageFile:close()
end
Not sure if this is correct or not as it isn't working. Also how would I execute this in my skin?
OnTrackChange=[!CommandMeasure "mScript"]
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Possibility? Now Playing Art gird

Post by Kaelri »

Just a few things to check. First, FilePath:GetStringValue() needs to be assigned to a new variable name. "FilePath" is not actually a path right now; it's what we call a "handle," an identifier for the measure that will later return the filepath as a value. To keep things simple, I usually just name it after the measure.

Code: Select all

function Initialize()
   mAlbumArt = SKIN:GetMeasure('mAlbumArt')
end

fuction Update()
   FilePath = mAlbumArt:GetStringValue()
   ...
Second, this: SKIN:MakePathAbsolute('FilePath') When a value in Lua is in quotes - either 'value' or "value" - that means Lua will use the literal string as a value. Obviously, "FilePath" is not a real filepath. ;) Always make sure to use Lua variable names without quotes.

Code: Select all

local OpenImagePath = SKIN:MakePathAbsolute(FilePath)
And third: local SaveImagePath = SKIN:MakePathAbsolute('C:\Users\Tyler\Documents\Rainmeter\Skins\Album Grid\Album Art\0.png') Lua uses the backslash as an "escape character," so that you can use quotes and other special characters within a string. To use a literal backslash, you just have to double them up.

Code: Select all

local SaveImagePath = SKIN:MakePathAbsolute('C:\\Users\\Tyler\\Documents\\Rainmeter\\Skins\\Album Grid\\Album Art\\0.png')
Lightz39
Posts: 98
Joined: August 1st, 2012, 12:48 am

Re: Possibility? Now Playing Art gird

Post by Lightz39 »

I was wondering about the double \\ this helps a lot. Thank you :welcome:
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Possibility? Now Playing Art gird

Post by MerlinTheRed »

This might work. Of course this won't be all you need. I'd make a loop over all 25 images and copy image 24 to 25, then 23 to 24, etc. If an image does not exist, you can check that and just go on without copying. Then at the end copy your current image to 0.png.

Code: Select all

function Initialize()
   FilePath = SKIN:GetMeasure('mAlbumArt')
end

fuction Update()
   FilePath:GetStringValue()
   local OpenImagePath = FilePath:GetStringValue()
   local OpenImageFile = io.open(OpenImagePath, 'rb')
   local OpenImageData = OpenImageFile:read('*all')
OpenImageFile:close()

local SaveImagePath = SKIN:ReplaceVariables('#ROOTCONFIGPATH#Album Art\0.png')
local SaveImageFile = io.open(SaveImagePath, 'wb')
SaveImageFile:write(OpenImageData)
SaveImageFile:close()
end
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!