Exemple #1
0
        /// <summary>
        /// Get Album Artwork already on disk
        /// </summary>
        /// <param name="albumInfo"></param>
        /// <returns></returns>
        public bool GetAlbumArt(DBAlbumInfo albumInfo)
        {
            logger.Debug("In Method GetAlbumArt(DBAlbumInfo mv)");

            if (albumInfo == null)
            {
                return(false);
            }

            // if we already have a artist move on for now
            if (albumInfo.ArtFullPath.Trim().Length > 0)
            {
                return(false);
            }

            bool found = false;

            if (mvCentralCore.Settings.SearchCustomFolderForAlbumArt)
            {
                found = getAlbumArtFromCustomAlbumArtFolder(albumInfo);
                logger.Debug("Sucessfully added fanart from custom folder: {0}", albumInfo.ArtFullPath);
            }

            if (!found)
            {
                found = getAlbumArtFromAlbumArtFolder(albumInfo);
            }

            if (!found)
            {
                found = getOldAlbumArt(albumInfo);
            }

            return(found);
        }
Exemple #2
0
        /// <summary>
        /// Get the Album Artwork from Mediaportal folder
        /// </summary>
        /// <param name="mvArtistObject"></param>
        /// <returns></returns>
        private bool getMPAlbumArt(DBAlbumInfo mvAlbumObject)
        {
            logger.Debug("In Method: getMPAlbumArt(DBAlbumInfo mvAlbumObject)");
            bool found = false;

            string artist = string.Empty;
            string album  = mvAlbumObject.Album;

            List <DBTrackInfo> a1 = DBTrackInfo.GetEntriesByAlbum(mvAlbumObject);

            if (a1.Count > 0)
            {
                artist = a1[0].ArtistInfo[0].Artist;
            }

            string thumbFolder = Thumbs.MusicAlbum;
            string cleanTitle  = string.Format("{0}-{1}", MediaPortal.Util.Utils.MakeFileName(artist), MediaPortal.Util.Utils.MakeFileName(album));
            string filename    = thumbFolder + @"\" + cleanTitle + "L.jpg";

            if (File.Exists(filename))
            {
                found &= mvAlbumObject.AddArtFromFile(filename);
            }
            logger.Debug("In Method: getMPAlbumArt(DBAlbumInfo mvAlbumObject) filename: " + filename + " - " + found);
            return(found);
        }
Exemple #3
0
        /// <summary>
        /// get the Album Artwork from the custom album artwork folder
        /// </summary>
        /// <param name="mvAlbumObject"></param>
        /// <returns></returns>
        private bool getAlbumArtFromCustomAlbumArtFolder(DBAlbumInfo mvAlbumObject)
        {
            logger.Debug("In Method getAlbumArtFromCustomAlbumArtFolder(DBAlbumInfo mv)");
            if (mvAlbumObject == null)
            {
                return(false);
            }

            // grab a list of possible filenames for the albumart based on the user pattern
            string        pattern   = mvCentralCore.Settings.AlbumArtworkFilenamePattern;
            List <string> filenames = getPossibleNamesFromPattern(pattern, mvAlbumObject);

            // check the albumart folder for the user patterned albumart
            string   albumArtFolderPath = mvCentralCore.Settings.CustomAlbumArtFolder;
            FileInfo newAlbumArt        = getFirstFileFromFolder(albumArtFolderPath, filenames);

            if (newAlbumArt != null && newAlbumArt.Exists)
            {
                mvAlbumObject.ArtFullPath = newAlbumArt.FullName;
                mvAlbumObject.AlternateArts.Add(newAlbumArt.FullName);
                mvAlbumObject.GenerateThumbnail();
                logger.Info("Loaded Albumimage from " + newAlbumArt.FullName);
                return(true);
            }
            return(false);
        }
Exemple #4
0
 /// <summary>
 /// Set the Album Information - override existing data
 /// </summary>
 /// <param name="mv"></param>
 /// <param name="albumInfo"></param>
 private void SetMusicVideoAlbum(ref DBAlbumInfo mv, AlbumInfo albumInfo)
 {
     mv.bioSummary   = getBioSummary(albumInfo.Review, 50);
     mv.bioContent   = albumInfo.Review;
     mv.YearReleased = albumInfo.Year.ToString();
     mv.Rating       = albumInfo.Rating;
 }
Exemple #5
0
 public UpdateResults UpdateTrack(DBTrackInfo mv)
 {
     if (mv == null)
     {
         return(UpdateResults.FAILED);
     }
     lock (LockList)
     {
         DBArtistInfo db1 = DBArtistInfo.Get(mv);
         if (db1 != null)
         {
             mv.ArtistInfo[0] = db1;
         }
         if (mv.ArtistInfo.Count > 0)
         {
             mv.ArtistInfo[0].PrimarySource = mv.PrimarySource;
             mv.ArtistInfo[0].Commit();
         }
         DBAlbumInfo db2 = DBAlbumInfo.Get(mv);
         if (db2 != null)
         {
             mv.AlbumInfo[0] = db2;
         }
         if (mv.AlbumInfo.Count > 0)
         {
             foreach (DBAlbumInfo db3 in mv.AlbumInfo)
             {
                 db3.PrimarySource = mv.PrimarySource;
                 db3.Commit();
             }
         }
     }
     return(UpdateResults.SUCCESS);
 }
Exemple #6
0
        /// <summary>
        /// Get the album details
        /// </summary>
        /// <param name="basicInfo"></param>
        /// <param name="albumTitle"></param>
        /// <param name="albumMbid"></param>
        /// <returns></returns>
        public bool GetAlbumDetails(DBBasicInfo basicInfo, string albumTitle, string albumMbid)
        {
            List <DBTrackInfo> tracksOnAlbum = DBTrackInfo.GetEntriesByAlbum((DBAlbumInfo)basicInfo);

            if (tracksOnAlbum.Count > 0)
            {
                string      artist = tracksOnAlbum[0].ArtistInfo[0].Artist;
                DBAlbumInfo mv1    = (DBAlbumInfo)basicInfo;
                basicInfo.ArtUrls.Clear();
                setMusicVideoAlbum(ref mv1, albumMbid);
                GetAlbumArt((DBAlbumInfo)basicInfo);
            }
            return(true);
        }
