/// <summary> /// Attempts to parse a URL that refers to a media collection. /// </summary> /// <param name="url">The URL to parse.</param> /// <returns>The state of the parser. See the documentation for <see cref="IUrlParseResult"/> for more info.</returns> public static IUrlParseResult ResolveUrl(string url) { if (string.IsNullOrWhiteSpace(url)) { return(UrlParse.Empty); } if (!Uri.TryCreate(url, UriKind.Absolute, out Uri actualUrl)) { return(UrlParse.Invalid); } var service = AthameApp.GetService(actualUrl); if (service == null) { return(UrlParse.NoService); } var descriptor = service.ParseUrl(actualUrl); if (descriptor == null || descriptor.MediaType == MediaType.Unknown) { return(UrlParse.NoMedia); } return(UrlParse.Success(descriptor)); }
public virtual void MediaDownloadStarted(object sender, MediaDownloadEventArgs e) { var descriptor = e.CurrentMediaDownload.Descriptor; var preference = Settings.GetPreference(descriptor.MediaType); var context = new MediaDownloadContext(preference); context.CreateMediaFolder(e.CurrentMediaDownload.Media); trackDownloader.Context = context; trackDownloader.MediaService = AthameApp.GetService(descriptor.OriginalUri); }
/// <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)); }