Searching via SDBApplication?

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

dharmaturtle
Posts: 10
Joined: Thu Feb 09, 2012 3:04 pm

Searching via SDBApplication?

Post by dharmaturtle »

Hi, I'm a newbie C# programmer, so I'm still exploring what may be obvious things.

I can't seem to find a way to search an entire library via SDBApplication. I'm making a WPF application to help me organize my music (press this button to mark track as reviewed, press another button to combine these two playcounts favoring the one with the higher bitrate, make sure the song doesn't belong in any playlists, etc.)

I currently have an AutoPlaylist called "All" that contains my entire library. To search, I do this:

Code: Select all

AllSongs = MakeSongListEnumerable(SDB.PlaylistByTitle["All"].Tracks);

//============//

public static List<SDBSongData> MakeSongListEnumerable(SDBSongList songlist) {
  var selectedSongList = new List<SDBSongData>();
  foreach (var i in Enumerable.Range(0, songlist.Count)) {
    selectedSongList.Add(songlist.Item[i]);
  }
  return selectedSongList;
}
I iterate over every song in my library and shove it into a list and search through that. This obviously takes forever with large libraries (like mine), so could someone point me towards the actual search API?

I thought WebSearch was it, but I can't seem to understand it.

Thanks!
Last edited by Lowlander on Mon Jan 12, 2015 10:19 am, edited 1 time in total.
Reason: Moved to correct forum
mcow
Posts: 834
Joined: Sun Sep 21, 2008 9:35 pm
Location: Cupertino, California

Re: Searching via SDBApplication?

Post by mcow »

The element SDB.Database gets you an SDBDatabase object.
You need to learn how to construct an SQL query, and submit the query to the database.
Scottes
Posts: 150
Joined: Sat Mar 21, 2009 6:51 am

Re: Searching via SDBApplication?

Post by Scottes »

Here's one way using OpenSQL

Code: Select all

public static List<SongInfo> GetAllSongInfo(string artist, string album)
{
    var allSongInfo = new List<SongInfo>();

    string query = string.Format("SELECT * FROM Songs WHERE AlbumArtist LIKE '{0}' AND Album LIKE '{1}';", artist, album);

    var sdb = new SongsDB.SDBApplication();
    var queryData = sdb.Database.OpenSQL(query);
    while (true)
    {
        if (queryData.StringByName("ID") == null)
            break;

        var songInfo = new SongInfo();
        songInfo.Album = queryData.StringByName("Album");
        songInfo.AlbumArtist = queryData.StringByName("AlbumArtist");
        songInfo.Artist = queryData.StringByName("Artist");
        songInfo.Custom1 = queryData.StringByName("Custom1");
        songInfo.Custom2 = queryData.StringByName("Custom2");
        songInfo.Custom3 = queryData.StringByName("Custom3");
        songInfo.Custom4 = queryData.StringByName("Custom4");
        songInfo.Custom5 = queryData.StringByName("Custom5");
        songInfo.DateAdded = Convert.ToDouble(queryData.StringByName("DateAdded"));
        songInfo.Extension = queryData.StringByName("Extension");
        songInfo.FileModified = queryData.StringByName("FileModified");
        songInfo.Genre = queryData.StringByName("Genre");
        songInfo.Rating = Convert.ToInt32(queryData.StringByName("Rating"));
        songInfo.ID = Convert.ToInt32(queryData.StringByName("ID"));
        songInfo.SongLength = Convert.ToInt32(queryData.StringByName("SongLength"));
        songInfo.SongTitle = queryData.StringByName("SongTitle");
        songInfo.Year = Convert.ToInt32(queryData.StringByName("Year"));
        songInfo.SongPath = "C" + queryData.StringByName("SongPath");
        allSongInfo.Add(songInfo);

        queryData.Next();
    }
    sdb = null;

    return allSongInfo;
}

public struct SongInfo
{
    public string Album;
    public string AlbumArtist;
    public string Artist;
    public string Custom1;
    public string Custom2;
    public string Custom3;
    public string Custom4;
    public string Custom5;
    public double DateAdded;
    public string Extension;
    public string FileModified;
    public string Genre;
    public int Rating;
    public int ID;
    public int SongLength;
    public string SongPath;
    public string SongTitle;
    public int Year;            // Dec 13, 1997 stored as 19971213, ie; YYYYMMDD. Displayed as "12/13/1997"
    public string DiscogsID;
    public string DiscogsReleased;
    public string DiscogsArtistURL;
    public string DiscogsReleaseURL;
}
Post Reply