Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Add Comment
Please, Sign In to add comment