示例#1
0
        public async Task <Game[]> SearchGames(string query)
        {
            string res = await web.GetStringAsync("https://api.twitch.tv/kraken/search/games/?query=" + query);

            TwitchGamesResponse resp = JsonConvert.DeserializeObject <TwitchGamesResponse>(res);

            return(resp.games);
        }
示例#2
0
        private LiveStreamData MakeStreamData(TwitchStreamData streamData, TwitchGamesResponse gamesResponse, TwitchUsersResponse usersResponse)
        {
            var gameData = gamesResponse.Data.Find(x => streamData.Game_id == x.Id);

            if (gameData == null)
            {
                _logger.LogWarning($"{nameof(gameData)} Is Null; gameId: {streamData.Game_id};UserId: {streamData.User_id}; StreamName {streamData.Title}");
            }

            if (gameData?.Name == null)
            {
                _logger.LogWarning($"Twitch Game with Id {streamData.Game_id} not found");
            }

            var gameName = gameData?.Name ?? gameData?.Id ?? "Unknown game";

            var userData = usersResponse.Data.Find(x => streamData.User_id == x.Id);

            if (userData == null)
            {
                throw new InvalidOperationException($"{nameof(userData)} Is Null; gameId: {streamData.Game_id};UserId: {streamData.User_id} StreamName {streamData.Title}");
            }

            if (userData.Login == null)
            {
                _logger.LogError($"Twitch User with Id {streamData.User_id} not found");
                return(null);
            }

            var lsData = new LiveStreamData()
            {
                StreamName = streamData.Title,
                GameName   = gameName,
                UserName   = userData.Login,
                ChannelUrl = GetChannelUrl(userData.Login),
                StartedAt  = streamData.Started_at,
                Type       = streamData.Type
            };

            return(lsData);
        }