Пример #1
0
    public DownloadTask(IPlaylistHandler playlistHandler, IMessageHandler messageHandler, IContentDownloadHelper contentDownloadHelper, IVideoListContainer container, IVideosUnchecker unchecker)
    {
        this._cts                   = new CancellationTokenSource();
        this._messageHandler        = messageHandler;
        this._contentDownloadHelper = contentDownloadHelper;
        this._playlistHandler       = playlistHandler;
        this._container             = container;
        this._unchecker             = unchecker;

        this.OnWait       = _ => { };
        this.TaskFunction = async(_, _) => await this.DownloadAsync();

        this.IsCompleted  = new ReactiveProperty <bool>().AddTo(this.disposables);
        this.IsProcessing = new ReactiveProperty <bool>().AddTo(this.disposables);
        this.IsCanceled   = new ReactiveProperty <bool>().AddTo(this.disposables);
        this.Message      = new ReactiveProperty <string>("未初期化").AddTo(this.disposables);

        this.Resolution.Subscribe(value =>
        {
            if (this._settings is not null)
            {
                this._settings.VerticalResolution = value;
            }
        });
    }
        protected void TestDeserializedExtraData(IPlaylistHandler handler, string playlistFile)
        {
            string outputFile = Path.Combine(OutputPath, "SavedExtraData.bplist");

            Directory.CreateDirectory(OutputPath);
            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }
            Assert.IsTrue(File.Exists(playlistFile), $"Could not find test file at '{playlistFile}'");

            using var fs = File.OpenRead(playlistFile);
            IPlaylist playlist = handler.Deserialize(fs);
            Dictionary <string, object> customData = playlist.CustomData ?? new Dictionary <string, object>();

            if (customData["extensionStringList"] is JArray)
            {
                Assert.Fail("Failed to convert string list.");
            }
            if (customData["extensionIntList"] is JArray)
            {
                Assert.Fail("Failed to convert int list.");
            }
            Assert.AreEqual(123, Convert.ToInt32(customData["customInt"]));
            Assert.AreEqual("test string", customData["extensionString"]);
            Assert.AreEqual(123.456d, customData["extensionFloat"]);
            using var fs2 = File.Create(outputFile);
            handler.Serialize(playlist, fs2);
        }