Exemple #7
0
        private void setMusicVideoAlbum(ref DBAlbumInfo mv, string id)
        {
            if (id == null || mv == null)
            {
                return;
            }
            XmlNodeList xml = null;

            // get release info

            xml = getXML(apiTrackGetInfo, id);
            if (xml == null)
            {
                return;
            }
            XmlNode root = xml.Item(0).ParentNode;

            if (root.Attributes != null && root.Attributes["stat"].Value != "ok")
            {
                return;
            }
            mv.MdID = xml.Item(0).Attributes["id"].Value;
            ; XmlNodeList mvNodes = xml.Item(0).ChildNodes;
            foreach (XmlNode node in mvNodes)
            {
                string value = node.InnerText;
                switch (node.Name)
                {
                case "title":
                    mv.Album = value;
                    break;

                case "release":

                    mv.MdID = node.FirstChild.Attributes["id"].Value;
                    break;

                case "images":
                {
                    mv.ArtUrls.Clear();
                    foreach (XmlNode x1 in node.ChildNodes)
                    {
                        mv.ArtUrls.Add(x1.Attributes["uri"].Value);
                    }
                }
                break;
                }
            }
        }
Exemple #8
0
        public bool GetAlbumDetails(DBBasicInfo basicInfo, string albumTitle, string albumMbid)
        {
            logger.Debug("In Method: GetAlbumDetails(DBBasicInfo basicInfo, Album: " + albumTitle + " MBID: " + albumMbid + ")");
            List <DBTrackInfo> tracksOnAlbum = DBTrackInfo.GetEntriesByAlbum((DBAlbumInfo)basicInfo);

            if (tracksOnAlbum.Count > 0)
            {
                string      artist = tracksOnAlbum[0].ArtistInfo[0].Artist;
                DBAlbumInfo mv1    = (DBAlbumInfo)basicInfo;
                basicInfo.ArtUrls.Clear();
                setMusicVideoAlbum(ref mv1, artist, albumTitle, albumMbid);
                GetAlbumArt((DBAlbumInfo)basicInfo);
            }
            return(true);
        }
Exemple #9
0
        /// <summary>
        /// Get Album Artwork already on disk
        /// </summary>
        /// <param name="albumInfo"></param>
        /// <returns></returns>
        public bool GetAlbumArt(DBAlbumInfo albumInfo)
        {
            if (albumInfo == null)
            {
                return(false);
            }
            logger.Debug("In Method: GetAlbumArt(DBAlbumInfo mv)");

            // if we already have a artist move on for now
            if (albumInfo.ArtFullPath.Trim().Length > 0 && File.Exists(albumInfo.ArtFullPath.Trim()))
            {
                return(false);
            }

            return(getMPAlbumArt(albumInfo));
        }
Exemple #10
0
        public int Compare(GUIListItem x, GUIListItem y)
        {
            try
            {
                DBAlbumInfo albumX = (DBAlbumInfo)x.MusicTag;
                DBAlbumInfo albumY = (DBAlbumInfo)y.MusicTag;

                int rtn;

                switch (_sortField)
                {
                case SortingFields.DateAdded:
                    rtn = albumX.DateAdded.CompareTo(albumY.DateAdded);
                    break;


                // default to the title field
                case SortingFields.Artist:
                default:
                    rtn = albumX.SortBy.CompareTo(albumY.SortBy);
                    break;
                }

                // if both items are identical, fallback to using the Title
                if (rtn == 0)
                {
                    rtn = albumX.Album.CompareTo(albumY.Album);
                }

                // if both items are STILL identical, fallback to using the ID
                if (rtn == 0)
                {
                    rtn = albumX.ID.GetValueOrDefault(0).CompareTo(albumY.ID.GetValueOrDefault(0));
                }

                if (_sortDirection == SortingDirections.Descending)
                {
                    rtn = -rtn;
                }

                return(rtn);
            }
            catch
            {
                return(0);
            }
        }
Exemple #11
0
        /// <summary>
        /// Get the Album Art
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public bool GetAlbumArt(DBAlbumInfo mv)
        {
            if (mv == null)
            {
                return(false);
            }

            if (mv.ArtFullPath.Trim().Length == 0)
            {
                List <string> at = mv.ArtUrls;
                if (at != null)
                {
                    // grab album art loading settings
                    int maxAlbumArt = mvCentralCore.Settings.MaxAlbumArts;

                    int albumartAdded = 0;
                    int count         = 0;
                    lock (at)
                    {
                        foreach (string a2 in at)
                        {
                            if (mv.AlternateArts.Count >= maxAlbumArt)
                            {
                                break;
                            }
                            if (mv.AddArtFromURL(a2) == ImageLoadResults.SUCCESS)
                            {
                                albumartAdded++;
                            }

                            count++;
                        }
                    }
                    if (albumartAdded > 0)
                    {
                        // Update source info
                        //                        mv.GetSourceMusicVideoInfo(SourceInfo).Identifier = mv.MdID;
                        return(true);
                    }
                }
            }


            return(true);
        }
