Exemplo n.º 1
0
        public WmpLibraryTrack(IWMPMedia libraryItem)
        {
            LibraryItem = libraryItem;

            Artist    = libraryItem.getItemInfo(ArtistAttribute) ?? "";
            ArtistKey = Artist.Neutralize();

            Title    = libraryItem.getItemInfo(TitleAttribute) ?? "";
            TitleKey = Title.Neutralize();

            // Defer initialization for the following, for performance

            album = new Lazy <string>(() =>
            {
                try { return(libraryItem.getItemInfo(AlbumTitleAttribute) ?? ""); }
                catch (COMException)
                {
                    return("");
                }
            });

            playCountCache = new Cacheable <int>(() =>
            {
                int playCount;
                if (!int.TryParse(LibraryItem.getItemInfo(PlayCountAttribute), out playCount))
                {
                    return(0);
                }
                return(playCount);
            },
                                                 value =>
            {
                LibraryItem.setItemInfo(PlayCountAttribute, value.ToString());
            });

            playDateCache = new Cacheable <DateTime>(() =>
            {
                DateTime lastPlayed;
                if (!DateTime.TryParse(LibraryItem.getItemInfo(UserLastPlayedTimeAttribute), out lastPlayed))
                {
                    return(DateTime.Now);
                }
                return(lastPlayed);
            },
                                                     value => LibraryItem.setItemInfo(UserLastPlayedTimeAttribute, value.ToString()));
        }
Exemplo n.º 2
0
        public static void RewriteWMPTags(DownloadItem item, IWMPMedia wmpmedia)
        {
            string strLocalFile = item.Filename;

            if (System.IO.File.Exists(strLocalFile))
            {
                // WindowsMediaPlayer player = null;
                try
                {
                    //wmppplayer = new WindowsMediaPlayer();
                    //IWMPMedia wmpmedia = wmppplayer.newMedia(strLocalFile);

                    //for (int q = 0; q < wmpmedia.attributeCount; q++)
                    //{
                    //    MessageBox.Show(wmpmedia.getAttributeName(q) + " - " + wmpmedia.getItemInfo(wmpmedia.getAttributeName(q)));
                    //}
                    string strTitle = wmpmedia.getItemInfo("Title");
                    string strGenre = wmpmedia.getItemInfo("Genre");
                    if (strGenre == null || strGenre == "")
                    {
                        strGenre = wmpmedia.getItemInfo("WM/Genre");
                    }
                    string strArtist = wmpmedia.getItemInfo("WM/AlbumArtist");
                    if (strArtist == null || strArtist == "")
                    {
                        strArtist = wmpmedia.getItemInfo("Author");
                    }
                    string strAlbum = wmpmedia.getItemInfo("WM/AlbumTitle");
                    if (item.TagTitle != null && item.TagTitle != "")
                    {
                        strTitle = ParseMediaTags(item.TagTitle, item, wmpmedia);
                    }
                    if (item.TagGenre != null && item.TagGenre != "")
                    {
                        strGenre = ParseMediaTags(item.TagGenre, item, wmpmedia);
                    }
                    if (item.TagArtist != null && item.TagArtist != "")
                    {
                        strArtist = ParseMediaTags(item.TagArtist, item, wmpmedia);
                    }
                    if (item.TagAlbum != null && item.TagAlbum != "")
                    {
                        strAlbum = ParseMediaTags(item.TagAlbum, item, wmpmedia);
                    }

                    wmpmedia.setItemInfo("Title", strTitle);
                    wmpmedia.setItemInfo("WM/Genre", strGenre);
                    wmpmedia.setItemInfo("Author", strArtist);
                    wmpmedia.setItemInfo("WM/AlbumTitle", strAlbum);
                }
                catch (COMException ex)
                {
                    if (Settings.Default.LogLevel > 0)
                    {
                        log.Error(ex);
                    }
                }
                //finally
                //{
                //    int left = 0;
                //    do
                //    {
                //        left = System.Runtime.InteropServices.Marshal.ReleaseComObject(wmppplayer);
                //    } while (left > 0);

                //}
            }
            else
            {
                if (Settings.Default.LogLevel > 0)
                {
                    log.Error("Cannot find file to rewrite tags");
                }
            }
        }