Created
March 20, 2017 11:13
-
-
Save assembler/3be68acdfa6e04d015e84572d9c7944a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "bundler" | |
Bundler.require | |
require "statfire/youtube" | |
require "pp" | |
require "uri" | |
require "google/apis/youtube_partner_v1" | |
StatFire::YouTube.configure do |config| | |
config.application_name = "StatFire YouTube" | |
config.application_version = "1.0" | |
config.client_id = "XXX" | |
config.client_secret = "XXX" | |
config.refresh_token = "XXX" | |
end | |
$partnerapi = Google::Apis::YoutubePartnerV1::YouTubePartnerService.new | |
CONTENT_OWNER = "8Lhf__cNjH6v8ahOGqC4Lw" | |
def get_content_owner_name(owner_id) | |
owner = $partnerapi.get_content_owner(owner_id, on_behalf_of_content_owner: "8Lhf__cNjH6v8ahOGqC4Lw") | |
owner.display_name | |
end | |
def api_attribution_for(video_id) | |
claims = $partnerapi.list_claim_searches(video_id: video_id, on_behalf_of_content_owner: CONTENT_OWNER) | |
return nil if claims.items.nil? || claims.items.empty? | |
asset_id = claims.items[0].asset_id | |
ownership_histories = $partnerapi.list_ownership_histories(asset_id, on_behalf_of_content_owner: CONTENT_OWNER) | |
return nil if ownership_histories.items.nil? || ownership_histories.items.empty? | |
ownership_histories.items[0].origination.owner | |
end | |
def web_attribution_for(video_id) | |
determiner = StatFire::YouTube::VideoAttributionDeterminer.new | |
determiner.determine(video_id) | |
end | |
#-----------------------------------------------------------------# | |
channel_ids = %w[ | |
UC-0JYzAIIXy0hsEqjK_Vqug | |
UC-0UnUZBEJHAKucJeQPsDnw | |
UC-0begwKR-zO6IrPK-tlwuw | |
UC-0vWYVb2xVdEdddHYAfqLw | |
UC-12FSbsZsMXsYlyv0jd0MA | |
UC-2DUgI6tX_L0kFTJ523OEw | |
] | |
channel_service = StatFire::YouTube::RealChannelService.new | |
channel_ids.each do |channel_id| | |
print "Channel: #{channel_id}" | |
video_ids = channel_service.get_channel_recent_video_ids(channel_id, limit: 10) | |
web_attributions = video_ids.map { |video_id| web_attribution_for(video_id) }.compact | |
web_network_id = web_attributions.uniq.max_by { |a| web_attributions.count(a) } | |
api_attributions = video_ids.map { |video_id| api_attribution_for(video_id) }.compact | |
api_network_id = api_attributions.uniq.max_by { |a| api_attributions.count(a) } | |
web_network = web_network_id && get_content_owner_name(web_network_id) | |
api_network = api_network_id && get_content_owner_name(api_network_id) | |
status = web_network == api_network ? "(good)" : "(wrng)" | |
print " #{status} #{web_network} vs #{api_network}\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment