def __init__(self, token=''): if token: self.token = token if not self.token: self.token = getattr(settings, 'BRIGHTCOVE_TOKEN', None) self.connector = Brightcove(self.token)
def get_videos(url): '''For a given topic url, returns a list of associated videos from the Brightcove API. ''' ref_id = url.split('/')[-2] brightcove = Brightcove(TOKEN) playlist = brightcove.find_playlist_by_reference_id(ref_id) return playlist.videos
class BrightcoveApi(): """Class managing communication with the Brightcove API though the brightcove app.""" token = '' connector = None def __init__(self, token=''): if token: self.token = token if not self.token: self.token = getattr(settings, 'BRIGHTCOVE_TOKEN', None) self.connector = Brightcove(self.token) def get_by_id(self, brightcove_id): video = self.connector.find_video_by_id(brightcove_id) if video: return self._save_item(video) return None def _get_list(self): return self.connector.find_all_videos() def synchronize_list(self): """Synchronizes the list of videos form a brightcove account with the BrightcoveItem model.""" items = self._get_list() existing_ids = [] for item in items.items: self._save_item(item) existing_ids.append(item.id) BrightcoveItems.objects.exclude( brightcove_id__in=existing_ids).delete() def _save_item(self, item): brightcove_item, created = BrightcoveItems.objects.get_or_create( brightcove_id=item.id) brightcove_item.name = item.name brightcove_item.video_still_URL = item.videoStillURL brightcove_item.thumbnail_URL = item.thumbnailURL brightcove_item.short_description = item.shortDescription brightcove_item.long_description = item.longDescription brightcove_item.length = item.length brightcove_item.link_URL = item.linkURL brightcove_item.plays_total = item.playsTotal brightcove_item.creation_date = item.creationDate brightcove_item.published_date = item.publishedDate brightcove_item.save() return brightcove_item
class BrightcoveApi(): """Class managing communication with the Brightcove API though the brightcove app.""" token = '' connector = None def __init__(self, token=''): if token: self.token = token if not self.token: self.token = getattr(settings, 'BRIGHTCOVE_TOKEN', None) self.connector = Brightcove(self.token) def get_by_id(self, brightcove_id): video = self.connector.find_video_by_id(brightcove_id) if video: return self._save_item(video) return None def _get_list(self): return self.connector.find_all_videos() def synchronize_list(self): """Synchronizes the list of videos form a brightcove account with the BrightcoveItem model.""" items = self._get_list() existing_ids = [] for item in items.items: self._save_item(item) existing_ids.append(item.id) BrightcoveItems.objects.exclude(brightcove_id__in=existing_ids).delete() def _save_item(self, item): brightcove_item, created = BrightcoveItems.objects.get_or_create(brightcove_id=item.id) brightcove_item.name = item.name brightcove_item.video_still_URL = item.videoStillURL brightcove_item.thumbnail_URL = item.thumbnailURL brightcove_item.short_description = item.shortDescription brightcove_item.long_description = item.longDescription brightcove_item.length = item.length brightcove_item.link_URL = item.linkURL brightcove_item.plays_total = item.playsTotal brightcove_item.creation_date = item.creationDate brightcove_item.published_date = item.publishedDate brightcove_item.save() return brightcove_item
def __init__(self, caching_decorator=None): self.brightcove = Brightcove(API_TOKEN) if caching_decorator: self._request = caching_decorator(self._request) # preload data self.mobile_data = json.loads(self._request(MOBILEDATA_URL)) try: self.fan_art_bootstarp = json.loads( self._request(FANART_BOOTSTRAP_URL)) except Exception, e: pass
def setUp(self): TOKEN = 'cE97ArV7TzqBzkmeRVVhJ8O6GWME2iG_bRvjBTlNb4o.' TOKEN = 'foobar' self.b = Brightcove(TOKEN) self.b._orig_read_conn = self.b.read_conn self.b.read_conn._request = _request
def test_init(self): b = Brightcove('xxx') self.assertEqual(b.token, 'xxx')
def play(videoId): api_token = get_api_token() brightcove = Brightcove(api_token) video = brightcove.find_video_by_id(videoId, media_delivery='http') plugin.set_resolved_url(video.videoFullLength['url'])