Ejemplo n.º 1
0
        public async Task <bool> CreateVideoAsync(IProgress <VideoProgress> progress, CancellationToken ct)
        {
            return(await Task.Run(async() =>
            {
                var video = await TwitchDownloader.DownloadVideoInfoAsync(ID, progress, ct);

                if (video?.ID == null)
                {
                    return false;
                }

                var bits = await TwitchDownloader.DownloadBitsAsync(video.StreamerID, progress, ct);
                var badges = await TwitchDownloader.DownloadBadgesAsync(video.StreamerID, progress, ct);
                //var bttv = await BTTV.CreateAsync(video.Streamer, progress, ct);
                //var ffz = await FFZ.CreateAsync(video.Streamer, progress, ct);
                var messages = await TwitchDownloader.GetChatAsync(ID, video.Duration, progress, ct);

                if (ct.IsCancellationRequested)
                {
                    return false;
                }

                //using (var chat_handler = new ChatHandler(this, bttv, ffz, badges, bits))
                using (var chat_handler = new ChatHandler(this, badges, bits))
                {
                    int current = 0;

                    try
                    {
                        var drawables = messages?.Select(m =>
                        {
                            progress?.Report(new VideoProgress(++current, messages.Count, VideoProgress.VideoStatus.Drawing));
                            return chat_handler.MakeDrawableMessage(m);
                        }).ToList();


                        var max = (int)(FPS *video.Duration);

                        var path = string.Format("{0}{1}-{2}.mp4", OutputDirectory, video.Streamer, video.ID);
                        var result = await WriteVideoFrames(path, drawables, 0, max, progress, ct);
                        progress?.Report(new VideoProgress(1, 1, VideoProgress.VideoStatus.CleaningUp));
                        drawables.ForEach(d => d.Lines.ForEach(l => l.Drawables.ForEach(dr => dr.Dispose())));

                        return result;
                    }
                    catch (Exception e)
                    {
                        using (StreamWriter w = File.AppendText("error.txt"))
                        {
                            w.WriteLine($"{DateTime.Now.ToLongTimeString()} : {e.ToString()}");
                        }

                        return false;
                    };
                }
            }));
        }
Ejemplo n.º 2
0
        public Cheer GetCheer(string word)
        {
            var match = Regex.Match(word, @"([A-Za-z]+)(\d+)");

            if (!match.Success)
            {
                return(default(Cheer));
            }

            var name = match.Groups[1].Value.ToLower();

            if (!cheer_dictionary.ContainsKey(name))
            {
                return(default(Cheer));
            }

            var cheer_tiers = cheer_dictionary[name];
            var amount      = int.Parse(match.Groups[2].Value);

            var max_cheer = 0;

            foreach (var key in cheer_tiers.Keys)
            {
                if (amount >= key)
                {
                    max_cheer = Math.Max(max_cheer, key);
                }
            }

            var cache_name = name + '-' + max_cheer;
            var cheer      = cheer_tiers[max_cheer];

            if (image_cache.ContainsKey(cache_name))
            {
                return(new Cheer()
                {
                    Emote = image_cache[cache_name],
                    Color = cheer.Color,
                    Amount = amount,
                });
            }

            var local_path = BaseDir + cache_name + ".gif";

            var img = TwitchDownloader.GetImage(local_path, cheer.Images.DarkMode.Animated[1]);

            image_cache.Add(cache_name, img);

            return(new Cheer()
            {
                Emote = img,
                Color = cheer.Color,
                Amount = amount,
            });
        }
Ejemplo n.º 3
0
        public static Image GetEmote(string name)
        {
            if (name == null)
            {
                return(null);
            }

            if (image_cache.ContainsKey(name))
            {
                return(image_cache[name]);
            }

            var emote_path = BaseDir + name + ".png";
            var url        = string.Format(EmoteDownload, name, EmoteSize);
            var img        = TwitchDownloader.GetImage(emote_path, url);

            image_cache.Add(name, img);

            return(img);
        }
Ejemplo n.º 4
0
        public Image GetEmote(string name)
        {
            if (!emote_dictionary.ContainsKey(name))
            {
                return(null);
            }

            if (image_cache.ContainsKey(name))
            {
                return(image_cache[name]);
            }

            var emote      = emote_dictionary[name];
            var local_path = BaseDir + emote.ID + "." + emote.ImageType;
            var url        = string.Format(EmoteDownload, emote.ID, EmoteSize);
            var img        = TwitchDownloader.GetImage(local_path, url);

            image_cache.Add(name, img);

            return(img);
        }
Ejemplo n.º 5
0
        public Image Lookup(String type, String version)
        {
            var concat = id + "/" + type + "-" + version;

            if (image_cache.ContainsKey(concat))
            {
                return(image_cache[concat]);
            }

            var badge = lookup.ContainsKey(type) && lookup[type].ContainsKey(version) ? lookup[type][version] : default(TwitchBadge);

            if (badge.Name == string.Empty)
            {
                return(null);
            }

            var local_path = BaseDir + concat;
            var img        = TwitchDownloader.GetImage(local_path, badge.URL);

            image_cache[concat] = img;

            return(img);
        }