Ability to retrieve track info

This commit is contained in:
Victor 2017-08-29 09:19:28 +03:00
commit 48cfa93e5c
4 changed files with 155 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.dub
docs.json
__dummy.html
*.o
*.obj
__test__*__

9
dub.json Normal file
View File

@ -0,0 +1,9 @@
{
"name" : "anmusic",
"authors" : [
"aNNiMON"
],
"description" : "aNMusic",
"copyright" : "Copyright © 2017, aNNiMON",
"license" : "free"
}

View File

@ -0,0 +1,119 @@
module aimpremote;
import core.sys.windows.windows;
private const wstring AIMPRemoteAccessClass = "AIMP2_RemoteInfo";
private const int AIMPRemoteAccessMapFileSize = 2048;
align(1)
private struct AIMPRemoteFileInfo
{
DWORD deprecated1;
BOOL active;
DWORD bitRate;
DWORD channels;
DWORD duration;
align(4) INT64 fileSize;
DWORD fileMark;
DWORD sampleRate;
DWORD trackNumber;
DWORD albumLength;
DWORD artistLength;
DWORD dateLength;
DWORD fileNameLength;
DWORD genreLength;
DWORD titleLength;
DWORD[6] deprecated2;
};
private enum TagItem {
Album, Artist, Date, FileName, Genre, Title
}
public struct TrackInfo {
wstring artist;
wstring title;
wstring genre;
};
public static TrackInfo getInfo() {
import std.conv : to;
import std.traits : EnumMembers;
auto haimp = OpenFileMapping(FILE_MAP_READ, 0, AIMPRemoteAccessClass.ptr);
const auto hfilemap = MapViewOfFile(haimp, FILE_MAP_READ, 0, 0, AIMPRemoteAccessMapFileSize);
AIMPRemoteFileInfo* info = cast(AIMPRemoteFileInfo*) hfilemap;
auto bytes = (cast(ubyte*) hfilemap)[0 .. AIMPRemoteAccessMapFileSize];
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 (index, immutable item; [EnumMembers!TagItem]) {
auto key = to!TagItem(index);
auto length = lengthInfo[key];
trackInfo[key] = cast(wstring)(bytes[pbuff .. (pbuff + length * wcharsize)]);
pbuff += length * wcharsize;
}
TrackInfo result = {
artist: trackInfo[TagItem.Artist],
title: trackInfo[TagItem.Title],
genre: trackInfo[TagItem.Genre]
};
return result;
}
private static HWND findPlayerWindow() {
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("Samplerate: ");
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);
}
}*/

21
source/app.d Normal file
View File

@ -0,0 +1,21 @@
import std.stdio;
import std.net.curl;
import aimpremote;
void main()
{
auto http = HTTP();
// http.caInfo("cacert.pem");
http.handle.set(CurlOption.ssl_verifypeer, 0);
auto track = getInfo();
auto content = post("https://annimon.com/json/nowplay", [
"login" : "test",
"token" : "5token",
"artist" : to!string(track.artist),
"title" : to!string(track.title),
"genre" : to!string(track.genre)
], http);
}