-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
149 lines (126 loc) · 5.62 KB
/
Program.cs
File metadata and controls
149 lines (126 loc) · 5.62 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Web;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Flurl.Http;
using Flurl;
namespace di320fm
{
static class Program
{
private const string UserUri = @"https://api.audioaddict.com/v1/di/members";
private const string HttpAuthUsername = "ephemeron";
private const string HttpAuthPwd = "dayeiph0ne@pp";
private static void Main()
{
var email = Helper.RandomString(10) + "@google.com";
var password = Helper.RandomString(10);
const string firstName = "nihau";
const string lastName = "1337";
User me;
var credentials = new NetworkCredential(HttpAuthUsername, HttpAuthPwd);
using (var handler = new HttpClientHandler { Credentials = credentials })
using (var client = new HttpClient(handler))
{
//register
//done in such way coz Flurl can't work with non-standard api keys
var registerParams = new Dictionary<string, string>
{
{ "member[email]", email },
{ "member[first_name]", firstName },
{ "member[last_name]", lastName },
{ "member[password]", password },
{ "member[password_confirmation]", password },
};
var response = client.PostAsync(UserUri, new FormUrlEncodedContent(registerParams));
var jsonResponse = response.Result.Content.ReadAsStringAsync();
me = JsonConvert.DeserializeObject<User>(jsonResponse.Result);
var login = "https://api.audioaddict.com/v1/di/members/authenticate"
.SetQueryParams(new { api_key = me.ApiKey })
.WithBasicAuth("ephemeron", "dayeiph0ne@pp")
.PostAsync()
.ReceiveJson()
.Result;
//confirmation
var confirmation = "http://www.di.fm/member/confirm/"
.AppendPathSegment(me.ConfirmationToken)
.GetAsync()
.Result;
login = "https://api.audioaddict.com/v1/di/members/authenticate"
.SetQueryParams(new { api_key = me.ApiKey })
.WithBasicAuth("ephemeron", "dayeiph0ne@pp")
.PostAsync()
.ReceiveJson()
.Result;
var canTrial = UserUri.AppendPathSegment("/1/subscriptions/trial_allowed/premium-pass")
.SetQueryParams(new { api_key = me.ApiKey })
.WithBasicAuth("ephemeron", "dayeiph0ne@pp")
.GetAsync()
.ReceiveJson<TrialAvailability>()
.Result;
if (canTrial.Allowed)
{
//activate trial
var trial =
UserUri.AppendPathSegment("/1/subscriptions/trial/premium-pass")
.SetQueryParams(new { api_key = me.ApiKey })
.WithBasicAuth("ephemeron", "dayeiph0ne@pp")
.PostAsync()
.ReceiveJson()
.Result;
}
//must login after activating
login = "https://api.audioaddict.com/v1/di/members/authenticate"
.SetQueryParams(new { api_key = me.ApiKey })
.WithBasicAuth("ephemeron", "dayeiph0ne@pp")
.PostAsync()
.ReceiveJson()
.Result;
}
Console.WriteLine("New key " + me.ListenKey);
ChangeListenKey(me.ListenKey);
Console.WriteLine($"{email}");
Console.WriteLine($"{password}");
}
/// <summary>
/// OH SUCH DIRTY WOW
/// </summary>
/// <param name="newKey">gimme your key brah, i know you got it</param>
private static void ChangeListenKey(string newKey)
{
var stations = JsonConvert.DeserializeObject<IEnumerable<Station>>("http://listen.di.fm/public3".GetStringAsync().Result);
const string plsFile = "Digitally Imported.pls";
string text = String.Empty;
var sb = new StringBuilder();
sb.AppendLine("[playlist]");
sb.AppendLine("NumberOfEntries=" + stations.Count());
var ij = 0;
foreach(var station in stations.OrderBy(x => x.Name))
{
ij++;
sb.AppendLine(String.Format(@"File{0}=http://prem2.di.fm:80/{1}_hi?09f33f12640bf313a5737e1e", ij, station.Key));
sb.AppendLine(String.Format("Title{0}=Digitally Imported - {1}", ij, station.Name));
sb.AppendLine(String.Format("Length{0}=-1", ij));
}
sb.AppendLine("Version=2");
text = sb.ToString();
int i = -1;
for (; ; )
{
i = text.IndexOf("?", i + 1);
if (i < 0)
break;
var j = text.IndexOf("\n", i);
text = text.Substring(0, i + 1) + newKey + text.Substring(j, text.Length - j);
}
File.WriteAllText(Path.GetFileNameWithoutExtension(plsFile) + " updated.pls", text);
}
}
}