Get CurrentSong info; Need help with album art

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Get CurrentSong info; Need help with album art

Re: Get CurrentSong info; Need help with album art

by HELOX » Fri Jan 07, 2011 7:44 am

I'm going the database way now.

But guesse what, I get stuck.

I'm trying to make a package.

The installation should execute some code. And that code should create a table called "CurrentPlay". It should also create 5 rows. With 2 colums ID (1,2,3,4,5) and SongID (At creation all 0 (null)). I use the following code and I suppose this works good.

Install.ini

Code: Select all

[Header]
ID=CurrentPlay110107
Title=Currently Playing
Description=Puts the currently playing song in a table
VersionMajor=0
VersionMinor=0
VersionRelease=0
VersionBuild=0
Type=script

[Copy]
Src=CPUpdate.vbs
Tgt={app}\Scripts\auto\CPUpdate.vbs

[Execute]
File=CPCreate.vbs
CPCreate.vbs

Code: Select all

Dim SelectMethod
Dim SQLString
Dim objSongStringiterator
Dim Create

SelectMethod = 2

SQLString = "CREATE TABLE CurrentPlay(ID INTEGER PRIMARY KEY ASC, SongID)"
set objSongStringiterator = SDB.Database.OpenSQL(SQLString)

SQLString = "INSERT INTO CurrentPlay values(1,0)"
set Create = SDB.Database.OpenSQL(SQLString)

SQLString = "INSERT INTO CurrentPlay values(2,0)"
set Create = SDB.Database.OpenSQL(SQLString)

SQLString = "INSERT INTO CurrentPlay values(3,0)"
set Create = SDB.Database.OpenSQL(SQLString)

SQLString = "INSERT INTO CurrentPlay values(4,0)"
set Create = SDB.Database.OpenSQL(SQLString)

SQLString = "INSERT INTO CurrentPlay values(5,0)"
set Create = SDB.Database.OpenSQL(SQLString)
The Unistallation looks like this (I have no idea if it woks):

Unistall.ini

Code: Select all

[Delete]
File={app}\Scripts\auto\CPUpdate.vbs

[Execute]
File=CPDelete.vbs
CPDelete.vbs

Code: Select all

Dim SelectMethod
Dim SQLString
Dim objSongStringiterator
Dim Create

SelectMethod = 2

SQLString = "DROP TABLE CurrentPlay"
set objSongStringiterator = SDB.Database.OpenSQL(SQLString)

But now comes the problem. Made a auto-script to update the SongID of a specified ID.
But nothing seems to happen.
I used and changed the script from here: http://www.mediamonkey.com/forum/viewto ... f=2&t=5404 (a post from Steegy)
Now the code looks like this:

CPUpdate.vbs

Code: Select all

Option Explicit


Dim Update
Dim SelectMethod
Dim Row

Row = 1

SelectMethod = 2


Sub OnStartUp

  Script.RegisterEvent SDB, "OnPlay", "WriteSignatureFile"
  Script.RegisterEvent SDB, "OnStop", "DeleteSignatureFile"
  Script.RegisterEvent SDB, "OnShutDown", "DeleteSignatureFile"
  
End Sub

Sub WriteSignatureFile

  On Error Resume Next

  Dim oTrack
  Set oTrack = SDB.Player.CurrentSong

  SQLString = "UPDATE CurrentPlay set SongID='" & oTrack.SongID & "' WHERE ID='" & Row & "'"
  set Update = SDB.Database.OpenSQL(SQLString)

   
End Sub



Sub DeleteSignatureFile

  On Error Resume Next
  
  Dim oTrack
  Set oTrack = SDB.Player.CurrentSong

  SQLString = "UPDATE CurrentPlay set SongID='999' WHERE ID=" & Row & "'"
  set Update = SDB.Database.OpenSQL(SQLString)

  
End Sub

Could anyway find any problom in the code and/or an solution to solve it. Or got an other idea or work around?

Re: Get CurrentSong info; Need help with album art

by HELOX » Thu Jan 06, 2011 5:18 pm

Thank you Melloware. Although I think I need some more explanation since im new to vbs and new to MM.

I think writing it to the db is better than writing it to a file.

That creates new questions for me like. How do I create a table (SQL, doh! -> but in vbs code?) and ad some records in a 'installation script'. And than how to edit db data in a auto script? I'm used to (in php) have some code to connect to a db, but I can't seem to find it :X

