Created
June 17, 2018 20:14
-
-
Save niklas152/b2595b775153b7f50361098ad8ee6235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <ctime> | |
#include <sstream> | |
#include <locale> | |
#include <iomanip> | |
#define ARTIST_PREFIX 20 | |
#define TRACK_PREFIX 19 | |
#define TIME_PREFIX 14 | |
#define POSTFIX 2 | |
struct lastFmEntry { | |
std::string artist; | |
std::string title; | |
std::string album = "single"; | |
int track = 1; | |
long timestamp; | |
int length = 300; | |
char noIdea = 'P'; | |
}; | |
int main() { | |
std::tm t = {}; | |
lastFmEntry currentEntry; | |
bool newEntry = true; | |
std::string line; | |
while (std::getline(std::cin, line)) { | |
if (newEntry) { | |
currentEntry.artist = ""; | |
currentEntry.title = ""; | |
currentEntry.timestamp = 0; | |
newEntry = false; | |
} | |
if (line.find("artistName") != std::string::npos) { | |
std::string artist = line.substr(ARTIST_PREFIX, line.size() - ARTIST_PREFIX - POSTFIX); | |
if (artist.find(',') != std::string::npos) { | |
currentEntry.artist = artist.substr(0, artist.find(',')); | |
} else currentEntry.artist = artist; | |
} else if (line.find("track") != std::string::npos) { | |
currentEntry.title = line.substr(TRACK_PREFIX, line.size() - TRACK_PREFIX - POSTFIX); | |
} else if (line.find("time") != std::string::npos) { | |
// convert human readable time to unix gmt timestamp | |
std::istringstream ss(line.substr(TIME_PREFIX, line.size() - TIME_PREFIX - POSTFIX + 1)); | |
ss >> std::get_time(&t, "%Y-%m-%d %H:%M:%S"); | |
currentEntry.timestamp = std::mktime(&t); | |
if (1528715908 < currentEntry.timestamp && currentEntry.timestamp < 1528960251) { | |
std::cout << | |
"a = " << currentEntry.artist << "\n" << | |
"t = " << currentEntry.title << "\n" << | |
"b = " << currentEntry.album << "\n" << | |
"n = " << currentEntry.track << "\n" << | |
"i = " << currentEntry.timestamp << "\n" << | |
"l = " << currentEntry.length << "\n" << | |
"o = " << currentEntry.noIdea << "\n\n"; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment