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

Commit 8654412

Browse files
author
Jason Sadler
committed
Fixes brave/brave-browser#971. Fine tuning Twitch time.
Reverted fix addressed in another PR. linting Updated media ID split to check for delimiter existence
1 parent 6b2796a commit 8654412

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

include/bat/ledger/publisher_info.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ LEDGER_EXPORT struct PublisherInfoFilter {
5151
int category;
5252
PUBLISHER_MONTH month;
5353
int year;
54-
std::vector<std::pair<std::string, bool>> order_by;
5554
PUBLISHER_EXCLUDE excluded;
55+
56+
std::vector<std::pair<std::string, bool>> order_by;
5657
};
5758

5859
LEDGER_EXPORT struct ContributionInfo {

src/bat_get_media.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "bat_get_media.h"
77

88
#include <sstream>
9+
#include <cmath>
910

1011
#include "bat_get_media.h"
1112
#include "bat_helper.h"
@@ -112,12 +113,16 @@ void BatGetMedia::getPublisherInfoDataCallback(const std::string& mediaId, const
112113
_2,
113114
_3));
114115
} else if (TWITCH_MEDIA_TYPE == providerName) {
115-
const std::string mediaUrl = getMediaURL(mediaId, providerName);
116+
const std::string twitchMediaID =
117+
mediaId.find(MEDIA_DELIMITER) != std::string::npos ?
118+
mediaId :
119+
braveledger_bat_helper::split(mediaId, MEDIA_DELIMITER)[0];
120+
const std::string mediaUrl = getMediaURL(twitchMediaID, providerName);
116121
std::unique_ptr<ledger::PublisherInfo> new_publisher_info(new ledger::PublisherInfo());
117122
new_publisher_info->favicon_url = "";
118123
new_publisher_info->url = mediaUrl + "/videos";
119-
std::string id = providerName + "#author:" + mediaId;
120-
new_publisher_info->name = mediaId;
124+
std::string id = providerName + "#author:" + twitchMediaID;
125+
new_publisher_info->name = twitchMediaID;
121126
new_publisher_info->id = id;
122127

123128
ledger::TwitchEventInfo oldEvent;
@@ -253,11 +258,15 @@ uint64_t BatGetMedia::getTwitchDuration(const ledger::TwitchEventInfo& oldEventI
253258
return 0;
254259
}
255260

261+
if (oldEventInfo.status_.empty()) { // if autoplay is off and play is pressed
262+
return 0;
263+
}
264+
256265
if (time > TWITCH_MAXIMUM_SECONDS_CHUNK) {
257266
time = TWITCH_MAXIMUM_SECONDS_CHUNK;
258267
}
259268

260-
return (uint64_t)time;
269+
return (uint64_t)std::round(time);
261270
}
262271

263272
void BatGetMedia::getPublisherFromMediaPropsCallback(const uint64_t& duration, const std::string& media_key,

src/static_values.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#define YOUTUBE_PROVIDER_NAME "YouTube"
5252
#define TWITCH_PROVIDER_NAME "Twitch"
5353
#define YOUTUBE_PROVIDER_URL "https://www.youtube.com/oembed"
54+
#define MEDIA_DELIMITER '_'
5455

5556
#define SEED_LENGTH 32
5657
#define SALT_LENGTH 64

0 commit comments

Comments
 (0)