示例#1
0
    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)
示例#2
0
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
示例#3
0
    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)
示例#4
0
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
示例#5
0
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
示例#6
0
    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
示例#7
0
 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
示例#8
0
文件: test_api.py 项目: yogi81/ru
 def test_init(self):
     b = Brightcove('xxx')
     self.assertEqual(b.token, 'xxx')
示例#9
0
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'])