Пример #3
0
        public SortInfoHandler(IPlaylistHandler playlistHandler, ICurrent current, IVideoListContainer container, ILogger logger)
        {
            this.playlistHandler = playlistHandler;
            this.current         = current;
            this.container       = container;
            this.logger          = logger;

            this.SortType             = new ReactiveProperty <VideoSortType>(current.SelectedPlaylist.Value?.VideoSortType ?? VideoSortType.Register);
            this.IsDescending         = new ReactiveProperty <bool>(current.SelectedPlaylist.Value?.IsVideoDescending ?? false);
            this.IdColumnTitle        = new ReactiveProperty <string>(DefaultIdColumnTitle);
            this.TitleColumnTitle     = new ReactiveProperty <string>(DefaultTitleColumnTitle);
            this.UploadColumnTitle    = new ReactiveProperty <string>(DefaultUploadColumnTitle);
            this.DlFlagColumnTitle    = new ReactiveProperty <string>(DefaultDlFlagColumnTitle);
            this.ViewCountColumnTitle = new ReactiveProperty <string>(DefaultViewCountColumnTitle);
            this.StateColumnTitle     = new ReactiveProperty <string>(DefaultStateColumnTitle);
            this.EconomyColumnTitle   = new ReactiveProperty <string>(DefaultEconomyColumnTitle);
            this.SortTypeStr          = this.SortType.Select(value => value switch
            {
                VideoSortType.NiconicoID => DefaultIdColumnTitle,
                VideoSortType.Title => DefaultTitleColumnTitle,
                VideoSortType.UploadedDT => DefaultUploadColumnTitle,
                VideoSortType.ViewCount => DefaultViewCountColumnTitle,
                VideoSortType.Custom => "カスタム",
                VideoSortType.State => DefaultStateColumnTitle,
                VideoSortType.Economy => DefaultEconomyColumnTitle,
                _ => "登録順",
            }).ToReactiveProperty().AddTo(this.disposables);
 /// <summary>
 /// Attempts to deserialize and return an <see cref="IPlaylist"/> from a file.
 /// </summary>
 /// <param name="handler"><see cref="IPlaylistHandler"/> to use.</param>
 /// <param name="path">Path to the file.</param>
 /// <returns>An <see cref="IPlaylist"/>.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null or empty.</exception>
 /// <exception cref="ArgumentException">Thrown if a file at <paramref name="path"/> does not exist.</exception>
 /// <exception cref="PlaylistSerializationException">Thrown if an error occurs while deserializing.</exception>
 public static IPlaylist Deserialize(this IPlaylistHandler handler, string path)
 {
     if (handler == null)
     {
         throw new ArgumentNullException(nameof(handler), $"{nameof(handler)} cannot be null.");
     }
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException(nameof(path), "path cannot be null or empty.");
     }
     path = Path.GetFullPath(path);
     if (!File.Exists(path))
     {
         throw new ArgumentException($"File at '{path}' does not exist or is inaccessible.");
     }
     try
     {
         using FileStream stream = Utilities.OpenFileRead(path);
         return(handler.Deserialize(stream));
     }
     catch (Exception ex)
     {
         throw new PlaylistSerializationException(ex.Message, ex);
     }
 }
 /// <summary>
 /// Serializes an <see cref="IPlaylist"/> to a file.
 /// </summary>
 /// <param name="handler"><see cref="IPlaylistHandler"/> to use.</param>
 /// <param name="playlist">The <see cref="IPlaylist"/> to serialize</param>
 /// <param name="path">The path to the target file to serialize to</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null or empty.</exception>
 /// <exception cref="ArgumentException">Thrown if <paramref name="playlist"/> is not of type <see cref="IPlaylistHandler.HandledType"/>.</exception>
 /// <exception cref="PlaylistSerializationException">Thrown if an error occurs while serializing.</exception>
 public static void SerializeToFile(this IPlaylistHandler handler, IPlaylist playlist, string path)
 {
     if (handler == null)
     {
         throw new ArgumentNullException(nameof(handler), $"{nameof(handler)} cannot be null.");
     }
     if (playlist == null)
     {
         throw new ArgumentNullException(nameof(playlist), $"{nameof(playlist)} cannot be null.");
     }
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException(nameof(path), "path cannot be null or empty.");
     }
     try
     {
         string backupPath = path + ".bak";
         if (File.Exists(path))
         {
             File.Move(path, backupPath);
         }
         using FileStream stream = File.Open(path, FileMode.Create, FileAccess.ReadWrite);
         handler.Serialize(playlist, stream);
         if (File.Exists(backupPath))
         {
             File.Delete(backupPath);
         }
     }
     catch (Exception ex)
     {
         throw new PlaylistSerializationException(ex.Message, ex);
     }
 }
 /// <summary>
 /// Populates the target <see cref="IPlaylist"/> with data from a file.
 /// </summary>
 /// <param name="handler"><see cref="IPlaylistHandler"/> to use.</param>
 /// <param name="path">Path to the file.</param>
 /// <param name="target">Target <see cref="IPlaylist"/>.</param>
 /// <returns>An <see cref="IPlaylist"/>.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null or empty.</exception>
 /// <exception cref="ArgumentException">Thrown if a file at <paramref name="path"/> does not exist
 /// or <paramref name="target"/>'s type doesn't match <see cref="IPlaylistHandler.HandledType"/>.</exception>
 /// <exception cref="PlaylistSerializationException">Thrown if an error occurs while deserializing.</exception>
 public static void Populate(this IPlaylistHandler handler, string path, IPlaylist target)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target), $"{nameof(target)} cannot be null.");
     }
     if (handler == null)
     {
         throw new ArgumentNullException(nameof(handler), $"{nameof(handler)} cannot be null.");
     }
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException(nameof(path), "path cannot be null or empty.");
     }
     if (!handler.HandledType.IsAssignableFrom(target.GetType()))
     {
         throw new ArgumentException($"target's type, '{target.GetType().Name}' cannot be handled by {handler.GetType().Name}.", nameof(target));
     }
     path = Path.GetFullPath(path);
     if (!File.Exists(path))
     {
         throw new ArgumentException($"File at '{path}' does not exist or is inaccessible.");
     }
     try
     {
         using FileStream stream = Utilities.OpenFileRead(path);
         handler.Populate(stream, target);
     }
     catch (Exception ex)
     {
         throw new PlaylistSerializationException(ex.Message, ex);
     }
 }
Пример #7
0
 public Coordinator(ILoveProvider loveProvider, IDataProvider dataProvider, IPlaylistHandler playlistHandler, IFile file, string userName, string rootFileName)
 {
     _loveProvider    = loveProvider;
     _dataProvider    = dataProvider;
     _playlistHandler = playlistHandler;
     _file            = file;
     _userName        = userName;
     _rootFileName    = rootFileName;
 }
Пример #8
0
        public static PlaylistManager GetPlaylistManager(string playlistDir, IPlaylistHandler defaultHandler, params IPlaylistHandler[] playlistHandlers)
        {
            if (Directory.Exists(playlistDir))
            {
                Directory.Delete(playlistDir, true);
            }
            Assert.IsFalse(Directory.Exists(playlistDir));
            PlaylistManager manager = new PlaylistManager(playlistDir, defaultHandler, playlistHandlers);

            Assert.IsTrue(Directory.Exists(playlistDir));
            return(manager);
        }
 /// <summary>
 /// Creates a new <see cref="PlaylistManager"/> to manage playlists in <paramref name="playlistDirectory"/>
 /// and sets the default <see cref="IPlaylistHandler"/> to <paramref name="defaultHandler"/>.
 /// Also creates the directory given in <paramref name="playlistDirectory"/>.
 /// </summary>
 /// <param name="playlistDirectory"></param>
 /// <param name="defaultHandler"></param>
 /// <param name="otherHandlers"></param>
 /// <exception cref="IOException">Thrown if directory creation fails.</exception>
 public PlaylistManager(string playlistDirectory, IPlaylistHandler defaultHandler, params IPlaylistHandler[] otherHandlers)
     : this(playlistDirectory)
 {
     DefaultHandler = defaultHandler;
     RegisterHandler(defaultHandler);
     if (otherHandlers != null)
     {
         for (int i = 0; i < otherHandlers.Length; i++)
         {
             RegisterHandler(otherHandlers[i]);
         }
     }
 }
Пример #10
0
        public VideoListContainer(IPlaylistHandler playlistHandler, IVideoHandler videoHandler, IVideoListRefresher refresher, ICurrent current, ILogger logger)
        {
            this.videoHandler     = videoHandler;
            this.refresher        = refresher;
            this.current          = current;
            this.logger           = logger;
            this.Videos           = new ObservableCollection <IListVideoInfo>();
            this._playlistHandler = playlistHandler;

            this.current.IsTemporaryPlaylist.Subscribe(value =>
            {
                if (value)
                {
                    this.Clear();
                }
            });
        }
Пример #11
0
        /// <summary>
        /// プレイリストを作成する
        /// </summary>
        /// <param name="filepaths"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public string GetPlaylist(IEnumerable <string> filepaths, string name, PlaylistType type)
        {
            var playlist = new Playlist()
            {
                PlaylistName = name,
            };

            playlist.AddRange(filepaths);
            if (playlist.Count == 0)
            {
                throw new InvalidOperationException("空のプレイリストを作成することは出来ません。");
            }

            IPlaylistHandler handler = type switch
            {
                PlaylistType.Aimp => new AIMP.AimpPlaylisthandler(),
                _ => throw new InvalidOperationException($"不明なプレイリストです。({type})")
            };

            return(handler.CreatePlaylist(playlist));
        }
    }
Пример #12
0
 public Shutdown(IDataBase dataBase, IPlaylistHandler playlistHandler, IAddonContexts contexts)
 {
     this.dataBase        = dataBase;
     this.playlistHandler = playlistHandler;
     this._contexts       = contexts;
 }