コード例 #1
0
        public void incrementTrackPlaycount(string track, string album, string artist, int playCount)
        {
            translate(ref artist, ref album);
            IWMPPlaylist list = collection.getByAttribute("WM/AlbumTitle", album);

            for (int i = 0; i < list.count; ++i)
            {
                IWMPMedia item = list.get_Item(i);
                if (
                    (track.ToLower() == item.getItemInfo("Title").ToLower())
                    &&
                    (artist.ToLower() == item.getItemInfo("WM/AlbumArtist").ToLower())
                    &&
                    (album.ToLower() == item.getItemInfo("WM/AlbumTitle").ToLower())
                    )
                {
                    string pc = item.getItemInfo("UserPlayCount");
                    int    p  = int.Parse(pc) + playCount;
                    //item.setItemInfo("UserPlayCount", p.ToString());
                    Console.WriteLine("Updating: {0} {1} {2}", track, album, p);

                    return;
                }
            }
            Console.WriteLine("Not found: {0} {1} {2}", track, album, artist);
            skipOrRename(artist, album, track, playCount);
        }
コード例 #2
0
        private void SaveWMPLibraryData(NHibernate.ISession pDataSession)
        {
            // Hip hip hooray for procedural......
            WindowsMediaPlayerClass WMP     = new WindowsMediaPlayerClass();
            IWMPMediaCollection     mc      = WMP.mediaCollection;
            IWMPStringCollection    strings = mc.getAttributeStringCollection("AlbumID", "audio");

            var albumArtistLookup = new System.Collections.Hashtable();

            int WmpCount = strings.count;

            if (WmpCount > 0)
            {
                for (int i = 0; i < WmpCount; i++)
                {
                    string       item     = strings.Item(i);
                    IWMPPlaylist playlist = mc.getByAttribute("AlbumID", item);
                    playlist.setItemInfo("SortAttribute", "OriginalIndex");
                    int playlistCount = playlist.count;
                    if (playlistCount > 0)
                    {
                        for (int ic = 0; ic < playlistCount; ic++)
                        {
                            IWMPMedia mMedia = playlist.get_Item(ic);

                            string guid        = mMedia.getItemInfo("WM/WMCollectionID");
                            string albumTitle  = mMedia.getItemInfo("WM/AlbumTitle");
                            string albumArtist = mMedia.getItemInfo("WM/AlbumArtist");

                            FileInfo file = new FileInfo(mMedia.sourceURL);

                            //Add to array if not found
                            if (!string.IsNullOrEmpty(guid) && !string.IsNullOrEmpty(albumTitle) &&
                                !albumArtistLookup.ContainsKey(file.DirectoryName))
                            {
                                albumArtistLookup[file.DirectoryName] = true;

                                string filePathLarge = System.IO.Path.Combine(file.DirectoryName, string.Format(WMP_LARGE_GUID, guid));
                                string filePathSmall = System.IO.Path.Combine(file.DirectoryName, string.Format(WMP_SMALL_GUID, guid));

                                if (File.Exists(filePathLarge))
                                {
                                    CreateAndSaveLargeArt(albumArtist, albumTitle, filePathLarge, pDataSession);
                                }
                                if (File.Exists(filePathSmall))
                                {
                                    CreateAndSaveSmallArt(albumArtist, albumTitle, filePathSmall, pDataSession);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: WMP.cs プロジェクト: swsss/Last.fm-Scrubbler-WPF
        /// <summary>
        /// Parses the windows media player database.
        /// </summary>
        /// <returns>List with tracks that can be scrobbled.</returns>
        public List <MediaDBScrobble> GetMusicLibrary()
        {
            List <MediaDBScrobble> entries;
            IWMPPlaylist           mediaList = null;
            IWMPMedia mediaItem;

            try
            {
                // get the full audio media list
                mediaList = _media.getByAttribute("MediaType", "Audio");
                entries   = new List <MediaDBScrobble>(mediaList.count);

                for (int i = 0; i < mediaList.count; i++)
                {
                    try
                    {
                        mediaItem = mediaList.get_Item(i);

                        // create the new entry and populate its properties
                        int playCount = GetPlayCount(mediaItem);
                        if (playCount == 0)
                        {
                            continue;
                        }
                        string   trackName   = GetTitle(mediaItem);
                        string   artistName  = GetArtist(mediaItem);
                        string   albumName   = GetAlbum(mediaItem);
                        string   albumArtist = GetAlbumArtist(mediaItem);
                        TimeSpan duration    = TimeSpan.FromSeconds(mediaItem.duration);
                        DateTime lastPlayed  = GetUserLastPlayedTime(mediaItem);

                        entries.Add(new MediaDBScrobble(playCount, lastPlayed, trackName, artistName, albumName, albumArtist, duration));
                    }
                    catch (Exception ex)
                    {
                        // probably missing necessary info...
                    }
                }
            }
            finally
            {
                // make sure we clean up as this is COM
                if (mediaList != null)
                {
                    mediaList.clear();
                }
            }

            return(entries);
        }
コード例 #4
0
        /// <summary>
        /// Displays the attribute information for a given media-based attribute source.
        /// </summary>
        /// <param name="Source">An AttributeSource specifying the schema to inspect.</param>
        /// <returns>void</returns>
        private void getMetadataFromMedia(AttributeSource Source)
        {
            IWMPPlaylist playlist = null;
            IWMPMedia    media    = null;

            string name = "";

            try
            {
                switch (Source)
                {
                case AttributeSource.CDTrack:
                    playlist = CD.Playlist;
                    break;

                case AttributeSource.CurrentMedia:
                    playlist = Player.currentPlaylist;
                    break;

                default:
                    // Get a playlist filled with media for the specified schema.
                    playlist = MediaCollection.getByAttribute("MediaType", Source.ToString());
                    break;
                }

                if (0 != playlist.count)
                {
                    // Get the first item from the playlist.
                    media = playlist.get_Item(0);
                }
                else
                {
                    throw new EmptyPlaylistException();
                }

                int cAttributes = media.attributeCount;

                // Log the attribute name, value, and writability.
                for (int i = 0; i < cAttributes; i++)
                {
                    name = media.getAttributeName(i);

                    ListViewItem item = new ListViewItem(Source.ToString());

                    item.SubItems.Add(name);
                    item.SubItems.Add(media.getItemInfo(name));
                    bool bRO = media.isReadOnlyItem(name);
                    item.SubItems.Add(bRO.ToString());
                    listView1.Items.Add(item);
                }
            }
            catch (EmptyPlaylistException)
            {
                ListViewItem item3 = new ListViewItem(Source.ToString());
                item3.SubItems.Add("EmptyPlaylistException");
                item3.SubItems.Add("Does your library contain media for this type or source?");
                listView1.Items.Add(item3);
            }
            catch (COMException exc)
            {
                lblStatus.Text = "Exception in getMetadata: " + exc.Message;
            }
            catch
            {
                lblStatus.Text = "Exception in getMetadata.";
                throw;
            }

            // Insert an empty line in the listview.
            ListViewItem item2 = new ListViewItem("");

            listView1.Items.Add(item2);
        }