public void MigrateTwitchVODMetadata()
        {
            var channelId = _twitchService.GetChannelIdFromChannelName("dasmehdi").GetAwaiter().GetResult();

            ChannelVideos videos = null;

            var offset = 0;

            do
            {
                videos = _twitchService.GetVideosFromChannelId(channelId, offset).GetAwaiter().GetResult();

                videos.Videos.ForEach(video =>
                {
                    var vod = new Vod()
                    {
                        ImportedAt = DateTime.UtcNow,
                        Video      = video
                    };

                    var dbVod = _vodCollection.AddOrUpdateAsync(vod).GetAwaiter().GetResult();
                    Assert.IsInstanceOfType(dbVod, typeof(Vod));
                });

                offset += 100;
            } while (offset <= videos.Total);
        }
        public async Task <string> GetVodByGame(string channelName, string game)
        {
            Video video;

            var dbVideos = (await _vodCollection.GetAsync()).ToList();

            if (!dbVideos.All(v => v.Value.Video.Channel.Name.Contains(channelName)))
            {
                var channelId = await _twitchClient.GetChannelIdFromChannelName(channelName);

                video = await _twitchClient.GetVideoFromChannelIdWithGame(channelId, game);
            }
            else
            {
                try
                {
                    var videoRow = dbVideos.Where(dbv => dbv.Value.Video.Game.Contains(game)).Select(v => v.Value)
                                   .FirstOrDefault();
                    video = videoRow?.Video;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            if (video == null)
            {
                return("No video for that game could be found. Please try another.");
            }

            var shortUrl = _googleService.UrlShortener.ShortenUrl($"https://www.twitch.tv/videos/{video.Id}");

            return($"{video.Title} - {shortUrl}");
        }
        public async void Perform(TwitchClient client, TwitchService service, ChatCommand chatCommand, Command command)
        {
            if (!command.IsActive)
            {
                return;
            }

            var channel = chatCommand.ArgumentsAsList.FirstOrDefault() ?? "KungRaseri";
            var uptime  = await service.GetUpTimeByChannel(await service.GetChannelIdFromChannelName(channel));

            if (uptime.HasValue)
            {
                var uptimePhrase = $"{(uptime.Value.Hours > 0 ? uptime.Value.Hours + " hours " : " ")} {(uptime.Value.Minutes > 0 ? uptime.Value.Minutes + " minutes " : " ")}";
                var message      = $"{channel} has been live for {uptimePhrase}";

                client.SendMessage(chatCommand.ChatMessage.Channel, message);
            }
            else
            {
                client.SendMessage(chatCommand.ChatMessage.Channel, $"{channel} is offline.");
            }
        }
Beispiel #4
0
        public void GetChannelIdFromChannel_ReturnsChannelId()
        {
            var channelId = _twitchService.GetChannelIdFromChannelName("dasmehdi").GetAwaiter().GetResult();

            Assert.IsTrue(channelId == "31557869");
        }