Exemple #1
0
        public async static Task <TagInformation> CreateTagInfoForCD(int drive, int track)
        {
            var title  = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"TITLE{track + 1}", "Unknown song");
            var artist = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"PERFORMER{track + 1}", "Unknown artist");
            var album  = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"PERFORMER{0}", "Unknown");

            album += " - " + CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"TITLE{0}", "");

            var ret = new TagInformation
            {
                FileName = $"CD track {track + 1}, on Drive: {drive}",
                Title    = title,
                Artist   = artist,
                Year     = "unknown",
                Album    = album
            };

            if (title != "Unknown song")
            {
                var bytes = await iTunesCoverDownloader.GetCoverFor($"{artist} - {title}");

                if (bytes != null)
                {
                    ret.Cover = iTunesCoverDownloader.CreateBitmap(bytes);
                }
            }
            else
            {
                ret.Cover = new BitmapImage(ResourceLocator.GetIcon(IconCategories.Big, "icons8-cd-540.png"));
            }

            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// Converts a full path to a file name
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>string, filename</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string fullpath = value.ToString();

            if (fullpath.StartsWith("http"))
            {
                return(fullpath);
            }
            else if (fullpath.StartsWith("cd:"))
            {
                try
                {
                    var cd = new CDTrackInfo(fullpath);
                    if (CDInfoProvider.CdData.Count > 0)
                    {
                        var title  = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"TITLE{cd.Track + 1}", "Unknown song");
                        var artist = CollectionExtensions.GetValueOrFallback(CDInfoProvider.CdData, $"PERFORMER{cd.Track + 1}", "Unknown artist");
                        return($"{artist} - {title}");
                    }
                    else
                    {
                        return($"CD track {cd.Track+1}, on Drive: {cd.Drive}");
                    }
                }
                catch (Exception)
                {
                    return(fullpath);
                }
            }
            else
            {
                try
                {
                    TagLib.File tags   = TagLib.File.Create(fullpath);
                    var         artist = tags.Tag.Performers[0];
                    var         title  = tags.Tag.Title;
                    if (string.IsNullOrEmpty(artist))
                    {
                        artist = "Unknown artist";
                    }
                    if (string.IsNullOrEmpty(title))
                    {
                        title = "Unknown song";
                    }
                    return(string.Format("{0} - {1}", artist, title));
                }
                catch (Exception)
                {
                    var fname = System.IO.Path.GetFileName(fullpath);
                    return(fname);
                }
            }
        }