Esempio n. 1
0
 def share(self, accounts):
     """
     Create a share
     """
     if not isinstance(accounts, (list, tuple)):
         msg = "Video.share expects an iterable argument"
         raise exceptions.PyBrightcoveError(msg)
     raise exceptions.PyBrightcoveError("Not yet implemented")
Esempio n. 2
0
 def find_by_tags(and_tags=None, or_tags=None, _connection=None,
     page_size=100, page_number=0, sort_by=enums.DEFAULT_SORT_BY,
     sort_order=enums.DEFAULT_SORT_ORDER):
     """
     List videos given a certain set of tags.
     """
     err = None
     if not and_tags and not or_tags:
         err = "You must supply at least one of either and_tags or or_tags."
     if and_tags and not isinstance(and_tags, (tuple, list)):
         err = "The and_tags argument for Video.find_by_tags must an "
         err += "iterable"
     if or_tags and not isinstance(or_tags, (tuple, list)):
         err = "The or_tags argument for Video.find_by_tags must an "
         err += "iterable"
     if err:
         raise exceptions.PyBrightcoveError(err)
     atags = None
     otags = None
     if and_tags:
         atags = ','.join([str(t) for t in and_tags])
     if or_tags:
         otags = ','.join([str(t) for t in or_tags])
     return connection.ItemResultSet('find_videos_by_tags',
         Video, _connection, page_size, page_number, sort_by, sort_order,
         and_tags=atags, or_tags=otags)
Esempio n. 3
0
 def find_modified(since,
                   filter_list=None,
                   _connection=None,
                   page_size=25,
                   page_number=0,
                   sort_by=enums.DEFAULT_SORT_BY,
                   sort_order=enums.DEFAULT_SORT_ORDER):
     """
     List all videos modified since a certain date.
     """
     filters = []
     if filter_list is not None:
         filters = filter_list
     if not isinstance(since, datetime):
         msg = 'The parameter "since" must be a datetime object.'
         raise exceptions.PyBrightcoveError(msg)
     fdate = int(since.strftime("%s")) / 60  ## Minutes since UNIX time
     return connection.ItemResultSet('find_modified_videos',
                                     Video,
                                     _connection,
                                     page_size,
                                     page_number,
                                     sort_by,
                                     sort_order,
                                     from_date=fdate,
                                     filter=filters)
Esempio n. 4
0
    def __setattr__(self, name, value):
        msg = None
        if value:
            if name == 'name' and len(value) > 255:
                msg = "Video.name must be 255 characters or less."
            if name == 'reference_id' and len(value) > 150:
                # val = value[:150]
                msg = "Video.reference_id must be 150 characters or less."
            if name == 'long_description' and len(value) > 5000:
                # val = value[:5000]
                msg = "Video.long_description must be 5000 characters or less."
            if name == 'short_description' and len(value) > 250:
                # val = value[:250]
                msg = "Video.short_description must be 250 characters or less."
            if name == 'item_state' and value not in (
                    enums.ItemStateEnum.ACTIVE,
                    enums.ItemStateEnum.INACTIVE):
                msg = "Video.item_state must be either ItemStateEnum.ACTIVE or"
                msg += " ItemStateEnum.INACTIVE"
            if name == 'video_full_length' and \
                    not isinstance(value, Rendition):
                msg = "Video.video_full_length must be of type Rendition"
            if name == 'economics' and value not in \
                    (enums.EconomicsEnum.FREE,
                     enums.EconomicsEnum.AD_SUPPORTED):
                msg = "Video.economics must be either EconomicsEnum.FREE or "
                msg += "EconomicsEnum.AD_SUPPORTED"

            if msg:
                raise exceptions.PyBrightcoveError(msg)
        return super(Video, self).__setattr__(name, value)
Esempio n. 5
0
 def find_by_ids(ids,
                 _connection=None,
                 page_size=100,
                 page_number=0,
                 sort_by=enums.DEFAULT_SORT_BY,
                 sort_order=enums.DEFAULT_SORT_ORDER,
                 **kwargs):
     """
     List all videos identified by a list of Brightcove video ids
     """
     if not isinstance(ids, (list, tuple)):
         err = "Video.find_by_ids expects an iterable argument"
         raise exceptions.PyBrightcoveError(err)
     ids = ','.join([str(i) for i in ids])
     apicall = 'find_videos_by_ids'
     if kwargs.get('unfiltered'):
         apicall = 'find_videos_by_ids_unfiltered'
     kwargs = Video.ensure_essential_fields(**kwargs)
     return connection.ItemResultSet(apicall,
                                     Video,
                                     _connection,
                                     page_size,
                                     page_number,
                                     sort_by,
                                     sort_order,
                                     video_ids=ids,
                                     **kwargs)
Esempio n. 6
0
    def find_modified(since,
                      filter_list=None,
                      _connection=None,
                      page_size=25,
                      page_number=0,
                      sort_by=enums.DEFAULT_SORT_BY,
                      sort_order=enums.DEFAULT_SORT_ORDER,
                      **kwargs):
        """
        List all videos modified since a certain date.
        """
        filters = []
        if filter_list is not None:
            filters = filter_list
        if isinstance(since, datetime):
            fdate = int(since.strftime("%s")) / 60  # Minutes since UNIX time
        elif since == 0:
            fdate = '0'  # This should be a string, otherwise kwargs
            # thinks it's not existent
        else:
            msg = 'The parameter "since" must be a datetime object.'
            raise exceptions.PyBrightcoveError(msg)

        kwargs = Video.ensure_essential_fields(**kwargs)
        return connection.ItemResultSet('find_modified_videos',
                                        Video,
                                        _connection,
                                        page_size,
                                        page_number,
                                        sort_by,
                                        sort_order,
                                        from_date=fdate,
                                        filter=filters,
                                        **kwargs)
Esempio n. 7
0
 def find_by_ids(ids, _connection=None, page_size=100, page_number=0,
     sort_by=enums.DEFAULT_SORT_BY, sort_order=enums.DEFAULT_SORT_ORDER):
     """
     List all videos identified by a list of Brightcove video ids
     """
     try:
         ids = ','.join([str(i) for i in ids])
     except TypeError, exc:
         err = "Video.find_by_ids expects an iterable argument"
         raise exceptions.PyBrightcoveError(err)
Esempio n. 8
0
 def find_by_ids(ids, _connection=None, page_size=100, page_number=0,
     sort_by=enums.DEFAULT_SORT_BY, sort_order=enums.DEFAULT_SORT_ORDER):
     """
     List all videos identified by a list of Brightcove video ids
     """
     if not isinstance(ids, (list, tuple)):
         err = "Video.find_by_ids expects an iterable argument"
         raise exceptions.PyBrightcoveError(err)
     ids = ','.join([str(i) for i in ids])
     return connection.ItemResultSet('find_videos_by_ids',
         Video, _connection, page_size, page_number, sort_by, sort_order,
         video_ids=ids)
Esempio n. 9
0
 def share(self, accounts):
     """
     Create a share
     """
     if not isinstance(accounts, (list, tuple)):
         msg = "Video.share expects an iterable argument"
         raise exceptions.PyBrightcoveError(msg)
     if len(accounts) > 0:
         if self.get_upload_status() == enums.UploadStatusEnum.COMPLETE:
             return self.connection.post('share_video',
                                         video_id=self.id,
                                         auto_accept=True,
                                         sharee_account_ids=accounts)
         else:
             raise exceptions.VideoStatusNotComplete
Esempio n. 10
0
    def __setattr__(self, name, value):
        msg = None
        if value:
            if name == 'video_duration' and not isinstance(value, (int, long)):
                msg = "Rendition.video_duration must be the duration in "
                msg += "milliseconds as an integer or long."
            if name == 'size' and not isinstance(value, (int, long)):
                msg = "Rendition.size must be the number of bytes as an "
                msg += "integer or long."
            if name == 'video_codec' and \
                    value not in (enums.VideoCodecEnum.SORENSON,
                                  enums.VideoCodecEnum.ON2,
                                  enums.VideoCodecEnum.H264):
                msg = "Rendition.video_codec must be SORENSON, ON2, or H264."

            if msg:
                raise exceptions.PyBrightcoveError(msg)
        return super(Rendition, self).__setattr__(name, value)
Esempio n. 11
0
    def get_status(video_id=None, reference_id=None, _connection=None):
        """
        Get the status of a video given the ``video_id`` parameter.
        """

        args = {}

        if video_id:
            args = {'video_id': video_id}
        elif reference_id:
            args = {'reference_id': reference_id}
        else:
            msg = 'get_status needs either a video_id or a reference_id'
            raise exceptions.PyBrightcoveError(msg)

        c = _connection
        if not c:
            c = connection.APIConnection()

        return c.post('get_upload_status', **args)
Esempio n. 12
0
 def search_videos(all=None,
                   any=None,
                   none=None,
                   _connection=None,
                   page_size=100,
                   page_number=0,
                   sort_by=enums.DEFAULT_SORT_BY,
                   sort_order=enums.DEFAULT_SORT_ORDER):
     """
     List videos given a certain set criteria.
     """
     err = None
     if not all and not any and not none:
         err = "You must supply at least one of either all or and or none parameters."
     if all and not isinstance(all, (tuple, list)):
         err = "The all argument for Video.search_videos must an "
         err += "iterable"
     if any and not isinstance(any, (tuple, list)):
         err = "The any argument for Video.search_videos must an "
         err += "iterable"
     if err:
         raise exceptions.PyBrightcoveError(err)
     allstr = None
     anystr = None
     nonestr = None
     if all:
         allstr = '&all='.join([str(t) for t in all])
     if any:
         anystr = '&any='.join([str(t) for t in any])
     if none:
         nonestr = '&none='.join([str(t) for t in none])
     return connection.ItemResultSet('search_videos',
                                     Video,
                                     _connection,
                                     page_size,
                                     page_number,
                                     sort_by,
                                     sort_order,
                                     all=allstr,
                                     any=anystr,
                                     none=nonestr)
Esempio n. 13
0
    def __init__(self, filename=None, name=None, short_description=None,
        id=None, reference_id=None, renditions=None, data=None,
        _connection=None):

        self._filename = None
        self.name = None
        self.short_description = None
        self.id = None
        self.reference_id = None
        self.accountId = None
        self.long_description = None
        self.flv_url = None
        self.renditions = []
        self.assets = []
        self.metadata = []
        self.video_full_length = None
        self.creation_date = None
        self.published_date = None
        self.last_modified_date = None
        self.item_state = None
        self.start_date = None
        self.end_date = None
        self.link_url = None
        self.link_text = None
        self.tags = []
        self.video_still_url = None
        self.thumbnail_url = None
        self.length = None
        self.economics = None
        self.geo_filtered = None
        self.geo_filtered_countries = None
        self.geo_filtered_exclude = None
        self.cue_points = None
        self.plays_total = None
        self.plays_trailing_week = None

        self.image = None
        self.raw_data = None

        self.connection = _connection
        if not self.connection:
            self.connection = connection.APIConnection()

        if is_ftp_connection(self.connection):
            if reference_id and name and short_description:
                self.reference_id = reference_id
                self.name = name
                self.short_description = short_description
            else:
                msg = "Invalid parameters for Video."
                raise exceptions.PyBrightcoveError(msg)
        else:
            if ((renditions and len(renditions) > 0) or filename) and name \
                and short_description:
                if filename is not None:
                    self._filename = filename
                if renditions is not None:
                    self.renditions = renditions
                self.name = name
                self.short_description = short_description
            elif id or reference_id:
                self.id = id
                self.reference_id = reference_id
                self._find_video()
            elif data:
                self._load(data)
            else:
                msg = "Invalid parameters for Video."
                raise exceptions.PyBrightcoveError(msg)