Exemplo n.º 1
0
        private static void ConvertXml(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("文件名为空");
            }
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("文件不存在:" + path);
            }
            var extension = Path.GetExtension(path);

            if (string.IsNullOrWhiteSpace(extension) || (extension.ToUpper() != ".XML" && extension.ToUpper() != ".BIN"))
            {
                throw new InvalidOperationException("文件拓展名不是.xml或.bin:" + path);
            }
            try
            {
                var danmakus = DanmakuParser.LoadXmlFromFile(path);
                var ass      = DanmakuConverter.ConvertToAss(danmakus, config.Width, config.Height, "Microsoft YaHei", 64, config.Line, config.Bottom, config.Shift);
                File.WriteAllText(Path.ChangeExtension(path, ".ass"), ass, Encoding.UTF8);
            }
            catch
            {
                throw new Exception("处理文件时出错:" + path);
            }
        }
Exemplo n.º 2
0
        public static async Task MakeMultiAssAsync(Dictionary <string, string> fileName_xmlDic, string outputPath)
        {
            try
            {
                await StorageFolder.GetFolderFromPathAsync(outputPath);
            }
            catch (FileNotFoundException)
            {
                throw new DirectoryNotFoundException("找不到指定下载目录:" + outputPath);
            }
            var dir = await StorageFolder.GetFolderFromPathAsync(outputPath);

            var tasks = new List <Task>();

            foreach (var item in fileName_xmlDic)
            {
                tasks.Add(Task.Run(async() =>
                {
                    var file         = await dir.CreateFileAsync(item.Key);
                    var assContent   = DanmakuParser.LoadXmlFromString(item.Value).ToAss(1920, 1080);
                    var bytes        = Encoding.UTF8.GetBytes(assContent);
                    using var stream = await file.OpenStreamForWriteAsync();
                    await stream.WriteAsync(bytes, 0, bytes.Length);
                }));
            }
            await Task.WhenAll(tasks);
        }
        private async void DownloadDanmakuAssBtn_Click(object sender, RoutedEventArgs e)
        {
            foreach (var v in _master.Videos)
            {
                var xml = await BiliDanmakuHelper.GetDanmakuXmlStringAsync(v.Cid);

                var ass = DanmakuParser.LoadXmlFromString(xml).ToAss(1920, 1080);
            }
        }
Exemplo n.º 4
0
        public static async Task MakeAssAsync(string xml, string fileName, string outputPath)
        {
            try
            {
                await StorageFolder.GetFolderFromPathAsync(outputPath);
            }
            catch (FileNotFoundException)
            {
                throw new DirectoryNotFoundException("找不到指定下载目录:" + outputPath);
            }
            var dir = await StorageFolder.GetFolderFromPathAsync(outputPath);

            var file = await dir.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

            var assContent = DanmakuParser.LoadXmlFromString(xml).ToAss(1920, 1080);
            var bytes      = Encoding.UTF8.GetBytes(assContent);

            using var stream = await file.OpenStreamForWriteAsync();

            await stream.WriteAsync(bytes, 0, bytes.Length);
        }
Exemplo n.º 5
0
        public void Test1()
        {
            var ass = DanmakuParser.LoadXmlFromString(File.ReadAllText("test1.xml")).ToAss(1920, 1080);

            Assert.Contains("Script Info", ass);
        }