Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Changelog
- //
- //Username entry now on same line
- //Added viewer count to live streams
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace temp
- {
- class Program
- {
- static void Main(string[] args)
- {
- using (var w = new WebClient())
- {
- //Prerequisites
- Console.ForegroundColor = ConsoleColor.Gray;
- string JsonData = "";
- //Header
- Console.WriteLine("Twicth Stream Status Checker v1.1");
- Console.WriteLine("Build by james_00000001 w/ help from rymate1234");
- //Start of loop
- Loop:
- Console.WriteLine("");
- //Get stream name
- Console.Write("Twitch Username: ");
- Console.ForegroundColor = ConsoleColor.White;
- string StreamName = Console.ReadLine();
- Console.ForegroundColor = ConsoleColor.Gray;
- //Check twitch
- try
- {
- JsonData = w.DownloadString("https://api.twitch.tv/kraken/streams/" + StreamName);
- }
- catch
- {
- //Bad reply
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("NOT FOUND");
- Console.ForegroundColor = ConsoleColor.Gray;
- goto Loop;
- }
- //Convert to readable format
- JObject JsonParsed = JObject.Parse(JsonData);
- JToken JsonToken = JsonParsed.GetValue("stream");
- //For debugging
- //Console.WriteLine(JsonData);
- //Check if user is live
- try
- {
- if (JsonToken.ToString().Equals(""))
- {
- //User offline
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("OFFLINE");
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- else
- {
- //User live
- string Viewers = JsonToken.SelectToken("viewers").ToString();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("LIVE - " + Viewers + " viewers");
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- }
- catch
- {
- //Error reading responce
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("READ ERROR");
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- //End of loop
- goto Loop;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment