Пример #1
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);
        }
Пример #2
0
        public virtual void MediaDownloadCompleted(object sender, MediaDownloadEventArgs e)
        {
            var media = e.CurrentMediaDownload.Media;

            if (MediaType.Track == media.MediaType)
            {
                return;
            }

            var path       = trackDownloader.Context.MediaFolder;
            var trackFiles = trackDownloader.Context.TrackFiles;

            CreateArtworkFile(path, media);
            CreateMediaInfo(path, media);
            CreatePlaylistFile(path, media, trackFiles, Settings.PlaylistFileType);

            trackDownloader.Context      = null;
            trackDownloader.MediaService = null;
        }
Пример #3
0
        public async Task DownloadAsync(IEnumerable <MediaItem> items)
        {
            var mediaQ = new Queue <MediaItem>(items);

            while (mediaQ.Count > 0)
            {
                var currentMedia = mediaQ.Dequeue();
                var e            = new MediaDownloadEventArgs
                {
                    CurrentMediaDownload = currentMedia,
                    Index = items.Count() - mediaQ.Count - 1,
                    Total = items.Count()
                };

                OnMediaDownloadStarted(e);

                await downloader.DownloadAsync(currentMedia);

                OnMediaDownloadCompleted(e);
            }
        }
Пример #4
0
 protected void OnMediaDownloadCompleted(MediaDownloadEventArgs e)
 => MediaDownloadCompleted?.Invoke(this, e);