示例#1
0
        /// <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));
        }
示例#2
0
        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);
        }
示例#3
0
        public MainWindowViewModel()
        {
            app        = Locator.Current.GetService <AthameApp>();
            downloader = new MediaDownloadManager();
            source     = new MediaDownloadSource();

            Router = new RoutingState();

            MediaSearch    = new MediaSearchViewModel();
            ProgressStatus = new ProgressStatusViewModel();
            MediaItems     = new MediaItemsViewModel(source);

            DownloadMediaCommand = ReactiveCommand.CreateFromTask(
                DownloadMedia,
                MediaItems.CanDownload);
            CancelDownloadCommand = ReactiveCommand.Create(RemoveMedia);
            CanRestoreCommand     = ReactiveCommand.Create(CanRestore);
            SaveSettingsCommand   = ReactiveCommand.Create(SaveSettings);
            ViewSettingsCommand   = ReactiveCommand.CreateFromObservable(
                Router.Navigate <SettingsViewModel>);
            ViewAboutAppCommand = ReactiveCommand.CreateFromObservable(
                Router.Navigate <AboutMeViewModel>);

            Activator = new ViewModelActivator();
            this.WhenActivated((CompositeDisposable disposables) =>
            {
                this.WhenAnyValue(x => x.MediaSearch.SearchResult)
                .Where(media => media != null)
                .Subscribe(AddMedia)
                .DisposeWith(disposables);

                Observable
                .FromEventPattern <MediaDownloadEventArgs>(downloader, nameof(downloader.MediaDownloadStarted))
                .Subscribe(e => MediaServiceDequeued(e.EventArgs))
                .DisposeWith(disposables);
                Observable
                .FromEventPattern <TrackDownloadEventArgs>(downloader, nameof(downloader.TrackDownloadStarted))
                .Subscribe()
                .DisposeWith(disposables);
                Observable
                .FromEventPattern <TrackDownloadEventArgs>(
                    downloader.TrackDownloader, nameof(downloader.TrackDownloader.TrackDownloadStarted), RxApp.MainThreadScheduler)
                .Subscribe(e => TrackDownloadStarted(e.EventArgs));
                Observable
                .FromEventPattern <TrackDownloadEventArgs>(downloader, nameof(downloader.TrackDownloadProgressChanged))
                .Subscribe(e => TrackDownloadProgressed(e.EventArgs))
                .DisposeWith(disposables);
                Observable
                .FromEventPattern <TrackDownloadEventArgs>(downloader, nameof(downloader.TrackDownloadCompleted))
                .Subscribe(e => TrackDownloadCompleted(e.EventArgs))
                .DisposeWith(disposables);
            });
        }
示例#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));
        }