Exemple #12
0
        /// <summary>
        /// Get the Album Artwork using the old method
        /// </summary>
        /// <param name="mvAlbumObject"></param>
        /// <returns></returns>
        private bool getOldAlbumArt(DBAlbumInfo mvAlbumObject)
        {
            logger.Debug("In Method getOldAlbumArt(DBAlbumInfo mv)");
            bool found = false;

            string        AlbumArtFolderPath = mvCentralCore.Settings.AlbumArtFolder;
            DirectoryInfo albumartFolder     = new DirectoryInfo(AlbumArtFolderPath);

            string safeName      = mvAlbumObject.Album.Replace(' ', '.').ToValidFilename();
            Regex  oldtrackRegex = new Regex("^{?" + Regex.Escape(safeName) + "}? \\[-?\\d+\\]\\.(jpg|png)");

            foreach (FileInfo currFile in albumartFolder.GetFiles())
            {
                if (oldtrackRegex.IsMatch(currFile.Name))
                {
                    found &= mvAlbumObject.AddArtFromFile(currFile.FullName);
                }
            }
            return(found);
        }
        /// <summary>
        /// get the album details
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public DBTrackInfo GetAlbumDetail(DBTrackInfo mv)
        {
            // ****************** Additional Album Info Processing ******************
            // Check and update Album details from additional providers
            DBAlbumInfo albumInfo = new DBAlbumInfo();

            albumInfo = mv.AlbumInfo[0];

            foreach (DBSourceInfo albumExtraInfo in albumDetailSources)
            {
                if (albumInfo.PrimarySource != albumExtraInfo.Provider)
                {
                    albumInfo = albumExtraInfo.Provider.GetAlbumDetail(mv).AlbumInfo[0];
                    albumInfo.PrimarySource = albumExtraInfo;
                }
            }
            mv.AlbumInfo[0] = albumInfo;

            return(mv);
        }
Exemple #14
0
        /// <summary>
        /// get the artist details and update missing data from this source
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public DBTrackInfo GetAlbumDetail(DBTrackInfo mv)
        {
            string strAlbumHTML;
            string album  = mv.AlbumInfo[0].Album;
            string artist = mv.ArtistInfo[0].Artist;

            if (GetAlbumHTML(artist, album, out strAlbumHTML))
            {
                //var albumInfo = new MusicAlbumInfo();
                //if (albumInfo.Parse(strAlbumHTML))
                var albumInfo = AMGHTMLParser.ParseAlbumHTML(strAlbumHTML, album, artist);
                if (albumInfo != null)
                {
                    albumInfo.Artist = album;
                    DBAlbumInfo mv1 = (DBAlbumInfo)mv.AlbumInfo[0];
                    SetMusicVideoAlbum(ref mv1, albumInfo);
                    getTrackComposers(mv, strAlbumHTML, string.Empty);
                }
            }
            return(mv);
        }
Exemple #15
0
        public UpdateResults UpdateTrack(DBTrackInfo mv)
        {
            // Have we anything to update?
            if (mv == null)
            {
                return(UpdateResults.FAILED);
            }

            logger.Debug("In Method: UpdateTrack(DBTrackInfo mv)");

            lock (lockObj)
            {
                // Update the Artist
                var artistData = DBArtistInfo.Get(mv);
                if (artistData != null)
                {
                    mv.ArtistInfo[0] = artistData;
                }

                if (mv.ArtistInfo.Count > 0)
                {
                    mv.ArtistInfo[0].PrimarySource = mv.PrimarySource;
                    mv.ArtistInfo[0].Commit();
                }
                // Update the Album
                var albumData = DBAlbumInfo.Get(mv);
                if (albumData != null)
                {
                    mv.AlbumInfo[0] = albumData;
                }

                if (mv.AlbumInfo.Count > 0)
                {
                    mv.AlbumInfo[0].PrimarySource = mv.PrimarySource;
                    mv.AlbumInfo[0].Commit();
                }
            }
            return(UpdateResults.SUCCESS);
        }
Exemple #16
0
        private void setMusicVideoAlbum(ref DBAlbumInfo mv, XmlNode node)
        {
            if (node == null || mv == null)
            {
                return;
            }


            if (node.Attributes["type"].Value != "Main")
            {
                return;
            }
            mv.MdID = node.Attributes["id"].Value;

            foreach (XmlNode node1 in node.ChildNodes)
            {
                switch (node1.Name)
                {
                case "release":

                    //                        mv.MdID = value;
                    break;

                case "title":
                    mv.Album = node1.InnerText;
                    break;

                case "image":

                    break;

                case "year":
                    //                       mv.y
                    break;
                }
            }
            return;
        }
Exemple #17
0
        /// <summary>
        /// Get the Album Art
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public bool GetAlbumArt(DBAlbumInfo mv)
        {
            if (string.IsNullOrEmpty(mv.MdID.Trim()))
            {
                return(false);
            }
            logger.Debug("In Method: GetAlbumArt(DBAlbumInfo mv)");

            // Get the images
            // If we have a MBID for this Artist use this to retrive the image otherwise fall back to keyword search
            var html = getJSON(SearchAlbumImage, APIKey, mv.MdID.Trim());

            // If we reveived nothing back, bail out
            if (string.IsNullOrEmpty(html))
            {
                return(false);
            }

            int albumartAdded = 0;
            var URLList       = new List <string>();

            URLList = ExtractURL("albumcover", html);
            if (URLList != null)
            {
                foreach (string _url in URLList)
                {
                    var _fileURL = _url.Substring(checked (_url.IndexOf("|") + 1));
                    if (mv.AddArtFromURL(_fileURL) == ImageLoadResults.SUCCESS)
                    {
                        albumartAdded++;
                    }
                }
            }

            return(albumartAdded > 0);
        }
Exemple #18
0
 public bool GetAlbumArt(DBAlbumInfo mv)
 {
     return(false);
 }
        /// <summary>
        /// Remove Orphaned Artwork
        /// </summary>
        public void RemoveOrphanArtwork()
        {
            logger.Info("Checking for Orphaned Artwork....");

            // Artist
            logger.Debug("Checking for Orphaned Artists Artwork....");
            foreach (DBArtistInfo currMusicVideo in DBArtistInfo.GetAll())
            {
                if (currMusicVideo.ID == null)
                {
                    continue;
                }

                logger.Debug("Checking " + currMusicVideo.GetType().ToString() + " CurrArtist.ID : " + currMusicVideo.Artist);
                // get the list of elements to remove
                List <string> toRemove = new List <string>();
                foreach (string currTrackArtPath in currMusicVideo.AlternateArts)
                {
                    if (!new FileInfo(currTrackArtPath).Exists)
                    {
                        toRemove.Add(currTrackArtPath);
                    }
                }

                // remove them
                foreach (string currItem in toRemove)
                {
                    currMusicVideo.AlternateArts.Remove(currItem);
                }

                // reset default cover is needed
                if (!currMusicVideo.AlternateArts.Contains(currMusicVideo.ArtFullPath))
                {
                    if (currMusicVideo.AlternateArts.Count == 0)
                    {
                        currMusicVideo.ArtFullPath = " ";
                    }
                    else
                    {
                        currMusicVideo.ArtFullPath = currMusicVideo.AlternateArts[0];
                    }
                }

                // get rid of the backdrop link if it doesnt exist
                if (currMusicVideo.ArtFullPath.Trim().Length > 0 && !new FileInfo(currMusicVideo.ArtFullPath).Exists)
                {
                    currMusicVideo.ArtFullPath = " ";
                }

                currMusicVideo.Commit();
            }

            // Album
            logger.Debug("Checking for Orphaned Albums Artwork....");
            foreach (DBAlbumInfo currMusicVideo in DBAlbumInfo.GetAll())
            {
                if (currMusicVideo.ID == null)
                {
                    continue;
                }

                logger.Debug("Checking " + currMusicVideo.GetType().ToString() + " CurrAlbum.ID : " + currMusicVideo.Album);
                // get the list of elements to remove
                List <string> toRemove = new List <string>();
                foreach (string currTrackArtPath in currMusicVideo.AlternateArts)
                {
                    if (!new FileInfo(currTrackArtPath).Exists)
                    {
                        toRemove.Add(currTrackArtPath);
                    }
                }

                // remove them
                foreach (string currItem in toRemove)
                {
                    currMusicVideo.AlternateArts.Remove(currItem);
                }

                // reset default cover is needed
                if (!currMusicVideo.AlternateArts.Contains(currMusicVideo.ArtFullPath))
                {
                    if (currMusicVideo.AlternateArts.Count == 0)
                    {
                        currMusicVideo.ArtFullPath = " ";
                    }
                    else
                    {
                        currMusicVideo.ArtFullPath = currMusicVideo.AlternateArts[0];
                    }
                }

                // get rid of the backdrop link if it doesnt exist
                if (currMusicVideo.ArtFullPath.Trim().Length > 0 && !new FileInfo(currMusicVideo.ArtFullPath).Exists)
                {
                    currMusicVideo.ArtFullPath = " ";
                }

                currMusicVideo.Commit();
            }

            // Track
            logger.Debug("Checking for Orphaned Tracks Artwork....");
            foreach (DBTrackInfo currMusicVideo in DBTrackInfo.GetAll())
            {
                if (currMusicVideo.ID == null)
                {
                    continue;
                }

                logger.Debug("Checking " + currMusicVideo.GetType().ToString() + " CurrMusicVideo.ID : " + currMusicVideo.Track);
                // get the list of elements to remove
                List <string> toRemove = new List <string>();
                foreach (string currTrackArtPath in currMusicVideo.AlternateArts)
                {
                    if (!new FileInfo(currTrackArtPath).Exists)
                    {
                        toRemove.Add(currTrackArtPath);
                    }
                }

                // remove them
                foreach (string currItem in toRemove)
                {
                    currMusicVideo.AlternateArts.Remove(currItem);
                }

                // reset default cover is needed
                if (!currMusicVideo.AlternateArts.Contains(currMusicVideo.ArtFullPath))
                {
                    if (currMusicVideo.AlternateArts.Count == 0)
                    {
                        currMusicVideo.ArtFullPath = " ";
                    }
                    else
                    {
                        currMusicVideo.ArtFullPath = currMusicVideo.AlternateArts[0];
                    }
                }

                // get rid of the backdrop link if it doesnt exist
                if (currMusicVideo.ArtFullPath.Trim().Length > 0 && !new FileInfo(currMusicVideo.ArtFullPath).Exists)
                {
                    currMusicVideo.ArtFullPath = " ";
                }

                currMusicVideo.Commit();
            }
        }
        /// <summary>
        /// This methoded checks for missing artwork and medatdata
        /// </summary>
        private void LookForMissingMetaData()
        {
            float count = 0;
            float total = DBArtistInfo.GetAll().Count + DBAlbumInfo.GetAll().Count + DBTrackInfo.GetAll().Count;

            // Check for missing Artist Artwork
            logger.Info("Checking for Missing Artwork (Artists)");
            foreach (DBArtistInfo currArtist in DBArtistInfo.GetAll())
            {
                OnProgress((count * 100) / total);
                count++;

                try
                {
                    logger.Debug("Checking " + currArtist.GetType().ToString() + " CurrArtist.ID : " + currArtist.Artist);
                    if (currArtist.ID == null)
                    {
                        continue;
                    }

                    if (currArtist.ArtFullPath.Trim().Length == 0)
                    {
                        mvCentralCore.DataProviderManager.GetArt(currArtist, false);

                        // because this operation can take some time we check again
                        // if the artist/album/track was not deleted while we were getting artwork
                        if (currArtist.ID == null)
                        {
                            continue;
                        }

                        currArtist.Commit();
                    }
                }
                catch (Exception e)
                {
                    if (e is ThreadAbortException)
                    {
                        throw e;
                    }

                    logger.ErrorException("Error retrieving Artist artwork for " + currArtist.Basic, e);
                }
            }
            // Check for Missing Album Artwork
            logger.Info("Checking for Missing Artwork (Albums)");
            foreach (DBAlbumInfo currAlbum in DBAlbumInfo.GetAll())
            {
                OnProgress((count * 100) / total);
                count++;

                try
                {
                    logger.Debug("Checking " + currAlbum.GetType().ToString() + " CurrAlbum.ID : " + currAlbum.Album);
                    if (currAlbum.ID == null)
                    {
                        continue;
                    }

                    if (currAlbum.ArtFullPath.Trim().Length == 0)
                    {
                        mvCentralCore.DataProviderManager.GetArt(currAlbum, false);

                        // because this operation can take some time we check again
                        // if the artist/album/track was not deleted while we were getting artwork
                        if (currAlbum.ID == null)
                        {
                            continue;
                        }

                        currAlbum.Commit();
                    }
                }
                catch (Exception e)
                {
                    if (e is ThreadAbortException)
                    {
                        throw e;
                    }

                    logger.Error("Error retrieving Album artwork for " + currAlbum.Basic);
                }
            }
            // Check for missing video Artwork
            logger.Info("Checking for Missing Artwork (Videos)");
            foreach (DBTrackInfo currTrack in DBTrackInfo.GetAll())
            {
                OnProgress((count * 100) / total);
                count++;
                try
                {
                    logger.Debug("Checking " + currTrack.GetType().ToString() + " CurrMusicVideo.ID : " + currTrack.Track);
                    if (currTrack.ID == null)
                    {
                        continue;
                    }

                    if (currTrack.ArtFullPath.Trim().Length == 0)
                    {
                        mvCentralCore.DataProviderManager.GetArt(currTrack, false);

                        // because this operation can take some time we check again
                        // if the artist/album/track was not deleted while we were getting artwork
                        if (currTrack.ID == null)
                        {
                            continue;
                        }

                        currTrack.Commit();
                    }
                }
                catch (Exception e)
                {
                    if (e is ThreadAbortException)
                    {
                        throw e;
                    }

                    logger.ErrorException("Error retrieving Video artwork for " + currTrack.Basic, e);
                }
            }
            OnProgress(100.0);
        }
