Adding Songs (How can this not work?)

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Adding Songs (How can this not work?)

Post by imd1b4u »

I am getting incredibly frustrated trying to figure out how to add songs to the MM database (among other things).

Here is an example of code that should work, if I am understanding the documentation at all. It is too simple to be broken, but it doesn't work!

Code: Select all

Option Explicit
Dim objSL
Sub MyTest()
  Set objSL = SDB.NewSongList
  objSL.Add(SDB.NewSongData)
  objSL.UpdateAll
End Sub
If I understand anything at all, that should add one song, with every user-editable value null, into the database. I would expect to see one new record in the Songs table, but I don't. Can someone please tell me why not? Apparently, nothing changes at all! There are no error messages (nor any way to activate them), either.

Also, this script should be creating an additional records in other tables such as Albumns, Artists, etc., too, if necessary to keep relationships valid, right? I'm not seeing any of those records being created either, but I already have a "blank" artist, etc.

What am I missing here?
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Re: Adding Songs (How can this not work?)

Post by imd1b4u »

imd1b4u wrote:I am getting incredibly frustrated trying to figure out how to add songs to the MM database (among other things).
Is that because the documentation and what Steegy says are bogus? A search of the entire forum for any script that used both SDBSonglist.UpdateAll() and SDB.NewSongList resulted in only two hits: The one above, which doesn't work, and an unfinished script (TextFileImporter) by Steegy. Apparently Steegy never managed to finish the script, but the problems could be unrelated, AFAIK. Yet Steegy recommends this method of adding songs to the database! Is he recommending something that no one uses because it is broken and just doesn't work? (According to Steegy, there is a good reason to use it if it did work.) Note: I could have missed scripts if they were split over two different posts with "UpdateAll" in one and "NewSongList" in the other, or where the code is not provided, of course.

I'm not sure. I will test Steegy's unfinished script to try to figure out what if anything is wrong with it. It could be that the part I am interested in works fine. :-?

In any case, I am bothered if Steegy is recommending doing things that no one has tested much. Why assume it would work, especially as buggy as the MM API is?

OTOH, has anyone had any success by adding songs the way Steegy recommends? If so, can you post the code, please?

@Steegy. Did you never get the TextFileImporter script to work correctly? Why is your link to it here under "To-do" and why does it point to a post that does nothing but point to trixmoto's different script? If the script actually did work, I would be very interested, because it is very similar to what I am trying to write.
Last edited by imd1b4u on Sun Oct 07, 2007 12:53 pm, edited 1 time in total.
ZvezdanD
Posts: 3112
Joined: Thu Jun 08, 2006 7:40 pm

Post by ZvezdanD »

Add method is for adding existing tracks from a database to some list. After modifying data in this list, you could update same tracks in database with UpdateAll.

If you want to add tracks to a database, you could use SDB.Database object and its ExecSQL method.
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Post by imd1b4u »

ZvezdanD wrote:Add method is for adding existing tracks from a database to some list. After modifying data in this list, you could update same tracks in database with UpdateAll.
Does this really work? Or is it just supposed to work? I can't make it work.

If not, I may use the SQL method. But that wouldn't automatically get the tags embedded in the MP3 files I don't think. The UpdateAll is suppsed to do that.
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden
Contact:

Post by Bex »

Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Post by imd1b4u »

Thanks, but that uses the way Steegy recommends against. I'm trying to see if the way he recommends (using UpdateAll) really works.

If need be, I might do it the other way, but I'm hoping I don't need to do that.
In the Tips & Tricks wiki page, Steegy wrote:Using the SongData object, you can either update the database/library (UpdateDB) and/or update the file's tags (WriteTags). So there's no way to let the song changes be saved like the user selected in the Options panel (menu Tools > Options > Library > Tags & Playlists > "Update tags when editing properties"). However, the UpdateAll method for the SongList object does take into account this user-specified option. So you can create a new SongList object using SDB.NewSongList and add your SDBSongData object(s) to it. Then call the UpdateAll method on the songlist, and your song(s) will be saved in user-specified way.
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Post by imd1b4u »

HA! Guess what! Steegy's script doesn't work either! Apparently, Steegy didn't have a clue what he was talking about in this case, yet he writes a paragraph of incorrect information in the wiki and in a stickied post that's just going to confuse people. Plus he posts a script as an example of how to do something, but his script is WRONG! And he never fixes it!

Granted he said he wasn't finished with the UI of his script (yes, that needed work) but the part that he said was "nice information for you" doesn't work either!

@Steegy, please don't say something works that you've never managed to get to work yourself, unless someone else has.

Actually, what I think would work, and I will try now, is close to what Steegy said, except you must add a call to ISDBSongData::UpdateDB to actually add the new song to the database. Later when you call ISDBSongList::UpdateAll, then perhaps it would update the embedded tags according to the user's preferences.

