diff --git a/include/bat/ledger/ledger.h b/include/bat/ledger/ledger.h index 0abe433b1936..d14f9ca6fe1e 100644 --- a/include/bat/ledger/ledger.h +++ b/include/bat/ledger/ledger.h @@ -122,7 +122,8 @@ class LEDGER_EXPORT Ledger { virtual void SetMediaPublisherInfo(const std::string& media_key, const std::string& publisher_id) = 0; virtual void GetMediaPublisherInfo(const std::string& media_key, - PublisherInfoCallback callback) = 0; + PublisherInfoCallback callback, + bool use_as_publisher_key = false) = 0; virtual std::vector GetRecurringDonationPublisherInfo() = 0; virtual void GetPublisherInfoList(uint32_t start, uint32_t limit, const ledger::PublisherInfoFilter& filter, diff --git a/include/bat/ledger/publisher_info.h b/include/bat/ledger/publisher_info.h index 82aeb3517f5d..b85aaf3ca0bf 100644 --- a/include/bat/ledger/publisher_info.h +++ b/include/bat/ledger/publisher_info.h @@ -65,6 +65,7 @@ LEDGER_EXPORT struct PublisherInfoFilter { std::vector> order_by; unsigned int min_duration; uint64_t reconcile_stamp; + std::string url; }; LEDGER_EXPORT struct ContributionInfo { diff --git a/src/bat_get_media.cc b/src/bat_get_media.cc index 28f21778f2b3..38d02092f3e0 100644 --- a/src/bat_get_media.cc +++ b/src/bat_get_media.cc @@ -68,6 +68,7 @@ void BatGetMedia::processMedia(const std::map& parts, if (type == YOUTUBE_MEDIA_TYPE) { duration = braveledger_bat_helper::getMediaDuration(parts, media_key, type); } else if (type == TWITCH_MEDIA_TYPE) { + twitch_media_key_ = media_key; std::map::const_iterator iter = parts.find("event"); if (iter != parts.end()) { twitchEventInfo.event_ = iter->second; @@ -181,7 +182,7 @@ void BatGetMedia::getPublisherInfoDataCallback(const std::string& mediaId, const updated_visit_data.name = publisher_info->name; updated_visit_data.url = publisher_info->url; if (providerName == YOUTUBE_MEDIA_TYPE) { - updated_visit_data.provider = YOUTUBE_PROVIDER_NAME; + updated_visit_data.provider = YOUTUBE_MEDIA_TYPE; updated_visit_data.favicon_url = publisher_info->favicon_url; std::string id = publisher_info->id; ledger_->SaveMediaVisit(id, updated_visit_data, duration); @@ -355,25 +356,9 @@ void BatGetMedia::getPublisherInfoCallback(const uint64_t& duration, const std:: const std::string& publisherName, const ledger::VisitData& visit_data, bool success, const std::string& response, const std::map& headers) { if (success && providerName == YOUTUBE_MEDIA_TYPE) { - std::string favIconURL = ""; - std::string avatarStr = "\"avatar\":{\"thumbnails\":[{\"url\":\""; - size_t startPos = response.find(avatarStr) + avatarStr.size(); - if (startPos != std::string::npos) { - size_t endPos = response.find("\"", startPos + avatarStr.size()); - if (endPos != std::string::npos && endPos > startPos) { - favIconURL = response.substr(startPos, endPos - startPos); - } - } - std::string channelId; - std::string channel_str = "\"ucid\":\""; - startPos = response.find(channel_str) + channel_str.size(); - if (startPos != std::string::npos) { - size_t endPos = response.find("\"", startPos + channel_str.size()); - if (endPos != std::string::npos && endPos > startPos) { - channelId = response.substr(startPos, endPos - startPos); - } - } + std::string favIconURL = parseFavIconUrl(response); + std::string channelId = parseChannelId(response); std::string publisher_id = providerName + "#channel:"; if (channelId.empty()) { @@ -411,13 +396,457 @@ std::string BatGetMedia::getMediaURL(const std::string& mediaId, const std::stri return res; } -void BatGetMedia::getMediaActivityFromUrl(uint64_t windowId, - const std::string& url, - const std::string& providerType, - ledger::PUBLISHER_MONTH month, - int year) { - // TODO NZ add logic +std::string BatGetMedia::getPublisherUrl(const std::string& publisher_key, + const std::string& providerName) { + std::string res; + DCHECK(!publisher_key.empty()); + if (YOUTUBE_MEDIA_TYPE == providerName) { + res = "https://www.youtube.com/channel/" + publisher_key; + } else if (TWITCH_MEDIA_TYPE == providerName) { + res = "https://www.twitch.tv/" + publisher_key; + } + + return res; +} + +void BatGetMedia::getMediaActivityFromUrl( + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath) { + if (providerType == YOUTUBE_MEDIA_TYPE) { + processYoutubeMediaPanel(windowId, visit_data, providerType, altPath); + + } else if (providerType == TWITCH_MEDIA_TYPE) { + processTwitchMediaPanel(windowId, visit_data, providerType); + } else { // treat as regular page + ledger_->GetPublisherActivityFromUrl( + windowId, visit_data); + } +} + +void BatGetMedia::processYoutubeMediaPanel(uint64_t windowId, + const ledger::VisitData& visit_data, const std::string& providerType, + bool altPath) { + if (visit_data.path.find("/watch") != std::string::npos) { + processYoutubeWatchPath(windowId, visit_data, providerType); + } else if (visit_data.path.find("/channel") != std::string::npos) { + processYoutubeChannelPath(windowId, visit_data, providerType, altPath); + } else if (visit_data.path.find("/user") != std::string::npos) { + processYoutubeUserPath(windowId, visit_data, providerType); + } else { + processYoutubeAlternatePath(windowId, visit_data, providerType, altPath); + } +} + +void BatGetMedia::processTwitchMediaPanel(uint64_t windowId, + const ledger::VisitData& visit_data, const std::string& providerType) { + std::string media_key; +} + +void BatGetMedia::onCheckTwitchResponse( + bool success, const std::string& response, + const std::map& headers) { + LOG(ERROR) << "=============TWITCH RESPONSE: " << response; +} + +void BatGetMedia::processYoutubeWatchPath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType) { + std::string media_key = getYoutubeMediaKeyFromUrl(providerType, visit_data); + if (!media_key.empty()) { + ledger_->GetMediaPublisherInfo(media_key, + std::bind(&BatGetMedia::onMediaPublisherActivity, + this, _1, _2, windowId, visit_data, + providerType, media_key)); + } +} + +void BatGetMedia::processYoutubeChannelPath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath) { + std::string publisher_key = "youtube#channel:"; + std::string key = getYoutubePublisherKeyFromUrl(providerType, visit_data); + if (!key.empty()) { + publisher_key += key; + fetchPublisherDataFromDB(windowId, visit_data, + providerType, publisher_key, altPath); + } else { + // get headliner video media key and see if we have it + fetchPublisherDataFromUrl(windowId, visit_data, providerType, altPath); + } +} + +void BatGetMedia::processYoutubeUserPath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType) { + fetchPublisherDataFromUserUrl(windowId, visit_data, providerType); +} + +void BatGetMedia::processYoutubeAlternatePath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath) { + fetchPublisherDataFromUrl(windowId, visit_data, providerType, altPath); +} + +void BatGetMedia::fetchPublisherDataFromDB(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& publisher_key, + bool altPath) { + if (altPath) { + auto filter = createPublisherFilter( + publisher_key, ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE, + visit_data.local_month, visit_data.local_year, + ledger::PUBLISHER_EXCLUDE::ALL, false, 0); + ledger_->GetPublisherInfo(filter, + std::bind(&BatGetMedia::onFetchPublisherFromDBResponse, + this, _1, _2, windowId, visit_data, providerType, publisher_key, altPath)); + } else { + ledger_->GetMediaPublisherInfo(publisher_key, + std::bind(&BatGetMedia::onFetchPublisherFromDBResponse, + this, _1, _2, windowId, visit_data, providerType, publisher_key, altPath)); + } +} + +void BatGetMedia::onFetchPublisherFromDBResponse( + ledger::Result result, + std::unique_ptr info, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& publisher_key, + bool altPath) { + if (result == ledger::Result::NOT_FOUND) { + fetchPublisherDataFromUrl(windowId, visit_data, providerType, altPath); + } else { + ledger_->OnPublisherActivity(result, std::move(info), windowId); + } +} + +void BatGetMedia::fetchPublisherDataFromUrl(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath) { + auto request = ledger_->LoadURL(visit_data.url, + std::vector(), "", "", + ledger::URL_METHOD::GET, &handler_); + handler_.AddRequestHandler(std::move(request), + std::bind(&BatGetMedia::onGetChannelHeadlineVideo, + this, windowId, visit_data, providerType, altPath, _1, + _2, _3)); + // +} + +void BatGetMedia::fetchPublisherDataFromUserUrl(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType) { + auto request = ledger_->LoadURL(visit_data.url, + std::vector(), "", "", + ledger::URL_METHOD::GET, &handler_); + handler_.AddRequestHandler(std::move(request), + std::bind(&BatGetMedia::onGetExternalIdFromUserPage, + this, windowId, visit_data, providerType, _1, + _2, _3)); +} + +void BatGetMedia::onGetExternalIdFromUserPage(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool success, const std::string& response, + const std::map& headers) { + processYoutubeAsPublisherType(response, windowId, visit_data, providerType); +} + +void BatGetMedia::onGetChannelHeadlineVideo(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath, bool success, const std::string& response, + const std::map& headers) { + if (visit_data.path.find("/channel") != std::string::npos || + visit_data.path.find("/user") != std::string::npos) { + if (channelHasAuthor(response) || altPath) { + processYoutubeAsMediaType(response, windowId, visit_data, providerType); + return; + } + } else { + processYoutubeAsPublisherType(response, windowId, visit_data, + providerType, altPath); + return; + } + ledger_->GetPublisherActivityFromUrl(windowId, visit_data); +} + + +void BatGetMedia::processYoutubeAsPublisherType( + const std::string& data, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath) { + std::string channelId = parsePublisherLink(data); + if (!channelId.empty()) { + std::string newPath = "/channel"; + if (visit_data.path.find("/user") == std::string::npos) { + altPath = true; + } + std::string publisherUrl = getPublisherUrl(channelId, providerType); + getMediaActivityFromUrl(windowId, visit_data, providerType, altPath); + } else { + ledger_->GetPublisherActivityFromUrl(windowId, visit_data); + } +} + +void BatGetMedia::processYoutubeAsMediaType( + const std::string& data, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType) { + std::string media_key = parseHeadlineMediaKey(data); + ledger::VisitData new_visit_data(visit_data); + if (!media_key.empty()) { + new_visit_data.url = getMediaURL(media_key, providerType); + new_visit_data.path = "/watch"; + processYoutubeWatchPath(windowId, new_visit_data, providerType); + } else { + ledger_->GetPublisherActivityFromUrl( + windowId, visit_data); + } +} + +void BatGetMedia::onMediaPublisherActivity(ledger::Result result, + std::unique_ptr info, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key) { + + if (ledger::Result::LEDGER_OK != result && + ledger::Result::NOT_FOUND != result) { + return; // TODO(jsadler) handle error + } + if (ledger::Result::NOT_FOUND == result) { + createMediaVisit( + windowId, visit_data, providerType, media_key); + } else { + ledger_->OnPublisherActivity(result, std::move(info), windowId); + } +} + +void BatGetMedia::createMediaVisit(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key) { + fetchYoutubeEmbedInfo(windowId, visit_data, providerType, media_key); + } + +void BatGetMedia::fetchYoutubeEmbedInfo( + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key) { + auto request = ledger_->LoadURL((std::string)YOUTUBE_PROVIDER_URL + + "?format=json&url=" + ledger_->URIEncode(visit_data.url), + std::vector(), "", "", ledger::URL_METHOD::GET, &handler_); + handler_.AddRequestHandler(std::move(request), + std::bind(&BatGetMedia::onGetMediaPublisher, + this, windowId, visit_data, providerType, + media_key, _1, _2, _3)); +} + +void BatGetMedia::onGetMediaPublisher( + uint64_t windowId, const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key, bool success, + const std::string& response, + const std::map& headers) { + if (providerType == YOUTUBE_MEDIA_TYPE) { + std::string publisherURL; + if (!success) { + return; // TODO(jsadler) handle error + } + braveledger_bat_helper::getJSONValue( + "author_url", response, publisherURL); + std::string publisherName; + braveledger_bat_helper::getJSONValue( + "author_name", response, publisherName); + + auto request = ledger_->LoadURL(publisherURL, + std::vector(), "", "", + ledger::URL_METHOD::GET, &handler_); + handler_.AddRequestHandler(std::move(request), + std::bind(&BatGetMedia::onGetChannelInfo, this, windowId, visit_data, + providerType, publisherURL, publisherName, + media_key, _1, _2, _3)); + } +} + +void BatGetMedia::onGetChannelInfo(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string publisherURL, + const std::string& publisherName, const std::string& media_key, bool success, + const std::string& response, + const std::map& headers) { + if (success) { + + std::string favIconURL = parseFavIconUrl(response); + std::string publisher_name = publisherName; + if (publisherName.empty()) { + publisher_name = parsePublisherName(response); + } + + std::string pubUrl = publisherURL + "/videos"; + std::string publisher_id = parsePublisherId(publisherURL, providerType); + saveMediaVisit(windowId, visit_data, publisher_name, pubUrl, + providerType, favIconURL, publisher_id, media_key, + std::bind(&BatGetMedia::getMediaActivity, this, windowId, + visit_data, providerType, _1)); + } +} + +void BatGetMedia::getMediaActivity(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + ledger::Result result) { + if (result != ledger::Result::LEDGER_OK) { + return; // TODO(jsadler) handle error + } + getMediaActivityFromUrl(windowId, visit_data, providerType); +} + +void BatGetMedia::saveMediaVisit(uint64_t windowId, + const ledger::VisitData& visit_data, const std::string& providerType, + const std::string publisherName, const std::string& publisherURL, + const std::string& favIconURL, const std::string& publisher_id, + const std::string& media_key, MediaPublisherInfoCallback callback) { + ledger::VisitData media_visit_data(YOUTUBE_TLD, YOUTUBE_TLD, + visit_data.path, -1, visit_data.local_month, visit_data.local_year, publisherName, + publisherURL, providerType, favIconURL); + ledger_->SaveMediaVisit(publisher_id, media_visit_data, 0); + ledger_->SetMediaPublisherInfo(media_key, publisher_id); + callback(ledger::Result::LEDGER_OK); +} + + +std::string BatGetMedia::parsePublisherId(const std::string& publisherURL, + const std::string& provider_name) { + size_t pos = publisherURL.rfind("/"); + std::string publisher_id = provider_name + "#channel:"; + if (pos != std::string::npos && pos < publisherURL.length() - 1) { + publisher_id += publisherURL.substr(pos + 1); + } + return publisher_id; +} + +std::string BatGetMedia::parseHeadlineMediaKey(const std::string& data) { + return extractData(data, "\"videoId\":\"", "\""); +} + +std::string BatGetMedia::parsePublisherLink(const std::string& data) { + std::string externalId = extractData(data, + "externalId\":\"", "\""); + return externalId; +} + +std::string BatGetMedia::parsePublisherName(const std::string& data) { + return extractData(data, "\"author\":\"", "\""); +} + +std::string BatGetMedia::parseFavIconUrl(const std::string& data) { + std::string favicon_url = extractData(data, + "\"avatar\":{\"thumbnails\":[{\"url\":\"", "\""); + if (favicon_url.length() > 0) { + std::string favicon_key = "https://" + ledger_->GenerateGUID() + + ".invalid"; + ledger_->FetchFavIcon(favicon_url, favicon_key); + favicon_url = favicon_key; + } + return favicon_url; +} + +std::string BatGetMedia::parseChannelId(const std::string& data) { + return extractData(data, "\"ucid\":\"", "\""); +} + +bool BatGetMedia::channelHasAuthor(const std::string& data) { + return !extractData(data, "\"author\":\"", "\"").empty(); +} + +std::string BatGetMedia::getYoutubeMediaKeyFromUrl( + const std::string& provider_type, + const ledger::VisitData& visit_data) { + std::vector m_url = + braveledger_bat_helper::split(visit_data.url, '='); + if (m_url.size() > 1) { + return provider_type + "_" + m_url[1]; + } else { + // TODO(jsadler) handle error + return std::string(); + } + return std::string(); +} + +std::string BatGetMedia::getYoutubePublisherKeyFromUrl( + const std::string& provider_type, + const ledger::VisitData& visit_data) { + return extractData(visit_data.url, "/channel/", "/"); +} + +void BatGetMedia::getTwitchMediaKey(uint64_t windowId, +const ledger::VisitData& visit_data, +const std::string& provider_type) { + LOG(ERROR) << "======+++++++TWITCH PATH: " << visit_data.path; + if (provider_type == TWITCH_MEDIA_TYPE) { + if (visit_data.path.find("/videos") != std::string::npos) { + //vod + } else { + + } + } +} + +std::string BatGetMedia::extractData(const std::string& data, + const std::string& matchAfter, const std::string& matchUntil) { + std::string match; + if (data.find(matchAfter) != std::string::npos) { + size_t startPos = data.find(matchAfter) + matchAfter.size(); + if (startPos != std::string::npos) { + size_t endPos = data.find(matchUntil, startPos + matchAfter.size()); + if (endPos != std::string::npos && endPos > startPos) { + match = data.substr(startPos, endPos - startPos); + } else { + match = data.substr(startPos, endPos); + } + } + } + return match; +} + +std::string BatGetMedia::getPublisherKeyFromUrl(const std::string& data) { + return extractData(data, "/channel/", "/"); +} +ledger::PublisherInfoFilter BatGetMedia::createPublisherFilter( + const std::string& publisher_id, + ledger::PUBLISHER_CATEGORY category, + ledger::PUBLISHER_MONTH month, + int year, + ledger::PUBLISHER_EXCLUDE excluded, + bool min_duration, + const uint64_t& currentReconcileStamp) { + ledger::PublisherInfoFilter filter; + filter.id = publisher_id; + filter.category = category; + filter.month = month; + filter.year = year; + filter.excluded = excluded; + filter.min_duration = min_duration ? ledger_->GetPublisherMinVisitTime() : 0; + filter.reconcile_stamp = currentReconcileStamp; + + return filter; } } // namespace braveledger_bat_get_media diff --git a/src/bat_get_media.h b/src/bat_get_media.h index 872ef706658e..3eac4801e207 100644 --- a/src/bat_get_media.h +++ b/src/bat_get_media.h @@ -23,6 +23,8 @@ class DB; namespace braveledger_bat_get_media { +using MediaPublisherInfoCallback = std::function; + class BatGetMedia { public: static std::string GetLinkType(const std::string& url, const std::string& first_party_url, const std::string& referrer); @@ -36,15 +38,14 @@ class BatGetMedia { const uint64_t& duration, const ledger::TwitchEventInfo& twitchEventInfo, const ledger::VisitData& visit_data); void getMediaActivityFromUrl(uint64_t windowId, - const std::string& url, - const std::string& providerType, - ledger::PUBLISHER_MONTH month, - int year); + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath = false); private: std::string getMediaURL(const std::string& mediaId, const std::string& providerName); void getPublisherFromMediaPropsCallback(const uint64_t& duration, const std::string& media_key, - const std::string& providerName, const std::string& mediaURL, const ledger::VisitData& visit_data, + const std::string& providerName, const std::string& mediaURL, const ledger::VisitData& visit_data, bool result, const std::string& response, const std::map& headers); void getPublisherInfoCallback(const uint64_t& duration, const std::string& media_key, @@ -59,9 +60,157 @@ class BatGetMedia { const ledger::VisitData& visit_data, ledger::Result result, std::unique_ptr media_publisher_info); + void getMediaActivity(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + ledger::Result result); + + void onMediaPublisherActivity(ledger::Result result, + std::unique_ptr info, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key); + + void createMediaVisit(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key); + + void onGetChannelInfo(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string publisherURL, + const std::string& publisherName, const std::string& media_key, + bool success, const std::string& response, + const std::map& headers); + + void onGetExternalIdFromUserPage(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool success, const std::string& response, + const std::map& headers); + + void onGetMediaPublisher( + uint64_t windowId, const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key, bool success, + const std::string& response, + const std::map& headers); + + void onGetMediaActivityFromUrl(bool success, + const std::string& response, + const std::map& headers, + const std::string& providerType, + const std::string& url, + uint64_t windowId); + + void saveMediaVisit(uint64_t windowId, const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string publisherName, + const std::string& publisherURL, + const std::string& favIconURL, const std::string& publisher_id, + const std::string& media_key, MediaPublisherInfoCallback callback); + void processYoutubeMediaPanel(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath); + void processTwitchMediaPanel(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType); + void processYoutubeWatchPath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType); + void processYoutubeChannelPath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath = false); + void processYoutubeUserPath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType); + void processYoutubeAlternatePath(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath); + void getTwitchMediaKey(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType); + void onGetChannelHeadlineVideo(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath, bool success, const std::string& response, + const std::map& headers); + void onFetchPublisherFromDBResponse( + ledger::Result result, + std::unique_ptr info, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& publisher_key, + bool altPath = false); + void onCheckTwitchResponse( + bool success, const std::string& response, + const std::map& headers); + void processYoutubeAsMediaType( + const std::string& data, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType); + void processYoutubeAsPublisherType( + const std::string& data, + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath = false); + void fetchYoutubeEmbedInfo( + uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& media_key); + std::string parsePublisherName(const std::string& data); + std::string parseFavIconUrl(const std::string& data); + std::string parsePublisherId(const std::string& publisherURL, + const std::string& provider_name); + std::string parseChannelId(const std::string& data); + std::string getYoutubeMediaKeyFromUrl( + const std::string& provider_type, + const ledger::VisitData& visit_data); + std::string getYoutubePublisherKeyFromUrl( + const std::string& provider_type, + const ledger::VisitData& visit_data); + std::string parseHeadlineMediaKey(const std::string& data); + std::string extractData(const std::string& data, + const std::string& matchAfter, const std::string& matchUntil); + std::string parsePublisherLink(const std::string& data); + std::string getPublisherUrl(const std::string& publisher_key, + const std::string& providerName); + std::string getPublisherKeyFromUrl(const std::string& data); + bool channelHasAuthor(const std::string& data); + void fetchPublisherDataFromDB(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + const std::string& publisher_key, + bool altPath = false); + void fetchPublisherDataFromUrl(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType, + bool altPath = false); + void fetchPublisherDataFromUserUrl(uint64_t windowId, + const ledger::VisitData& visit_data, + const std::string& providerType); + ledger::PublisherInfoFilter createPublisherFilter( + const std::string& publisher_id, + ledger::PUBLISHER_CATEGORY category, + ledger::PUBLISHER_MONTH month, + int year, + ledger::PUBLISHER_EXCLUDE excluded, + bool min_duration, + const uint64_t& currentReconcileStamp); + bat_ledger::LedgerImpl* ledger_; // NOT OWNED bat_ledger::URLRequestHandler handler_; + std::string twitch_media_key_; std::map twitchEvents; }; diff --git a/src/bat_publishers.cc b/src/bat_publishers.cc index 22fab6ec78b4..e7cfe60e1e80 100644 --- a/src/bat_publishers.cc +++ b/src/bat_publishers.cc @@ -864,8 +864,8 @@ void BatPublishers::getPublisherActivityFromUrl(uint64_t windowId, const ledger: type = TWITCH_MEDIA_TYPE; } - // TODO NZ add logic - // ledger_->GetMediaActivityFromUrl(windowId, (std::string)visit_data.domain + visit_data.path, type, month, year); + ledger_->GetMediaActivityFromUrl( + windowId, visit_data, type); return; } diff --git a/src/ledger_impl.cc b/src/ledger_impl.cc index 25ae737a3d2a..42b0716e2847 100644 --- a/src/ledger_impl.cc +++ b/src/ledger_impl.cc @@ -327,7 +327,8 @@ void LedgerImpl::GetPublisherInfo( } void LedgerImpl::GetMediaPublisherInfo(const std::string& media_key, - ledger::PublisherInfoCallback callback) { + ledger::PublisherInfoCallback callback, + bool use_as_publisher_key) { ledger_client_->LoadMediaPublisherInfo(media_key, callback); } @@ -758,11 +759,10 @@ void LedgerImpl::GetPublisherActivityFromUrl(uint64_t windowId, } void LedgerImpl::GetMediaActivityFromUrl(uint64_t windowId, - const std::string& providerType, - const std::string& url, - ledger::PUBLISHER_MONTH month, - int year) { - bat_get_media_->getMediaActivityFromUrl(windowId, url, providerType, month, year); + const ledger::VisitData& visit_data, + const std::string& providerType) { + bat_get_media_->getMediaActivityFromUrl( + windowId, visit_data, providerType); } void LedgerImpl::OnPublisherActivity(ledger::Result result, diff --git a/src/ledger_impl.h b/src/ledger_impl.h index 1aa46c3c343d..b1f230fad6e3 100644 --- a/src/ledger_impl.h +++ b/src/ledger_impl.h @@ -52,7 +52,8 @@ class LedgerImpl : public ledger::Ledger, void GetPublisherInfo(const ledger::PublisherInfoFilter& filter, ledger::PublisherInfoCallback callback) override; void GetMediaPublisherInfo(const std::string& media_key, - ledger::PublisherInfoCallback callback) override; + ledger::PublisherInfoCallback callback, + bool use_as_publisher_key = false) override; void SetMediaPublisherInfo(const std::string& media_key, const std::string& publisher_id) override; std::vector GetRecurringDonationPublisherInfo() override; @@ -149,10 +150,8 @@ class LedgerImpl : public ledger::Ledger, bool IsWalletCreated() const override; void GetPublisherActivityFromUrl(uint64_t windowId, const ledger::VisitData& visit_data) override; void GetMediaActivityFromUrl(uint64_t windowId, - const std::string& url, - const std::string& providerType, - ledger::PUBLISHER_MONTH month, - int year); + const ledger::VisitData& visit_data, + const std::string& providerType); void OnPublisherActivity(ledger::Result result, std::unique_ptr info, uint64_t windowId); diff --git a/src/static_values.h b/src/static_values.h index c34e8c6e50d0..2bea0cb02a97 100644 --- a/src/static_values.h +++ b/src/static_values.h @@ -53,7 +53,7 @@ #define YOUTUBE_PROVIDER_URL "https://www.youtube.com/oembed" #define TWITCH_PROVIDER_URL "https://api.twitch.tv/v5/oembed" #define YOUTUBE_TLD "youtube.com" -#define TWITCH_TLD "twitch.com" +#define TWITCH_TLD "twitch.tv" #define TWITCH_VOD_URL "https://www.twitch.tv/videos/" #define MEDIA_DELIMITER '_' #define WALLET_PASSPHRASE_DELIM ' '