Exemple #21
0
 private void setMusicVideoAlbum(ref DBAlbumInfo mv, XmlNode node)
 {
 }
Exemple #22
0
        private DBTrackInfo getMusicVideoTrack(string artist, string album, string track)
        {
            if (track == null)
            {
                return(null);
            }
            XmlNodeList xml = null;

            //first get artist info

            if (artist != null)
            {
                xml = getXML(apiArtistGetInfo, artist);
            }
            else
            {
                return(null);
            }

            if (xml == null)
            {
                return(null);
            }
            XmlNode root = xml.Item(0).ParentNode;

            if (root.Attributes != null && root.Attributes["stat"].Value != "ok")
            {
                return(null);
            }
            XmlNodeList  mvNodes = xml.Item(0).ChildNodes;
            DBTrackInfo  mv      = new DBTrackInfo();
            DBArtistInfo a1      = new DBArtistInfo();

            mv.ArtistInfo.Add(a1);
            foreach (XmlNode node in mvNodes)
            {
                string value = node.InnerText;
                switch (node.Name)
                {
                case "name":
                    a1.Artist = value;
                    break;

                case "profile":
                    a1.bioContent = mvCentralUtils.StripHTML(value);
                    break;

                case "images":
                {
                    foreach (XmlNode x1 in node.ChildNodes)
                    {
                        a1.ArtUrls.Add(x1.Attributes["uri"].Value);
                    }
                }
                break;


                case "releases":
                    if (node.ChildNodes[0].InnerText.Trim().Length > 0)
                    {
                        if (album != null)
                        {
                            DBAlbumInfo d4 = new DBAlbumInfo();

                            if (!mvCentralCore.Settings.UseMDAlbum)
                            {
                                d4.Album = album;
                                mv.AlbumInfo.Add(d4);
                            }
                            else
                            {
                                setMusicVideoAlbum(ref d4, node.FirstChild);
                            }
                            mv.AlbumInfo.Add(d4);
                        }
                        else
                        {
                            mv.AlbumInfo.Clear();
                        }
                    }
                    break;
                }
            }

            if (mv.ArtistInfo.Count == 0)
            {
                return(null);
            }

            // get release info

            if (track != null)
            {
                xml = getXML(apiSearch, artist + " " + track);
            }
            else
            {
                return(null);
            }

            if (xml == null)
            {
                return(null);
            }
            root = xml.Item(0).ParentNode;
            if (root.Attributes != null && root.Attributes["stat"].Value != "ok")
            {
                return(null);
            }
            int numresults = Convert.ToInt16(root.FirstChild.Attributes["numResults"].Value);

            mvNodes = xml.Item(0).ChildNodes;
            if (numresults > 0)
            {
                Release r2 = new Release(mvNodes[0]);
                mv.Track      = r2.title;
                mv.MdID       = r2.id;
                mv.bioContent = mvCentralUtils.StripHTML(r2.summary);
            }
            else
            {
                return(null);
            }
            return(mv);
        }
Exemple #23
0
        private DBTrackInfo getMusicVideoTrack(string artist, string track)
        {
            if (track == null)
            {
                return(null);
            }

            logger.Debug("In Method: getMusicVideoTrack(Artist: " + artist + " Track: " + track + ")");

            MusicDatabase m_db = null;

            try
            {
                m_db = MusicDatabase.Instance;
            }
            catch (Exception e)
            {
                logger.Error("getMusicVideoTrack: Music database init failed " + e.ToString());
                return(null);
            }

            var trackInfo = new MediaPortal.Music.Database.Song();

            if (!m_db.GetSongByMusicTagInfo(artist, string.Empty, track, false, ref trackInfo))
            {
                return(null);
            }

            DBTrackInfo mv = new DBTrackInfo();

            mv.Track = trackInfo.Title;
            // mv.MdID = value;
            // Artist
            var _artist = string.Empty;

            if (!string.IsNullOrEmpty(trackInfo.AlbumArtist))
            {
                _artist = trackInfo.AlbumArtist;
            }
            else if (!string.IsNullOrEmpty(trackInfo.Artist))
            {
                _artist = trackInfo.Artist;
            }
            if (!string.IsNullOrEmpty(_artist))
            {
                DBArtistInfo d4 = new DBArtistInfo();
                setMusicVideoArtist(ref d4, _artist, null);
                mv.ArtistInfo.Add(d4);
            }
            // Album
            if (!string.IsNullOrEmpty(trackInfo.Album))
            {
                DBAlbumInfo d4 = new DBAlbumInfo();
                setMusicVideoAlbum(ref d4, _artist, trackInfo.Album, null);
                // Have we actually got a valid album?
                if (d4.Album.Trim() != string.Empty)
                {
                    mv.AlbumInfo.Add(d4);
                }
            }
            // Tag
            char[]   delimiters = new char[] { ',' };
            string[] tags       = trackInfo.Genre.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tag in tags)
            {
                mv.Tag.Add(tag.Trim());
            }
            // mv.bioSummary = mvCentralUtils.StripHTML(cdataSection.Value);
            // mv.bioContent = mvCentralUtils.StripHTML(cdataSection.Value);

            if (mv.ArtistInfo.Count == 0)
            {
                return(null);
            }

            return(mv);
        }
Exemple #24
0
        public List <DBTrackInfo> GetTrackDetail(MusicVideoSignature mvSignature)
        {
            // Switch off album support
            if (mvCentralCore.Settings.DisableAlbumSupport)
            {
                mvSignature.Album = null;
            }

            List <DBTrackInfo> results = new List <DBTrackInfo>();

            if (mvSignature == null)
            {
                return(results);
            }

            logger.Debug("In Method: GetTrackDetail(MusicVideoSignature mvSignature)");
            logger.Debug("*** Artist: " + mvSignature.Artist + " - " + mvSignature.ArtistMdId);
            logger.Debug("*** Album: " + mvSignature.Album + " - " + mvSignature.AlbumMdId);
            logger.Debug("*** Other: " + mvSignature.Title + " - " + mvSignature.MdId);
            lock (lockObj)
            {
                DBTrackInfo mvTrackData = null;
                // Artist/Album handling, if the track and artist dont match and the track contains the artist name this would indicate the that track is in the format /<artist>/<album>/<atrist - track>.<ext>
                // This will throw out the parseing so remove the artist name from the track.
                // This is not the best fix, need to add code so I know whch expression produced the result or better still have a ignore folder structure when pasring option.
                if (mvSignature.Track != null && mvSignature.Artist != null)
                {
                    if ((mvSignature.Track.ToLower().Trim() != mvSignature.Artist.ToLower().Trim()) && mvSignature.Track.ToLower().Contains(mvSignature.Artist.ToLower().Trim()))
                    {
                        mvTrackData = getMusicVideoTrack(mvSignature.Artist, Regex.Replace(mvSignature.Track, mvSignature.Artist, string.Empty, RegexOptions.IgnoreCase));
                    }
                    else
                    {
                        mvTrackData = getMusicVideoTrack(mvSignature.Artist, mvSignature.Track);
                    }
                }
                else
                {
                    mvTrackData = getMusicVideoTrack(mvSignature.Artist, mvSignature.Track);
                }

                if (mvTrackData != null)
                {
                    if (mvTrackData.ArtistInfo.Count == 0)
                    {
                        DBArtistInfo artistInfo = new DBArtistInfo();
                        artistInfo.Artist = mvSignature.Artist;
                        mvTrackData.ArtistInfo.Add(artistInfo);
                    }

                    if (mvSignature.Album != null && mvSignature.Artist != null)
                    {
                        if (!mvCentralCore.Settings.UseMDAlbum)
                        {
                            DBAlbumInfo albumInfo = new DBAlbumInfo();
                            albumInfo.Album = mvSignature.Album;
                            setMusicVideoAlbum(ref albumInfo, mvSignature.Artist, mvSignature.Album, null);
                            mvTrackData.AlbumInfo.Clear();
                            mvTrackData.AlbumInfo.Add(albumInfo);
                        }
                    }
                    else if (mvTrackData.AlbumInfo.Count > 0 && mvCentralCore.Settings.SetAlbumFromTrackData)
                    {
                        logger.Debug("There are {0} Albums found for Artist: {1} / {2}", mvTrackData.AlbumInfo.Count.ToString(), mvSignature.Artist, mvSignature.Title);
                        DBAlbumInfo albumInfo = new DBAlbumInfo();
                        albumInfo.Album = mvTrackData.AlbumInfo[0].Album;
                        setMusicVideoAlbum(ref albumInfo, mvSignature.Artist, mvTrackData.AlbumInfo[0].Album, null);
                        mvTrackData.AlbumInfo.Clear();
                        mvTrackData.ArtistInfo[0].Artist = mvSignature.Artist;
                        mvTrackData.AlbumInfo.Add(albumInfo);
                    }
                    else
                    {
                        mvTrackData.AlbumInfo.Clear();
                    }

                    results.Add(mvTrackData);
                }
            }
            return(results);
        }
        /// <summary>
        /// Based on the calculated signature retrive data from providers
        /// </summary>
        /// <param name="mvSignature"></param>
        /// <returns></returns>
        public List <DBTrackInfo> GetTrackDetail(MusicVideoSignature mvSignature)
        {
            List <DBSourceInfo> trackSources;

            lock (trackDetailSources) trackSources = new List <DBSourceInfo>(trackDetailSources);

            List <DBSourceInfo> artistSources;

            lock (artistDetailSources) artistSources = new List <DBSourceInfo>(artistDetailSources);


            // Try each datasource (ordered by their priority) to get results
            List <DBTrackInfo> results = new List <DBTrackInfo>();

            foreach (DBSourceInfo currSource in trackSources)
            {
                if (currSource.IsDisabled(DataType.TRACKDETAIL))
                {
                    continue;
                }

                // if we have reached the minimum number of possible matches required, we are done
                if (results.Count >= mvCentralCore.Settings.MinimumMatches && mvCentralCore.Settings.MinimumMatches != 0)
                {
                    logger.Debug("We have reached the minimum number of possible matches required, we are done.");
                    break;
                }

                // search with the current provider
                List <DBTrackInfo> newResults = currSource.Provider.GetTrackDetail(mvSignature);

                // tag the results with the current source
                foreach (DBTrackInfo currMusicVideo in newResults)
                {
                    currMusicVideo.PrimarySource = currSource;

                    // ****************** Additional Artist Info Processing ******************
                    // Check and update Artist details from additional providers
                    DBArtistInfo artInfo = new DBArtistInfo();
                    artInfo = currMusicVideo.ArtistInfo[0];

                    foreach (DBSourceInfo artistExtraInfo in artistDetailSources)
                    {
                        if (artistExtraInfo != currSource)
                        {
                            logger.Debug("Searching for additional Artist infomation from Provider: " + artistExtraInfo.Provider.Name);
                            artInfo = artistExtraInfo.Provider.GetArtistDetail(currMusicVideo).ArtistInfo[0];
                        }
                    }
                    artInfo.DisallowBackgroundUpdate = true;
                    currMusicVideo.ArtistInfo[0]     = artInfo;

                    // If album support disabled or no associated album then skip album processing
                    if (mvCentralCore.Settings.DisableAlbumSupport || currMusicVideo.AlbumInfo.Count == 0)
                    {
                        continue;
                    }

                    // ****************** Additional Album Info Processing ******************
                    // Check and update Album details from additional providers
                    DBAlbumInfo albumInfo = new DBAlbumInfo();
                    albumInfo = currMusicVideo.AlbumInfo[0];

                    foreach (DBSourceInfo albumExtraInfo in albumDetailSources)
                    {
                        if (albumExtraInfo != currSource)
                        {
                            logger.Debug("Searching for additional Album infomation from Provider: " + albumExtraInfo.Provider.Name);
                            albumInfo = albumExtraInfo.Provider.GetAlbumDetail(currMusicVideo).AlbumInfo[0];
                        }
                    }
                    albumInfo.DisallowBackgroundUpdate = true;
                    currMusicVideo.AlbumInfo[0]        = albumInfo;
                }

                // add results to our total result list and log what we found
                results.AddRange(newResults);
            }
            return(results);
        }
