Example #1
0
        private void AddTrack(IGoogleDesktopQueryResultItem item)
        {
            Uri uri = new Uri ((string) item.GetProperty ("uri"));

            string artist = (string) GetResultProperty (item, "artist");
            string title = (string) GetResultProperty (item, "title");
            string album = (string) GetResultProperty (item, "album_title");

            ulong duration = 0;
            object o = GetResultProperty (item, "length");
            if (o != null)
                duration = (ulong) o;

            uint bitrate = 0;
            o = GetResultProperty (item, "bit_rate");
            if (o != null)
                bitrate = (uint) o;

            string genre = (string) GetResultProperty (item, "genre");

            uint trackNum = 0;
            o = GetResultProperty (item, "track_number");
            if (o != null)
                trackNum = (uint) o;

            if (artist == null || title == null)
                return;

            Track track = new Track ();
            track.Artist = artist;
            track.Album = album;
            track.Title = title;
            track.FileName = uri.LocalPath;
            track.Duration = TimeSpan.FromMilliseconds ((double) duration / (double) 10000);
            track.BitRate = (short) bitrate;
            track.Genre = genre;
            track.TrackNumber = (int) trackNum;

            Daemon.DefaultDatabase.AddTrack (track);
        }
Example #2
0
 private object GetResultProperty(IGoogleDesktopQueryResultItem item, string name)
 {
     try {
         return item.GetProperty (name);
     } catch (Exception e) {
         return null;
     }
 }