Exemple #1
0
        /// <summary>
        /// Return available tags for specified file
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private async Task <IGmtMedia> GetTagsAsync(TrackFile file)
        {
            //Object to store all retrieved tags
            var gmtContainer = new TrackFile();

            //Start looking for tags based on specified order in settings
            foreach (var tagType in GetSearchOrder())
            {
                //Get the tag type that has priority
                var searchCacheType = tagType == SearchResultType.Album ? CacheType.Album : CacheType.Artist;

                //Search tags from cache or if result is null return it from web
                IGmtMedia tags = GetCache(file, searchCacheType) ?? (await GetTagsFromWebAsync(file, tagType));

                //If no tracks are found go to next search type
                if (tags == null)
                {
                    continue;
                }

                //Log progress
                await LogMessageTagSearchResult(tagType.ToString(), tags.Count());

                //Add retrieved tags to container
                gmtContainer.AddGmtMedia(tags);

                //If we got what we want, stop
                if (tags?.Count() > 0 && Options.TagPriority != 2)
                {
                    break;
                }
            }

            return(gmtContainer);
        }
Exemple #2
0
 public static int Count(this IGmtMedia media)
 {
     return
         ((media.Genres?.Count ?? 0) +
          (media.Moods?.Count ?? 0) +
          (media.Themes?.Count ?? 0));
 }
        private void _webImport_OnImport(object sender, IGmtMedia result)
        {
            _manager_genres.AddRange(result.Genres);
            _manager_moods.AddRange(result.Moods);
            _manager_themes.AddRange(result.Themes);

            tabControl.SelectedIndex = 0;
        }
Exemple #4
0
 public CacheObject(string id, IGmtMedia tags)
 {
     Id      = id;
     Genres  = tags?.Genres?.ToList() ?? new List <string>();
     Moods   = tags?.Moods?.ToList() ?? new List <string>();
     Themes  = tags?.Themes?.ToList() ?? new List <string>();
     Created = DateTime.Now;
 }
Exemple #5
0
        private async Task <IGmtMedia> GetTagsFromWebAsync(TrackFile file, SearchResultType tagType)
        {
            //Load tags from web
            IGmtMedia tags = await GetTags(file, tagType);

            //save it to cache
            if (tagType == SearchResultType.Album)
            {
                Cache.Set(new CacheObject(file.GetAlbumCacheId(), tags));
            }
            else
            {
                Cache.Set(new CacheObject(file.GetArtistCacheId(), tags));
            }

            return(tags);
        }
        /// <summary>
        /// Add GMT values to existing values
        /// </summary>
        /// <param name="file"></param>
        /// <param name="media"></param>
        /// <returns></returns>
        public static TrackFile AddGmtMedia(this TrackFile file, IGmtMedia media)
        {
            if (media == null)
            {
                return(file);
            }

            file.Genres.AddRange(media.Genres);
            file.Moods.AddRange(media.Moods);
            file.Themes.AddRange(media.Themes);

            file.Genres = file.Genres.Select(x => x.Trim()).Distinct().ToList();
            file.Moods  = file.Moods.Select(x => x.Trim()).Distinct().ToList();
            file.Themes = file.Themes.Select(x => x.Trim()).Distinct().ToList();

            return(file);
        }
        /// <summary>
        /// Add GMT tags according to bot options
        /// </summary>
        /// <param name="file"></param>
        /// <param name="media"></param>
        /// <param name="setOptions"></param>
        /// <returns></returns>
        public static TrackFile SetGmtMedia(this TrackFile file, IGmtMedia media, GmtBotOptions setOptions)
        {
            switch (setOptions.FillTagsMode)
            {
            case 1:     //If empty
                return(file.SetGmtMediaIfEmpty(media));

            case 2:     //Add to existing ones
                return(file.AddGmtMedia(media));

            case 3:     // Replace all
                return(file.ForceSetGmt(media));

            default:     // Test mode or invalid options return unchanged data
                return(file);
            }
        }
        /// <summary>
        /// Replace properties with GMT values
        /// </summary>
        /// <param name="file"></param>
        /// <param name="media"></param>
        /// <returns></returns>
        public static TrackFile ForceSetGmt(this TrackFile file, IGmtMedia media)
        {
            if (media?.Genres?.Count > 0)
            {
                file.Genres = media.Genres.Select(x => x.Trim()).Distinct().ToList();
            }

            if (media?.Moods?.Count > 0)
            {
                file.Moods = media.Moods.Select(x => x.Trim()).Distinct().ToList();
            }

            if (media?.Themes?.Count > 0)
            {
                file.Themes = media.Themes.Select(x => x.Trim()).Distinct().ToList();
            }

            return(file);
        }
Exemple #9
0
        private async Task LoadTagsForGroup(IEnumerable <TrackFile> files)
        {
            foreach (var file in files)
            {
                if (_cancelProgress)
                {
                    break;
                }

                IGmtMedia tags = await GetTagsAsync(file);

                ReportProgress(file);

                if (tags?.Count() > 0)
                {
                    await LogMessageTagSearchCompleted(tags.Count(), file.Title, file.Artist);

                    _filesToUpdate.Add(file.SetGmtMedia(tags, Options));
                }
            }
        }
        /// <summary>
        /// Add values of IGmtMedia if properties are empty
        /// </summary>
        /// <param name="file"></param>
        /// <param name="media"></param>
        /// <returns></returns>
        public static TrackFile SetGmtMediaIfEmpty(this TrackFile file, IGmtMedia media)
        {
            if (media == null)
            {
                return(file);
            }

            if (file.Genres.Count == 0)
            {
                file.Genres = media.Genres.Select(x => x.Trim()).ToList();
            }
            if (file.Moods.Count == 0)
            {
                file.Moods = media.Moods.Select(x => x.Trim()).ToList();
            }
            if (file.Themes.Count == 0)
            {
                file.Themes = media.Themes.Select(x => x.Trim()).ToList();
            }

            return(file);
        }