Exemple #26
0
        /// <summary>
        /// Get the Album Art
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public bool GetAlbumArt(DBAlbumInfo mvAlbumObject)
        {
            Logger.Debug("In Method : GetAlbumArt(DBAlbumInfo mv)");

            if (mvAlbumObject == null)
            {
                return(false);
            }

            List <string> albumImageList = mvAlbumObject.ArtUrls;

            // Reload existing Artwork - Why springs to mind??
            if (albumImageList.Count > 0)
            {
                // grab album art loading settings
                int maxAlbumArt = mvCentralCore.Settings.MaxAlbumArts;

                int albumartAdded = 0;
                int count         = 0;
                foreach (string albumImage in albumImageList)
                {
                    if (mvAlbumObject.AlternateArts.Count >= maxAlbumArt)
                    {
                        break;
                    }

                    if (mvAlbumObject.AddArtFromURL(albumImage) == ImageLoadResults.SUCCESS)
                    {
                        albumartAdded++;
                    }

                    count++;
                }
                // We added some artwork so commit
                if (count > 0)
                {
                    mvAlbumObject.Commit();
                }
            }

            // Now add any new art from this provider
            string             strAlbumHTML;
            DBArtistInfo       artist        = null;
            List <DBTrackInfo> tracksOnAlbum = DBTrackInfo.GetEntriesByAlbum(mvAlbumObject);

            if (tracksOnAlbum.Count > 0)
            {
                artist = DBArtistInfo.Get(tracksOnAlbum[0]);

                if (GetAlbumHTML(artist.Artist, mvAlbumObject.Album, out strAlbumHTML))
                {
                    var albumInfo = new MusicAlbumInfo();

                    if (albumInfo.Parse(strAlbumHTML))
                    {
                        ImageLoadResults imageLoadResults = mvAlbumObject.AddArtFromURL(albumInfo.ImageURL);

                        if (imageLoadResults == ImageLoadResults.SUCCESS || imageLoadResults == ImageLoadResults.SUCCESS_REDUCED_SIZE)
                        {
                            mvAlbumObject.Commit();
                        }
                    }
                }
            }
            // We always return sucess...
            return(true);
        }
Exemple #27
0
        /// <summary>
        /// Get the Artist, Album Details
        /// </summary>
        /// <param name="mv"></param>
        /// <returns></returns>
        public bool GetDetails(DBBasicInfo mv)
        {
            string strArtistHTML;
            string strAlbumHTML;
            string strArtistURL;

            ReportProgress(string.Empty);

            // Get details of the artist
            if (mv.GetType() == typeof(DBArtistInfo))
            {
                string artist = ((DBArtistInfo)mv).Artist;
                ReportProgress("Getting Artist...");
                if (GetArtistHTML(artist, out strArtistHTML, out strArtistURL))
                {
                    var artistInfo = AMGHTMLParser.ParseArtistHTML(strArtistHTML, artist);

                    if (artistInfo != null)
                    {
                        artistInfo.Artist = artist;
                        DBArtistInfo mv1 = (DBArtistInfo)mv;
                        SetMusicVideoArtist(ref mv1, artistInfo, strArtistHTML);
                        GetArtistArt((DBArtistInfo)mv);
                        ReportProgress("Done...");
                        return(true);
                    }
                }
                return(false);
            }
            // get details of the album
            if (mv.GetType() == typeof(DBAlbumInfo))
            {
                string             album     = ((DBAlbumInfo)mv).Album;
                List <DBTrackInfo> trackList = DBTrackInfo.GetEntriesByAlbum((DBAlbumInfo)mv);
                DBArtistInfo       artist    = DBArtistInfo.Get(trackList[0]);

                if (GetAlbumHTML(artist.Artist, album, out strAlbumHTML))
                {
                    var albumInfo = AMGHTMLParser.ParseAlbumHTML(strAlbumHTML, album, artist.Artist);
                    if (albumInfo != null)
                    {
                        albumInfo.Artist = album;
                        DBAlbumInfo mv1 = (DBAlbumInfo)mv;
                        SetMusicVideoAlbum(ref mv1, albumInfo);
                    }
                }
                return(false);
            }

            // get details of the track
            if (mv.GetType() == typeof(DBTrackInfo))
            {
                if (((DBTrackInfo)mv).LocalMedia[0].IsDVD)
                {
                    string track = ((DBTrackInfo)mv).Track;
                    GetDVDDetails((DBTrackInfo)mv);
                    return(true);
                }
                else
                {
                    string track = ((DBTrackInfo)mv).Track;
                    GetTrackDetails((DBTrackInfo)mv);
                    return(true);
                }
            }

            return(true);
        }
