Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
Fixes brave/brave-browser#971. Fixed youtube time recording truncations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Sadler committed Sep 26, 2018
1 parent 07cf007 commit 0ac4ce5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ static bool ignore_ = false;

uint64_t getMediaDuration(const std::map<std::string, std::string>& data, const std::string& media_key, const std::string& type) {
uint64_t duration = 0;

if (YOUTUBE_MEDIA_TYPE == type) {
std::map<std::string, std::string>::const_iterator iterSt = data.find("st");
std::map<std::string, std::string>::const_iterator iterEt = data.find("et");
Expand All @@ -1864,17 +1864,21 @@ static bool ignore_ = false;
if (startTime.size() != endTime.size()) {
return 0;
}
double tempTime = 0;
// get all the intervals and combine them.
// (Should only be one set if there were no seeks)
for (size_t i = 0; i < startTime.size(); i++) {
std::stringstream tempET(endTime[i]);
std::stringstream tempST(startTime[i]);
double st = 0;
double et = 0;
tempET >> et;
tempST >> st;
tempTime = et - st;

// round instead of truncate
// also make sure we include previous iterations
// if more than one set exists
duration += (uint64_t)std::round(et - st);
}
duration = (uint64_t)tempTime;
}
} else if (TWITCH_MEDIA_TYPE == type) {
// We set the correct duration for twitch in BatGetMedia class
Expand Down

0 comments on commit 0ac4ce5

Please sign in to comment.