using System using System IO using System Net using System Text using

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using JsonClasses;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
DateTime date;
Timer timer = new Timer();
int timerCounter = 0;
public Form1()
{
InitializeComponent();
}
private void start_Click(object sender, EventArgs e)
{
File.WriteAllText("timer.txt", "");
File.WriteAllText("followersToday.txt", "0");
File.WriteAllText("song.txt", "");
date = DateTime.Now;
timer.Tick += new EventHandler(tickTimer);
timer.Interval = 1000;
if (start.Text == "Stop")
{
timer.Stop();
start.Text = "Start";
}
else
{
timer.Start();
start.Text = "Stop";
File.WriteAllText("timer.txt", "");
File.WriteAllText("followersToday.txt", "0");
File.WriteAllText("song.txt", "");
}
}
private void tickTimer(object sender, EventArgs e)
{
long tick = DateTime.Now.Ticks - date.Ticks;
DateTime stopWatch = new DateTime();
stopWatch = stopWatch.AddTicks(tick);
streamTime.Text = "Stream Time: " + String.Format("{0:HH:mm:ss}", stopWatch);
File.WriteAllText("timer.txt", streamTime.Text);
timerCounter++;
if (timerCounter == 10)
{
timer.Tick += new EventHandler(taskGetSong);
timer.Tick += new EventHandler(taskGetFollower);
timerCounter = 0;
}
}
private void taskGetSong(object sender, EventArgs e)
{
Task task = new Task(getSong);
task.Start();
}
private void taskGetFollower(object sender, EventArgs e)
{
Task task = new Task(getFollower);
task.Start();
}
private void getSong()
{
HttpWebRequest songRequest = (HttpWebRequest)WebRequest.Create("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=dockgg&api_key=e28039161acc777b14cfb09eb41ef896&limit=1&format=json");
HttpWebResponse response = (HttpWebResponse)songRequest.GetResponse();
string json = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
json = json.Replace("{\"#", "{\"");
json = json.Replace("@", "");
if (json.IndexOf("nowplaying") != -1)
{
var result = JsonConvert.DeserializeObject<RootObjectSong>(json);
songName.Text = "Song: " + result.recenttracks.track[0].artist.text + " - " + result.recenttracks.track[0].name;
File.WriteAllText("song.txt", songName.Text);
}
else
{
songName.Text = "Song: Doesn' t play";
}
}
private void getFollower()
{
HttpWebRequest songRequest = (HttpWebRequest)WebRequest.Create("https://api.twitch.tv/kraken/channels/dockgg/follows?limit=10");
HttpWebResponse response = (HttpWebResponse)songRequest.GetResponse();
string json = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
var result = JsonConvert.DeserializeObject<RootObjectFollower>(json);
lastFollower.Text = "Last Follower: " + result.follows[0].user.display_name;
File.WriteAllText("lastFollower.txt", lastFollower.Text);
string text = System.IO.File.ReadAllText(@"followers.txt");
for (int i = 0; i < 10; i++ )
{
if (text.IndexOf("<n>" + result.follows[i].user.name + "</n>") == -1)
{
text += "<n>" + result.follows[i].user.name + "</n>\n";
File.WriteAllText("followers.txt", text);
string folToday = System.IO.File.ReadAllText(@"followersToday.txt");
int num = Int32.Parse(folToday);
num++;
followersToday.Text = "Followers Today: " + String.Format("{0}", num);
}
}
}
}
}