There are also some more steps to take. But I will only ask if I can't find it myself.

Re: Get CurrentSong info; Need help with album art

by Melloware » Thu Jan 06, 2011 2:39 pm

Here is some pseudocode...

It checks whether the album cover is in the ID tag or is a Path to a picture and then shows you how to go about getting the path. I don't think you are worried if it is inside a tag only if ItemStorage == 1 which means its a JPG or file on disk somewhere.

Code: Select all

SDBAlbumArtItem artwork = null;
                    if ((track.AlbumArt != null) && (track.AlbumArt.Count > 0)) {
                        LOG.DebugFormat("Artwork Items Found = {0}", track.AlbumArt.Count);
                        artwork = track.AlbumArt.get_Item(0); // grab first one
                    }

                    if (artwork != null) {
                        if ((artwork.ItemStorage == 1) && (File.Exists(artwork.PicturePath))) {
                            LOG.DebugFormat("Artwork File Location: {0}", artwork.PicturePath);
                            response.AddArtwork(artwork.PicturePath);
                        } else if (artwork.ItemStorage == 0) {
                            LOG.DebugFormat("Artwork Tag: {0}", artwork.Description);

                            string tempFile = Path.GetTempFileName();

                            LOG.DebugFormat("Extracting image from tag: {0}", tempFile);
                            SDBTextFile artworkFile = MediaMonkey.Tools.FileSystem.CreateTextFile(tempFile, true);
                            try {
                                SDBImage image = artwork.Image.ConvertFormatEx(ArtworkResponse.RETINA_WIDTH, ArtworkResponse.RETINA_HEIGHT, "image/png", 100, 0, 1);
                                artworkFile.WriteData(image.ImageData, image.ImageDataLen);
                            } finally {
                                artworkFile.Close();
                            }
                            response.AddArtwork(tempFile);
                            File.Delete(tempFile);
                        }
                    }

Get CurrentSong info; Need help with album art

by HELOX » Thu Jan 06, 2011 5:36 am

Hello MediaMonkey community,

Since this is (one of) my first post I want first of all to say that MediaMonkey is a great piece of software. And that it can count on my support.
Secondly I want to say that my English is not as good as it should be. I'm still learning. If I make any grammatical mistake feel free to correct me.


I'm quite new to MediaMonkey and especially the scripting. I have no experience on vbs. (I do have with other languages though.)

I'm trying to make a (windows) screensaver that displays some information about the song that currently get played.
I'm gonna write the screensaver in C# (that will be no problem). I want to import the song info with a .txt file.
I found Click and Click very usefull.
I can get all the song info I want in the .txt except the album art path.

Here is an image that should display the whole idea.

So the question is does anyone got an idea how to get the AlbumArt path or get embedded AlbumArt extracted.

I'm looking forward too any solution or ideas. Sharing your vision can also be quite usefull. So feel free to reply any ontopic comments.


Until this point I got this:

Code: Select all

Option Explicit

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim sSignatureFileName
sSignatureFileName = "C:\Users\Wouter\Desktop\NowPlayingSignature.txt"


Sub OnStartUp
  Script.RegisterEvent SDB, "OnPlay", "WriteSignatureFile"
  Script.RegisterEvent SDB, "OnStop", "DeleteSignatureFile"
  Script.RegisterEvent SDB, "OnShutDown", "DeleteSignatureFile"
End Sub


Sub WriteSignatureFile
  On Error Resume Next
  Dim oSignatureFile, oTrack, sAlbumArtist
   
  Set oSignatureFile = oFSO.CreateTextFile(sSignatureFileName, True)
  Set oTrack = SDB.Player.CurrentSong
   
  oSignatureFile.Write "|" & oTrack.ArtistName
  oSignatureFile.Write "|" & oTrack.Title
  oSignatureFile.Write "|" & oTrack.AlbumName
  oSignatureFile.Write "|" & oTrack.Path
  oSignatureFile.Write "|" & oTrack.PreviewPath

  oSignatureFile.Close()
   
End Sub


Sub DeleteSignatureFile

  On Error Resume Next
  
  oFSO.DeleteFile(sSignatureFileName)
  
End Sub
Greetz,

HELOX

Top