Guest User

Twicth Stream Status Checker v1.1

a guest
Nov 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. //Changelog
  2. //
  3. //Username entry now on same line
  4. //Added viewer count to live streams
  5.  
  6. using Newtonsoft.Json.Linq;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13.  
  14. namespace temp
  15. {
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             using (var w = new WebClient())
  21.             {
  22.                 //Prerequisites
  23.                 Console.ForegroundColor = ConsoleColor.Gray;
  24.                 string JsonData = "";
  25.  
  26.                 //Header
  27.                 Console.WriteLine("Twicth Stream Status Checker v1.1");
  28.                 Console.WriteLine("Build by james_00000001 w/ help from rymate1234");
  29.  
  30.                 //Start of loop
  31.                 Loop:
  32.                 Console.WriteLine("");
  33.  
  34.                 //Get stream name
  35.                 Console.Write("Twitch Username: ");
  36.                 Console.ForegroundColor = ConsoleColor.White;
  37.                 string StreamName = Console.ReadLine();
  38.                 Console.ForegroundColor = ConsoleColor.Gray;
  39.  
  40.                 //Check twitch
  41.                 try
  42.                 {
  43.                     JsonData = w.DownloadString("https://api.twitch.tv/kraken/streams/" + StreamName);
  44.                 }
  45.                 catch
  46.                 {
  47.                     //Bad reply
  48.                     Console.ForegroundColor = ConsoleColor.DarkYellow;
  49.                     Console.WriteLine("NOT FOUND");
  50.                     Console.ForegroundColor = ConsoleColor.Gray;
  51.                     goto Loop;
  52.                 }
  53.  
  54.                 //Convert to readable format
  55.                 JObject JsonParsed = JObject.Parse(JsonData);
  56.                 JToken JsonToken = JsonParsed.GetValue("stream");
  57.  
  58.                 //For debugging
  59.                 //Console.WriteLine(JsonData);
  60.  
  61.                 //Check if user is live
  62.                 try
  63.                 {
  64.                     if (JsonToken.ToString().Equals(""))
  65.                     {
  66.                         //User offline
  67.                         Console.ForegroundColor = ConsoleColor.Red;
  68.                         Console.WriteLine("OFFLINE");
  69.                         Console.ForegroundColor = ConsoleColor.Gray;
  70.                     }
  71.                     else
  72.                     {
  73.                         //User live
  74.                         string Viewers = JsonToken.SelectToken("viewers").ToString();
  75.                         Console.ForegroundColor = ConsoleColor.Green;
  76.                         Console.WriteLine("LIVE - " + Viewers + " viewers");
  77.                         Console.ForegroundColor = ConsoleColor.Gray;
  78.                     }
  79.                 }
  80.                 catch
  81.                 {
  82.                     //Error reading responce
  83.                     Console.ForegroundColor = ConsoleColor.DarkYellow;
  84.                     Console.WriteLine("READ ERROR");
  85.                     Console.ForegroundColor = ConsoleColor.Gray;
  86.                 }
  87.  
  88.                 //End of loop
  89.                 goto Loop;
  90.             }
  91.         }
  92.     }
  93. }
Add Comment
Please, Sign In to add comment