示例#1
0
        public void CreateMediaFolder(ITrackCollection media)
        {
            var parts = PathHelpers.Split(pathFormat).ToList();

            if (media is Album album && album.NumberOfDiscs > 1)
            {
                parts.Add(parts[^ 1]);
示例#2
0
 public MediaViewItem(ITrackCollection media)
 {
     Id             = media.Id;
     Name           = $"{media.Title} - {media.Artist}";
     TrackViewItems = TrackViewItem.Create(media.Tracks);
     Flags          = media.CustomMetadata?.Where(m => m.CanDisplay && m.IsFlag);
 }
示例#3
0
 public void CreateMediaInfo(string path, ITrackCollection media)
 {
     try
     {
         var info = MediaInfo
                    .Create(media.MediaType)
                    .BuildContent(media);
         var fileName = Path.Combine(path, info.Name);
         AthameWriter.Write(fileName, info);
     }
     catch (Exception ex)
     {
         Log.Warning(ex, "Exception occurred when writing mediainfo file.");
     }
 }
示例#4
0
        /// <summary>
        /// Resolves the media descriptor to a media item object.
        /// </summary>
        /// <returns>An <see cref="MediaItem"/> according to the <see cref="MediaDescriptor.MediaType"/> property.</returns>
        public async Task <MediaItem> ResolveMedia()
        {
            var id      = descriptor.MediaId;
            var service = AthameApp.GetService(descriptor.OriginalUri);

            ITrackCollection media = descriptor.MediaType switch
            {
                MediaType.Album
                => await service.GetAlbumAsync(id, withTracks : true),
                MediaType.Track
                => (await service.GetTrackAsync(id)).AsCollection(),
                MediaType.Playlist
                => await service.GetPlaylistAsync(id),
                _ => throw new InvalidOperationException("Can't resolve unknown media type")
            };

            return(new MediaItem(media, descriptor));
        }
示例#5
0
 public static bool TryFormat(string format, ITrackCollection media, out string result)
 {
     try
     {
         result = $"{FormatFilePath(media.Tracks.First(), format)}.ext";
         return(true);
     }
     catch (FormatException)
     {
         result = "Improperly formed format string - did you forget a { or }?";
     }
     catch (NullReferenceException)
     {
         result = "Undefined variable referenced - click the \"Help with path formats\" button to learn more.";
     }
     catch (Exception ex)
     {
         result = $"Unknown error ({ex.GetType().Name})";
     }
     return(false);
 }
示例#6
0
 public MediaItem(ITrackCollection media, MediaDescriptor descriptor)
 {
     Descriptor = descriptor;
     Media      = media;
 }
示例#7
0
 public static bool IsDownloadable(this ITrackCollection media)
 => media.Tracks.Any(t => t.IsDownloadable);
示例#8
0
 public static IEnumerable <Track> GetDownloadableTracks(this ITrackCollection media)
 => from t in media.Tracks where t.IsDownloadable select t;
示例#9
0
 public static int GetDownloadableTracksCount(this ITrackCollection media)
 => media.Tracks.Sum(track => track.IsDownloadable ? 1 : 0);