Add config properties and worker thread
This commit is contained in:
parent
d149f8625f
commit
aa6e02e731
3
config.properties
Normal file
3
config.properties
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
login=test
|
||||||
|
token=token
|
||||||
|
update_time=1
|
5
dub.json
5
dub.json
@ -5,5 +5,8 @@
|
|||||||
],
|
],
|
||||||
"description" : "aNMusic",
|
"description" : "aNMusic",
|
||||||
"copyright" : "Copyright © 2017, aNNiMON",
|
"copyright" : "Copyright © 2017, aNNiMON",
|
||||||
"license" : "free"
|
"license" : "free",
|
||||||
|
"dependencies" : {
|
||||||
|
"variantconfig": "~>1.1.5"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
dub.selections.json
Normal file
6
dub.selections.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"fileVersion": 1,
|
||||||
|
"versions": {
|
||||||
|
"variantconfig": "1.1.5"
|
||||||
|
}
|
||||||
|
}
|
@ -136,44 +136,3 @@ public static Nullable!TrackInfo getInfo() {
|
|||||||
private static HWND findPlayerWindow() {
|
private static HWND findPlayerWindow() {
|
||||||
return FindWindow(AIMPRemoteAccessClass.ptr, null);
|
return FindWindow(AIMPRemoteAccessClass.ptr, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void main() {
|
|
||||||
import std.stdio : writeln, write;
|
|
||||||
|
|
||||||
auto haimp = OpenFileMapping(FILE_MAP_READ, 0, AIMPRemoteAccessClass.ptr);
|
|
||||||
auto hfilemap = MapViewOfFile(haimp, FILE_MAP_READ, 0, 0, AIMPRemoteAccessMapFileSize);
|
|
||||||
|
|
||||||
AIMPRemoteFileInfo* info = cast(AIMPRemoteFileInfo*) hfilemap;
|
|
||||||
write("Bitrate: ");
|
|
||||||
writeln(info.bitRate);
|
|
||||||
write("Samlerate: ");
|
|
||||||
writeln(info.sampleRate);
|
|
||||||
write("fileSize: ");
|
|
||||||
writeln(info.fileSize);
|
|
||||||
|
|
||||||
auto bytes = (cast(ubyte*) hfilemap)[0 .. AIMPRemoteAccessMapFileSize];
|
|
||||||
writeln(bytes);
|
|
||||||
|
|
||||||
|
|
||||||
const wcharsize = wchar.sizeof;
|
|
||||||
auto pbuff = AIMPRemoteFileInfo.sizeof;
|
|
||||||
|
|
||||||
DWORD[TagItem] lengthInfo;
|
|
||||||
wstring[TagItem] trackInfo;
|
|
||||||
|
|
||||||
lengthInfo[TagItem.Album] = info.albumLength;
|
|
||||||
lengthInfo[TagItem.Artist] = info.artistLength;
|
|
||||||
lengthInfo[TagItem.Date] = info.dateLength;
|
|
||||||
lengthInfo[TagItem.FileName] = info.fileNameLength;
|
|
||||||
lengthInfo[TagItem.Genre] = info.genreLength;
|
|
||||||
lengthInfo[TagItem.Title] = info.titleLength;
|
|
||||||
foreach (key; TagItem.min .. TagItem.max) {
|
|
||||||
auto length = lengthInfo[key];
|
|
||||||
trackInfo[key] = cast(wstring)(bytes[pbuff .. (pbuff + length * wcharsize)]);
|
|
||||||
pbuff += length * wcharsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (key, value; trackInfo) {
|
|
||||||
writeln(value);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
86
source/app.d
86
source/app.d
@ -1,25 +1,91 @@
|
|||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.net.curl;
|
import std.net.curl;
|
||||||
|
import std.datetime;
|
||||||
|
import std.typecons;
|
||||||
|
import std.algorithm.searching : startsWith;
|
||||||
|
import std.conv : to;
|
||||||
|
import std.file;
|
||||||
|
import core.thread;
|
||||||
import aimpremote;
|
import aimpremote;
|
||||||
|
import variantconfig;
|
||||||
|
|
||||||
|
shared string login;
|
||||||
|
shared string token;
|
||||||
|
shared int update_time;
|
||||||
|
|
||||||
void main()
|
bool readConfig() {
|
||||||
{
|
if (!exists("config.properties")) {
|
||||||
|
writeln("Unable to open config.properties file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto config = VariantConfig("config.properties");
|
||||||
|
login = config["login"].toStr;
|
||||||
|
if (login.length == 0) {
|
||||||
|
writeln("Unable to find login");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
token = config["token"].toStr;
|
||||||
|
if (token.length == 0) {
|
||||||
|
writeln("Unable to find token");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
update_time = config["update_time"].toInt;
|
||||||
|
if (update_time <= 0) {
|
||||||
|
update_time = 2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void process() {
|
||||||
|
final switch (getPlayerState()) {
|
||||||
|
case PlayerState.Off:
|
||||||
|
case PlayerState.Stopped:
|
||||||
|
case PlayerState.Paused:
|
||||||
|
Thread.sleep(dur!"seconds"(10));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PlayerState.Playing:
|
||||||
|
auto track = getInfo();
|
||||||
|
if (!track.isNull) {
|
||||||
|
auto time = Clock.currTime();
|
||||||
|
writefln("[%02d:%02d] %s - %s",
|
||||||
|
time.hour, time.minute,
|
||||||
|
track.artist, track.title);
|
||||||
|
sendTrackInfo(track);
|
||||||
|
}
|
||||||
|
Thread.sleep(dur!"minutes"(update_time));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendTrackInfo(Nullable!TrackInfo track) {
|
||||||
auto http = HTTP();
|
auto http = HTTP();
|
||||||
// http.caInfo("cacert.pem");
|
// http.caInfo("cacert.pem");
|
||||||
http.handle.set(CurlOption.ssl_verifypeer, 0);
|
http.handle.set(CurlOption.ssl_verifypeer, 0);
|
||||||
|
|
||||||
auto track = getInfo();
|
|
||||||
if (track.isNull) {
|
|
||||||
writeln("No data");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto content = post("https://annimon.com/json/nowplay", [
|
auto content = post("https://annimon.com/json/nowplay", [
|
||||||
"login" : "test",
|
"login" : login,
|
||||||
"token" : "5token",
|
"token" : token,
|
||||||
"artist" : to!string(track.artist),
|
"artist" : to!string(track.artist),
|
||||||
"title" : to!string(track.title),
|
"title" : to!string(track.title),
|
||||||
"genre" : to!string(track.genre)
|
"genre" : to!string(track.genre)
|
||||||
], http);
|
], http);
|
||||||
|
if (content.startsWith("{\"error")) {
|
||||||
|
writeln(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
writeln("Starting aNMusic");
|
||||||
|
if (!readConfig()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
new Thread({
|
||||||
|
while (true) {
|
||||||
|
process();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user