Damn, I wish I knew that a couple of days ago!

Now I will go and make my third edit to Steegy's Tips and Trick's wiki page.
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Contact:

Post by Steegy »

UpdateAll would be the best way to do it, giving the fact that it does work 100% fine (which it doesn't, and this was found out later than my posting probably).

UpdateAll should be faster because you update a set of songs, instead of each song separately. It also uses the choice of the user in the settings, on how he wants to save stuff: in the tags, in the database, or both.
However, it might give some problems, like trying to "update" SongList objects that contain songs (SongData objects) that aren't in the library (yet), e.g. files browsed to with the My Computer node. There is at least one post about this problem (if only the forum search worked a bit good) but I'm 100% sure of it because I needed it made it as workaround in WST (Web Sources Tagger).

So it depends on your own opinion. Saving the songs themselves explicitly (using UpdateAlbum, UpdateArtist, UpdateDB, SaveTags or so) gives you "full control", but ideally (which it is not yet) UpdateAll on the SongList object would be better.

So maybe I've been wrong about this in past posts, but that was because we (at least I) didn't know any better...
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Contact:

Post by Steegy »

Other part:

You probably can't just add an empty SongData object to the library, because that doesn't have an album, artist, ... which it might need to be added successfully.



Bottomline: If nobody knows, the only way to find out is to test it ourselves. Certainly with the introduction of the MM3 era. If we still don't get the good grasp, we can ask the developers to shed some light on the subject.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Post by imd1b4u »

Steegy wrote: UpdateAll on the SongList object would be better.
Sorry, I am frustrated right now and am taking it out on you.

BTW, IMO, UpdateAll shouldn't be able to add anything to the database. Updating is not adding. The concepts should be kept separate. Either ISDBApplication::NewSongData should add a "blank" song in the database from the very beginning, or there should be a SDB.AddSong(objMyNewSong) and perhaps SDB.AddSongs(objNewSongsList) that would add songs to the database. Anything else should only update (or delete) what is already there.
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Post by imd1b4u »

Steegy wrote:You probably can't just add an empty SongData object to the library, because that doesn't have an album, artist, ... which it might need to be added successfully.
This adds a song:

Code: Select all

Option Explicit
Dim objSL,objSong
Sub MyTest()
  Set objSL = SDB.NewSongList
  Set objSong = SDB.NewSongData
  objSong.UpdateDB()
  objSL.Add(SDB.NewSongData)
'  objSL.UpdateAll
End Sub
It adds a "blank" song to the songs table as expected. Note: "objSL.UpdateAll" is commented out. That doesn't work. I just left the objSL stuff in there to show the second way that doesn't work.
Steegy wrote:Bottomline: If nobody knows, the only way to find out is to test it ourselves. Certainly with the introduction of the MM3 era. If we still don't get the good grasp, we can ask the developers to shed some light on the subject.
That may be a reasonable attitude for for MM3 since it is still in beta, but it's unacceptable that MM2's interface and documentation are so shoddy, IMO. I have wasted many hours based on the promise that MM2 had a scripting API! It's pathetic. If I had known how bad it was, I never would have tried writing the script in the first place, and would have been much better off. I would have either done the editing manually, or bypassed their API entirely. (I still might do that.)

If MM can't provide a decent API, they should at least own up to that fact. That way they are not misleading anyone.

I am not complaining that I did not get my money's worth out of MM's basic features. It's just that they wasted my time by misleading me into thinking they had decent scriptability that turns out to be very shoddy. If they are going to do offer scripting, they should at least do it right (or warn people that it's 'use at your own risk'). Since time is money, they cost me many times more than I paid for the product! That was a bad deal!
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

I don't understand why you're so frustrated, and the API has never let me down, although sometimes a little trial and error is necessary. The documentation is getting better all the time now that the Wiki is up and running. There's no need to slate Steegy because you misunderstood his help. If you think it's unclear, try suggesting a revised paragraph.

Yes "Song.UpdateDB" will add a new track but "SongList.UpdateAll" will not add new tracks. You should instead loop through them, like onkel_enno's AddToLibrary script. I hope this is clear.

Please calm down, and if you still have any queries then ask them as clearly as possible. We are all willing to help a new scripter! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
imd1b4u
Posts: 30
Joined: Tue Oct 02, 2007 10:25 pm
Contact:

Post by imd1b4u »

trixmoto wrote:I don't understand why you're so frustrated
I'm am frustrated because I was mislead into wasting a large amount of my time. Doing that is immoral, IMO. I don't know how I can be any more clear than that!
trixmoto wrote:... the API has never let me down, although sometimes a little trial and error is necessary.
I get the impression that you and Steegy view working with the API as a challenge and a hobby. You may have somewhat the same attitude as a white-hat hacker, who enjoys solving puzzles and figuring out how to make things work. Plus you will hopefully come up with something that others can enjoy. There is nothing wrong with that. Just understand that most users of MM won't have the same attitude. They want MM to help them. That's why they downloaded it and perhaps paid money for it. I wanted MM to help me. Instead, it wasted my time. I am upset.

Understand too that there were different ways of solving my problem that bypassed the MM API. I thought writing the script would be the quickest and easiest way. It turned out very different. Had MM been more upfront about how bad their API is, I wouldn't have made that mistake.

I think it is doing people a disservice if someone is making the API appear better than it is. It should be clear up front that MM scripting is only for those who want the challenge of figuring out a rather poorly designed and implemented API. That way people are not mislead.

Also, keep in mind that it is reasonable for people to assume that the API is as good as the rest of MM, which is pretty high quality, after all. If the rest of MM was as poor as the API, MM certainly wouldn't be as popular as it is now.
trixmoto wrote:If you think it's unclear, try suggesting a revised paragraph.
I have edited the wiki several times already! Check the history. Keep in mind, though, that it is difficult to come up with something better when you can't figure out what it should say in the first place. Don't think I haven't tried!
trixmoto wrote:Yes "Song.UpdateDB" will add a new track but "SongList.UpdateAll" will not add new tracks. You should instead loop through them, like onkel_enno's AddToLibrary script. I hope this is clear.
Well, now that you say it, it is perfectly clear. What is not clear is how I would have known that before you said it, or why it would be that way.
trixmoto wrote:Please calm down, and if you still have any queries then ask them as clearly as possible. We are all willing to help a new scripter! :)
I should not absolutely need to ask questions. What if I had only occasional or slow internet access? If the API was well designed, implemented and documented, I should be able to figure out everything well enough to get things to work at some basic level. (That doesn't mean I couldn't have improved my script by getting advice from others, but it still would have worked well enough to meet my basic needs.) As it was, I asked questions, had to keep checking for an answer, respond occasionally to people who meant to help but told me things I didn't need to be told, and finally, got told what I needed to hear. That was better than nothing, but not as good as having a good API in the first place.

Besides, why should you (trixmoto) or anyone else need to answer questions that should not have to be asked in the first place? That's your choice, of course, but wouldn't it be better if things were more logical to begin with?

In case you don't understand what I think is unacceptable, but which you (and others) seem to have accepted, here are a couple of examples:

1) Some things that can be done with VBScript can't be done with JScript. At a minimum, that means the developers should have been upfront about the fact that they have only partial JScript support. Yes, the users have documented that there is only partial JScript support, but a new coder won't see that before he was convinced that MM really did have full JScript support. Keep in mind that there don't seem to be many - if any - links to the Wiki from MM's web pages.

There is no law that says MM must offer JScript support, but if the developers claim you can use JScript, it should work.

2) There are some properties in the API named "Terminate". "Terminate" is strictly an action verb in the English language. That means it is a violation of good programming practice (and inherently nonsensical) to name anything, other than a method, "Terminate". One of the most basic concepts in computer programming is that objects represent things while methods represent actions, etc., so you use nouns to name objects, action verbs to name methods, etc. If the developers can't even get that much right, what can they do?

It is one thing to ignore good programming practices in code that only the programmer will ever see, but it's another thing to ignore them in the design of an interface and then advertise the interface as something that will make people's lives easier. That is not acceptable, IMO.

I think (but am unsure) that I read somewhere that the programmers are German, but even if they don't speak English very well, that's still no excuse. It would just mean that they must use a dictionary or have someone fluent in English check what names they picked. They should not be confusing other people by using misleading names in the API. (Or at the very least, MM should have been upfront about it, and warned potential scripters that the designers of the API didn't follow good programming practices.)

Of course, I could come up with much more than these two examples. These aren't the most important problems (there are far worse ones), but it should be easy for anyone to comprehend the problems in these cases.

Again, I wouldn't be so upset about this if I didn't feel as if I was mislead. It's important to not over-sell MM scripting or else you are just misleading people. If people are up for a challenge, fine! But it should be made clear that the MM API is not up to the same quality as the rest of MM.
Last edited by imd1b4u on Mon Oct 08, 2007 6:20 pm, edited 2 times in total.
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden
Contact:

Post by Bex »

Jesus!
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

As I've said, the API is known to be previously lacking, hence why the new wiki has been introduced, so it should improve rapidly now.

And frankly complaining about "Terminate" is a bit childish, who cares if it's a verb, a noun or an adjective. They could use "Cat" instead for all I care! :lol:
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Post Reply