Exemple #28
0
        public bool GetDetails(DBBasicInfo mv)
        {
            if (mv.GetType() == typeof(DBAlbumInfo))
            {
                List <DBTrackInfo> a1 = DBTrackInfo.GetEntriesByAlbum((DBAlbumInfo)mv);
                if (a1.Count > 0)
                {
                    string artist = a1[0].ArtistInfo[0].Artist;
                    //first get artist info
                    XmlNodeList xml = null;

                    if (artist != null)
                    {
                        xml = getXML(apiArtistGetInfo, artist);
                    }
                    else
                    {
                        return(false);
                    }

                    if (xml == null)
                    {
                        return(false);
                    }
                    XmlNode root = xml.Item(0).ParentNode;
                    if (root.Attributes != null && root.Attributes["stat"].Value != "ok")
                    {
                        return(false);
                    }
                    XmlNode n1 = root.SelectSingleNode(@"/resp/artist/releases");

                    List <Release> r1 = new List <Release>();
                    foreach (XmlNode x1 in n1.ChildNodes)
                    {
                        Release r2 = new Release(x1);
                        r1.Add(r2);
                    }
                    r1.Sort(Release.TitleComparison);

                    DetailsPopup d1 = new DetailsPopup(r1);

                    if (d1.ShowDialog() == DialogResult.OK)
                    {
                        DBAlbumInfo mv1 = (DBAlbumInfo)mv;
                        setMusicVideoAlbum(ref mv1, d1.label8.Text);
                        GetAlbumArt((DBAlbumInfo)mv);
                    }
                    ;
                }
            }

            if (mv.GetType() == typeof(DBTrackInfo))
            {
                string artist = ((DBTrackInfo)mv).ArtistInfo[0].Artist;
                //first get artist info
                XmlNodeList xml = null;

                if (artist != null)
                {
                    xml = getXML(apiArtistGetInfo, artist);
                }
                else
                {
                    return(false);
                }

                if (xml == null)
                {
                    return(false);
                }
                XmlNode root = xml.Item(0).ParentNode;
                if (root.Attributes != null && root.Attributes["stat"].Value != "ok")
                {
                    return(false);
                }
                XmlNode n1 = root.SelectSingleNode(@"/resp/artist/releases");

                if (n1 == null)
                {
                    return(false);
                }

                List <Release> r1 = new List <Release>();
                foreach (XmlNode x1 in n1.ChildNodes)
                {
                    Release r2 = new Release(x1);
                    r1.Add(r2);
                }
                r1.Sort(Release.TitleComparison);
                DetailsPopup d1 = new DetailsPopup(r1);

                if (d1.ShowDialog() == DialogResult.OK)
                {
                    DBTrackInfo mv1 = (DBTrackInfo)mv;
                    setMusicVideoTrack(ref mv1, d1.label8.Text);
                    GetTrackArt((DBTrackInfo)mv);
                }
                ;
            }
            return(true);
        }
Exemple #29
0
        /// <summary>
        /// parses and replaces variables from a filename based on the pattern supplied
        /// returning a list of possible file matches
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="mv"></param>
        /// <returns></returns>
        private List <string> getPossibleNamesFromPattern(string pattern, object mv)
        {
            Regex parser = new Regex("%(.*?)%", RegexOptions.IgnoreCase);

            // Artist Artwork
            if (mv.GetType() == typeof(DBArtistInfo))
            {
                mvArtistObject = (DBArtistInfo)mv;
                lock (lockObj)
                {
                    List <string> filenames = new List <string>();
                    foreach (string currPattern in pattern.Split('|'))
                    {
                        // replace db field patterns
                        string filename = parser.Replace(currPattern, new MatchEvaluator(dbArtistNameParser)).Trim().ToLower();
                        if (filename != null)
                        {
                            filenames.Add(filename);
                        }
                    }
                    return(filenames);
                }
            }
            // Album Artwork
            if (mv.GetType() == typeof(DBAlbumInfo))
            {
                mvAlbumObject = (DBAlbumInfo)mv;
                lock (lockObj)
                {
                    List <string> filenames = new List <string>();
                    foreach (string currPattern in pattern.Split('|'))
                    {
                        // replace db field patterns
                        string filename = parser.Replace(currPattern, new MatchEvaluator(dbAlbumNameParser)).Trim().ToLower();
                        if (filename != null)
                        {
                            filenames.Add(filename);
                        }
                    }
                    return(filenames);
                }
            }
            // This is track data
            if (mv.GetType() == typeof(DBTrackInfo))
            {
                // try to create our filename(s)
                this.mvTrackObject = (DBTrackInfo)mv;
                //this.mvTrackObject.LocalMedia[0].TrimmedFullPath;
                lock (lockObj)
                {
                    List <string> filenames = new List <string>();
                    foreach (string currPattern in pattern.Split('|'))
                    {
                        // replace db field patterns

                        string filename = parser.Replace(currPattern, new MatchEvaluator(dbTrackNameParser)).Trim().ToLower();

                        // replace %filename% pattern
                        if (mvTrackObject.LocalMedia.Count > 0)
                        {
                            string videoFileName = Path.GetFileNameWithoutExtension(mvTrackObject.LocalMedia[0].File.Name);
                            filename = filename.Replace("%filename%", videoFileName);
                        }

                        filenames.Add(filename);
                    }
                    return(filenames);
                }
            }

            //should never get here
            return(null);
        }
Exemple #30
0
 /// <summary>
 /// Set the Album Information
 /// </summary>
 /// <param name="mv"></param>
 /// <param name="albumInfo"></param>
 private void setMusicVideoAlbum(ref DBAlbumInfo mv, MusicAlbumInfo albumInfo)
 {
 }