Created
February 11, 2013 21:27
-
-
Save thepeopleseason/4757787 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
def brightcove_share(self, sitelist=[]): | |
""" | |
make an API call to brightcove to share this particular | |
video to the listed sites | |
""" | |
if self.shareable: | |
account_ids = [ | |
setting.db_value for setting in Setting.objects.filter( | |
name='brightcove_account_id', | |
site__in=sitelist)] | |
sitesettings = Setting.cached_dict(site_id=self.originating_site.pk) | |
read_token = sitesettings.get('brightcove_api_read_key') | |
write_token = sitesettings.get('brightcove_api_write_key') | |
# check if video is from 3rd party alternate account | |
if not str(sitesettings.get('brightcove_large')) in self.player_url: | |
accountlist = [] | |
accounts = sitesettings.get('brightcove_multiple_accounts') | |
if accounts: | |
accountlist.extend(json.loads(accounts)) | |
for tsettings in accountlist: | |
if str(tsettings.get('brightcove_large')) in self.player_url: | |
read_token = tsettings.get('brightcove_api_read_key') | |
write_token = tsettings.get('brightcove_api_write_key') | |
break | |
bc_connection = APIConnection(read_token=read_token, | |
write_token=write_token) | |
try: | |
bcvideo = BCVideo( | |
id=self.brightcove_video_id, | |
_connection=bc_connection | |
) | |
bcvideo.tags.append(PREVIOUSLY_SHARED_TAG) | |
bcvideo.save() | |
bcvideo.share(accounts=account_ids) | |
return True, None | |
except Exception, e: | |
return False, 'Failure sharing "%s": %s' % (self.title, e) | |
return False, '"%s" is not shareable' % (self.title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment