public void CreateMediaFolder(ITrackCollection media) { var parts = PathHelpers.Split(pathFormat).ToList(); if (media is Album album && album.NumberOfDiscs > 1) { parts.Add(parts[^ 1]);
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); }
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."); } }
/// <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)); }
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); }
public MediaItem(ITrackCollection media, MediaDescriptor descriptor) { Descriptor = descriptor; Media = media; }
public static bool IsDownloadable(this ITrackCollection media) => media.Tracks.Any(t => t.IsDownloadable);
public static IEnumerable <Track> GetDownloadableTracks(this ITrackCollection media) => from t in media.Tracks where t.IsDownloadable select t;
public static int GetDownloadableTracksCount(this ITrackCollection media) => media.Tracks.Sum(track => track.IsDownloadable ? 1 : 0);