Example #1
0
 public Stream(string strtitle, Game game = null, string strviewers = "n/a") {
     this.name = strtitle;
     this.viewers = strviewers;
     if (game != null) {
         this.game = game.name;
     }
     else {
         this.game = "n/a";
     }
 }
Example #2
0
        public override IEnumerable<Result> get_streamlist() {
            dynamic json = get_json();
            var resultlist = new List<Result>();

            foreach (var entry in json.featured) {
                var channel = entry.stream.channel.display_name.ToString();
                var viewers = entry.stream.viewers.ToString();
                var game = new Game(entry.stream.game.ToString());
                var stream = new Stream(channel, game: game, strviewers: viewers);
                resultlist.Add(stream);
            }

            return resultlist;
        }
Example #3
0
 public Channel(string chname, Game game, string chURL) {
     this.name = chname;
     this.game = game.name;
     this.url = chURL;
 }
Example #4
0
        public IEnumerable<Result> handle_queries() {

            /* implement feature that checks for multiple occurances
            of the same type and concatenate them to speed things up 
            Also the http clint should be moved here so we can reuse
            the same connection multiple times                       */
            List<Result> resultlist = new List<Result>();
            Dictionary<Type, List<Query>> grouped_queries = new Dictionary<Type, List<Query>>();

            foreach (var query in this.querylist) {
                var querytype = query.GetType();
                if (grouped_queries.ContainsKey(querytype)) {
                    grouped_queries[querytype].Add(query);
                } else {
                    var tmplist = new List<Query>();
                    tmplist.Add(query);
                    grouped_queries.Add(querytype, tmplist);
                }

            }

            foreach (var entry in this.querylist) {
                var querytype = entry.GetType();
                if (grouped_queries.ContainsKey(querytype)) {
                    foreach (var query in grouped_queries[querytype]) {
                        // now handle the grouped queries as one
                        if (query.querygroupoptions != null) {
                            queryoptions = query.querygroupoptions;
                            if (this.querystring != null) {
                                this.querystring = String.Join(",", this.querystring, query.querystring);
                            }
                            else {
                                this.querystring = query.querystring;
                            }
                        }
                        else {
                            foreach (var result in entry.get_streamlist()) {
                                resultlist.Add(result);
                            }
                        }
                    }
                    grouped_queries.Remove(querytype);
                } else {
                    continue;
                }
            }
            string querystr = queryoptions + System.Net.WebUtility.UrlEncode(this.querystring);
            var response = client.GetAsync(querystr).Result;
            var dataobjects = response.Content.ReadAsStringAsync().Result;
            var jsonresponse = JsonConvert.DeserializeObject<dynamic>(dataobjects);
            if (jsonresponse != null) {
                foreach (var jsonstream in jsonresponse.streams) {
                    if (jsonstream != null) {
                        var name = jsonstream.channel.display_name.ToString();
                        var game = new Game(jsonstream.game.ToString());
                        var viewers = jsonstream.viewers.ToString();

                        var stream = new Stream(name, game, viewers);
                        resultlist.Add(stream);
                    }
                    else if (jsonstream.error != null) {
                        resultlist.Add(new Error(jsonstream.message.ToString()));
                    }
                }

            }
            else {
                jsonresponse = new Error("Invalid JSON received from twitch");
                return JsonConvert.SerializeObject(jsonresponse);
            }
            return resultlist;
        }
Example #5
0
        public override IEnumerable<Result> get_streamlist() {
            dynamic json = get_json();
            var resultlist = new List<Result>();

            foreach (var entry in json.top) {
                var game = new Game(entry.game.name.ToString(), entry.viewers.ToString());
                resultlist.Add(game);
            }
            return resultlist;
        }
Example #6
0
        public override IEnumerable<Result> get_streamlist() {
            dynamic json = get_json();
            var resultlist = new List<Result>();

            if (json.stream != null) {
                var name = json.stream.channel.display_name.ToString();
                var game = new Game(json.stream.game.ToString());
                var viewers = json.stream.viewers.ToString();

                var stream = new Stream(name, game, viewers);
                resultlist.Add(stream);
            }
            else if (json.error != null) {
                resultlist.Add(new Error(json.message.ToString()));
            }
            else {
                resultlist.Add(new Error(string.Format("{0} is offline", this.querystring)));
            }
            
            return resultlist;
        }
Example #7
0
        public override IEnumerable<Result> get_streamlist() {
            dynamic json = get_json();
            var resultlist = new List<Result>();

            if (json.error != null) {
                var error = new Error(json.message.ToString());
                resultlist.Add(error);
                return resultlist;
            }

            var channame = json.display_name.ToString();
            Game game = null;

            if (json.game != null) {
                game = new Game(json.game.ToString());
            }
            else {
                game = new Game("n/a");
            }
            var url = json.url.ToString();
            var channel = new Channel(channame, game, url);
            resultlist.Add(channel);

            return resultlist;
        }