Skip to content

Commit

Permalink
Merge pull request #2247 from brave/vimeo
Browse files Browse the repository at this point in the history
Adds support for Vimeo
  • Loading branch information
NejcZdovc authored Jun 25, 2019
2 parents 0b474a3 + 3fa6bbd commit ef87c6d
Show file tree
Hide file tree
Showing 25 changed files with 1,328 additions and 62 deletions.
1 change: 1 addition & 0 deletions browser/brave_rewards/rewards_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void RewardsTabHelper::ResourceLoadComplete(
if (!rewards_service_ || !render_frame_host)
return;

// TODO(nejczdovc): do we need to get anyother type then XHR??
if (resource_load_info.resource_type == content::ResourceType::kMedia ||
resource_load_info.resource_type == content::ResourceType::kXhr ||
resource_load_info.resource_type == content::ResourceType::kImage ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "bat/ledger/media_publisher_info.h"
#include "bat/ledger/media_event_info.h"
#include "bat/ledger/pending_contribution.h"
#include "build/build_config.h"
#include "sql/meta_table.h"
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "bat/ledger/ledger.h"
#include "bat/ledger/auto_contribute_props.h"
#include "bat/ledger/media_publisher_info.h"
#include "bat/ledger/media_event_info.h"
#include "bat/ledger/publisher_info.h"
#include "bat/ledger/wallet_properties.h"
#include "bat/ledger/transactions_info.h"
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ test("brave_unit_tests") {
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/reddit_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/twitch_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/twitter_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/vimeo_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/youtube_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper_unittest.h",
Expand Down
4 changes: 3 additions & 1 deletion vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ source_set("headers") {
"include/bat/ledger/ledger.h",
"include/bat/ledger/ledger_callback_handler.h",
"include/bat/ledger/ledger_client.h",
"include/bat/ledger/media_publisher_info.h",
"include/bat/ledger/media_event_info.h",
"include/bat/ledger/pending_contribution.h",
"include/bat/ledger/publisher_info.h",
"include/bat/ledger/reconcile_info.h",
Expand Down Expand Up @@ -123,6 +123,8 @@ source_set("ledger") {
"src/bat/ledger/internal/media/twitch.cc",
"src/bat/ledger/internal/media/twitter.h",
"src/bat/ledger/internal/media/twitter.cc",
"src/bat/ledger/internal/media/vimeo.h",
"src/bat/ledger/internal/media/vimeo.cc",
"src/bat/ledger/internal/media/youtube.h",
"src/bat/ledger/internal/media/youtube.cc",
"src/bat/ledger/internal/wallet/balance.h",
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ledger/include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "bat/ledger/balance.h"
#include "bat/ledger/ledger_client.h"
#include "bat/ledger/publisher_info.h"
#include "bat/ledger/media_publisher_info.h"
#include "bat/ledger/media_event_info.h"
#include "bat/ledger/transactions_info.h"
#include "bat/ledger/rewards_internals_info.h"
#include "bat/ledger/pending_contribution.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "bat/ledger/export.h"
#include "bat/ledger/grant.h"
#include "bat/ledger/ledger_callback_handler.h"
#include "bat/ledger/media_publisher_info.h"
#include "bat/ledger/media_event_info.h"
#include "bat/ledger/pending_contribution.h"
#include "bat/ledger/publisher_info.h"
#include "bat/ledger/reconcile_info.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BAT_LEDGER_MEDIA_PUBLISHER_INFO_HANDLER_
#define BAT_LEDGER_MEDIA_PUBLISHER_INFO_HANDLER_
#ifndef BAT_LEDGER_MEDIA_EVENT_INFO_H_
#define BAT_LEDGER_MEDIA_EVENT_INFO_H_

#include <string>

Expand All @@ -13,10 +13,10 @@

namespace ledger {

LEDGER_EXPORT struct TwitchEventInfo {
TwitchEventInfo();
TwitchEventInfo(const TwitchEventInfo&);
~TwitchEventInfo();
LEDGER_EXPORT struct MediaEventInfo {
MediaEventInfo();
MediaEventInfo(const MediaEventInfo&);
~MediaEventInfo();

std::string event_;
std::string time_;
Expand All @@ -25,4 +25,4 @@ LEDGER_EXPORT struct TwitchEventInfo {

} // namespace ledger

#endif // BAT_LEDGER_MEDIA_PUBLISHER_INFO_HANDLER_
#endif // BAT_LEDGER_MEDIA_EVENT_INFO_H_
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ std::string getProviderName(const std::string& publisher_id) {
return TWITCH_MEDIA_TYPE;
} else if (publisher_id.find(TWITTER_MEDIA_TYPE) != std::string::npos) {
return TWITTER_MEDIA_TYPE;
} else if (publisher_id.find(VIMEO_MEDIA_TYPE) != std::string::npos) {
return VIMEO_MEDIA_TYPE;
}

return "";
}

Expand Down Expand Up @@ -708,7 +711,8 @@ void BatPublishers::getPublisherActivityFromUrl(
const bool is_media = visit_data.domain == YOUTUBE_TLD ||
visit_data.domain == TWITCH_TLD ||
visit_data.domain == TWITTER_TLD ||
visit_data.domain == REDDIT_TLD;
visit_data.domain == REDDIT_TLD ||
visit_data.domain == VIMEO_TLD;

if (is_media &&
visit_data.path != "" && visit_data.path != "/") {
Expand All @@ -719,6 +723,8 @@ void BatPublishers::getPublisherActivityFromUrl(
type = TWITTER_MEDIA_TYPE;
} else if (visit_data.domain == REDDIT_TLD) {
type = REDDIT_MEDIA_TYPE;
} else if (visit_data.domain == VIMEO_TLD) {
type = VIMEO_MEDIA_TYPE;
}

ledger::VisitDataPtr new_visit_data = ledger::VisitData::New(visit_data);
Expand Down
15 changes: 13 additions & 2 deletions vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,23 @@ void LedgerImpl::OnPostData(
return;
}

std::vector<std::map<std::string, std::string>> twitchParts;
if (TWITCH_MEDIA_TYPE == type) {
if (type == TWITCH_MEDIA_TYPE) {
std::vector<std::map<std::string, std::string>> twitchParts;
braveledger_media::GetTwitchParts(post_data, &twitchParts);
for (size_t i = 0; i < twitchParts.size(); i++) {
bat_media_->ProcessMedia(twitchParts[i], type, std::move(visit_data));
}
return;
}

if (type == VIMEO_MEDIA_TYPE) {
std::vector<std::map<std::string, std::string>> parts;
braveledger_media::GetVimeoParts(post_data, &parts);

for (auto part = parts.begin(); part != parts.end(); part++) {
bat_media_->ProcessMedia(*part, type, std::move(visit_data));
}
return;
}
}

Expand Down
37 changes: 37 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/internal/media/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "base/json/json_reader.h"
#include "bat/ledger/internal/media/helper.h"
#include "bat/ledger/internal/bat_helper.h"

Expand Down Expand Up @@ -68,4 +69,40 @@ std::string ExtractData(const std::string& data,
return match;
}

void GetVimeoParts(
const std::string& query,
std::vector<std::map<std::string, std::string>>* parts) {
base::Optional<base::Value> data = base::JSONReader::Read(query);
if (!data || !data->is_list()) {
return;
}

for (const auto& item : data->GetList()) {
if (item.is_dict()) {
std::map<std::string, std::string> part;
auto* name = item.FindKey("name");
if (name) {
part.emplace("event", name->GetString());
}

auto* clip_id = item.FindKey("clip_id");
if (clip_id) {
part.emplace("video_id", std::to_string(clip_id->GetInt()));
}

auto* product = item.FindKey("product");
if (product) {
part.emplace("type", product->GetString());
}

auto* video_time = item.FindKey("video_time");
if (video_time) {
part.emplace("time", std::to_string(video_time->GetDouble()));
}

parts->push_back(part);
}
}
}

} // namespace braveledger_media
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ std::string ExtractData(const std::string& data,
const std::string& match_after,
const std::string& match_until);

void GetVimeoParts(const std::string& query,
std::vector<std::map<std::string, std::string>>* parts);

} // namespace braveledger_media

#endif // BRAVELEDGER_MEDIA_HELPER_H_
51 changes: 35 additions & 16 deletions vendor/bat-native-ledger/src/bat/ledger/internal/media/media.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Media::Media(bat_ledger::LedgerImpl* ledger):
media_youtube_(new braveledger_media::YouTube(ledger)),
media_twitch_(new braveledger_media::Twitch(ledger)),
media_twitter_(new braveledger_media::Twitter(ledger)),
media_reddit_(new braveledger_media::Reddit(ledger)) {
media_reddit_(new braveledger_media::Reddit(ledger)),
media_vimeo_(new braveledger_media::Vimeo(ledger)) {
}

Media::~Media() {}
Expand All @@ -36,6 +37,9 @@ std::string Media::GetLinkType(const std::string& url,
first_party_url,
referrer);
}
if (type.empty()) {
type = braveledger_media::Vimeo::GetLinkType(url);
}

return type;
}
Expand All @@ -56,6 +60,11 @@ void Media::ProcessMedia(const std::map<std::string, std::string>& parts,
media_twitch_->ProcessMedia(parts, *visit_data);
return;
}

if (type == VIMEO_MEDIA_TYPE) {
media_vimeo_->ProcessMedia(parts);
return;
}
}

void Media::GetMediaActivityFromUrl(
Expand All @@ -74,6 +83,8 @@ void Media::GetMediaActivityFromUrl(
*visit_data);
} else if (type == REDDIT_MEDIA_TYPE) {
media_reddit_->ProcessActivityFromUrl(window_id, *visit_data);
} else if (type == VIMEO_MEDIA_TYPE) {
media_vimeo_->ProcessActivityFromUrl(window_id, *visit_data);
} else {
OnMediaActivityError(std::move(visit_data), type, window_id);
}
Expand All @@ -90,23 +101,30 @@ void Media::OnMediaActivityError(ledger::VisitDataPtr visit_data,
} else if (type == TWITCH_MEDIA_TYPE) {
url = TWITCH_TLD;
name = TWITCH_MEDIA_TYPE;
} else if (type == TWITTER_MEDIA_TYPE) {
url = TWITTER_TLD;
name = TWITTER_MEDIA_TYPE;
} else if (type == REDDIT_MEDIA_TYPE) {
url = REDDIT_TLD;
name = REDDIT_MEDIA_TYPE;
} else if (type == VIMEO_MEDIA_TYPE) {
url = VIMEO_TLD;
name = VIMEO_MEDIA_TYPE;
}

if (!url.empty()) {
visit_data->domain = url;
visit_data->url = "https://" + url;
visit_data->path = "/";
visit_data->name = name;

ledger_->GetPublisherActivityFromUrl(
window_id, std::move(visit_data), std::string());
} else {
BLOG(ledger_, ledger::LogLevel::LOG_ERROR)
<< "Media activity error for "
<< type << " (name: "
<< name << ", url: "
<< visit_data->url << ")";
if (url.empty()) {
BLOG(ledger_, ledger::LogLevel::LOG_ERROR)
<< "Media activity error for url: "
<< visit_data->url;
return;
}

visit_data->domain = url;
visit_data->url = "https://" + url;
visit_data->path = "/";
visit_data->name = name;

ledger_->GetPublisherActivityFromUrl(window_id, std::move(visit_data), "");
}

void Media::SaveMediaInfo(const std::string& type,
Expand All @@ -125,8 +143,9 @@ void Media::SaveMediaInfo(const std::string& type,
std::string Media::GetShareURL(
const std::string& type,
const std::map<std::string, std::string>& args) {
if (type == TWITTER_MEDIA_TYPE)
if (type == TWITTER_MEDIA_TYPE) {
return braveledger_media::Twitter::GetShareURL(args);
}

return std::string();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "bat/ledger/internal/media/reddit.h"
#include "bat/ledger/internal/media/twitch.h"
#include "bat/ledger/internal/media/twitter.h"
#include "bat/ledger/internal/media/vimeo.h"
#include "bat/ledger/internal/media/youtube.h"
#include "bat/ledger/ledger.h"

Expand Down Expand Up @@ -60,6 +61,7 @@ class Media {
std::unique_ptr<braveledger_media::Twitch> media_twitch_;
std::unique_ptr<braveledger_media::Twitter> media_twitter_;
std::unique_ptr<braveledger_media::Reddit> media_reddit_;
std::unique_ptr<braveledger_media::Vimeo> media_vimeo_;
};

} // namespace braveledger_media
Expand Down
Loading

0 comments on commit ef87c6d

Please sign in to comment.