示例#1
0
        static async Task ProcessChannel(Channel channel)
        {
            //Get the records
            Console.WriteLine("Processing Channel " + channel.ChannelId);
            var records = await mixer.GetRecordingsAsync(channel.ChannelId, settings.GameType, channel.LastRecording);

            foreach (var record in records)
            {
                //Get the file
                string url  = record.GetMP4Url();
                string path = Path.Combine(settings.TempDirectory, record.ID + ".source.mp4");
                Console.WriteLine("Channel Video {0} : {1}", record.ID, path);

                try
                {
                    //If the file doesn't exist download it
                    if (!File.Exists(path))
                    {
                        Console.WriteLine("Downloading....");
                        var   downloadStopWatch = Stopwatch.StartNew();
                        ulong downloadedBytes   = 0;
                        using (var stream = await downloader.GetStreamAsync(url))
                        {
                            using (var file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
                            {
                                int read;
                                while ((read = await stream.ReadAsync(downloadBuffer, 0, downloadBuffer.Length)) > 0)
                                {
                                    downloadedBytes += (ulong)read;
                                    await file.WriteAsync(downloadBuffer, 0, read);
                                }
                            }
                        }
                        Console.WriteLine("Downloaded {0}MB, took {2}s", downloadedBytes / 1024 / 1024, downloadStopWatch.Elapsed.TotalSeconds);
                    }

                    //Updated our last recorded channel
                    channel.LastRecording = record.CreatedAt;

                    //Perform the clipping
                    using (var trimmer = new Trimmer(settings.Tesseract)
                    {
                        Prefix = record.ID + ".",
                        DeleteTemporaryFiles = settings.DeleteTemporaryFiles,
                        TemporaryFileDirectory = settings.TempDirectory
                    })
                    {
                        var highlights = trimmer.GenerateClips(path, clipDirectory, channel.SiegeName);
                        var json       = JsonConvert.SerializeObject(highlights);
                        File.WriteAllText(clipDirectory + "/" + record.ID + ".json", json);
                    }

                    //Save the settings once we are done.
                    SaveSettings();
                }
                finally
                {
                    //Delete the temporary file, f**k storing your shit gameplay amirite
                    if (settings.DeleteTemporaryFiles && File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
            Console.WriteLine("DONE");

            //await Task.Run(() => Downloader.Download(records.FirstOrDefault().GetMP4Url(), "potato", 4));
        }