Permalink
Browse files

finished remaining video read APIs

  • Loading branch information...
1 parent 90527c2 commit 70eb5feba4394f4307ad6e8af2cd2e6e613d6e16 Patrick Altman committed Mar 22, 2009
Showing with 248 additions and 41 deletions.
  1. +7 −7 TODO
  2. +241 −34 pybrightcove/connection.py
View
14 TODO
@@ -10,13 +10,13 @@
[*] Implement find_all_videos
[*] Implement find_video_by_id
-[ ] Implement find_related_videos
-[ ] Implement find_videos_by_reference_id
-[ ] Implement find_videos_by_reference_ids
-[ ] Implement find_videos_by_user_id
-[ ] Implement find_videos_by_campaign_id
-[ ] Implement find_videos_by_text
-[* ] Implement find_videos_by_tags
+[*] Implement find_related_videos
+[*] Implement find_videos_by_reference_id
+[*] Implement find_videos_by_reference_ids
+[*] Implement find_videos_by_user_id
+[*] Implement find_videos_by_campaign_id
+[*] Implement find_videos_by_text
+[*] Implement find_videos_by_tags
## Playlist Read APIs
View
@@ -65,7 +65,10 @@ def _get_response(self, **kwargs):
url = self.read_url + "?output=JSON&token=%s" % self.read_token
for key in kwargs:
if key and kwargs[key]:
- url += "&%s=%s" % (key, kwargs[key])
+ val = kwargs[key]
+ if isinstance(val, (list, tuple)):
+ val = ",".join(val)
+ url += "&%s=%s" % (key, val)
req = urllib2.urlopen(url)
return simplejson.loads(req.read())
@@ -88,20 +91,11 @@ def _base_get_command(self, command, page_size=100, page_number=0,
return Video(data=data)
return ItemCollection(data=data, collection_type="Video")
- def find_videos_by_tags(self, and_tags=None, or_tags=None, page_size=100,
- page_number=0, sort_by=SortByType.MODIFIED_DATE,
- sort_order=SortByOrderType.ASC, get_item_count=True, fields=None):
+ def find_all_videos(self, page_size=100, page_number=0,
+ sort_by=SortByType.CREATION_DATE, sort_order=SortByOrderType.ASC,
+ fields=None, get_item_count=True):
"""
- Performs a search on all the tags of the videos in this account,
- and returns a collection of videos that contain the specified tags.
-
- Note that tags are case-sensitive.
-
- and_tags:
- Limit the results to those that contain all of these tags.
-
- or_tags
- Limit the results to those that contain at least one of these tags.
+ Find all videos in the Brightcove media library for this account.
page_size:
Integer Number of items returned per page. A page is a subset of
@@ -129,20 +123,124 @@ def find_videos_by_tags(self, and_tags=None, or_tags=None, page_size=100,
get_item_count:
If set to True, return a total_count value with the payload.
"""
- if sort_by not in (SortByType.MODIFIED_DATE,
- SortByType.PLAYS_TRAILING_WEEK):
- raise Exception("Invalid sort by type.")
-
- return self._base_get_command(command="find_videos_by_tags",
+ return self._base_get_command(command="find_all_videos",
page_size=page_size, page_number=page_number, sort_by=sort_by,
sort_order=sort_order, fields=fields,
- get_item_count=get_item_count, and_tags=and_tags,
- or_tags=or_tags)
+ get_item_count=get_item_count)
- def find_all_videos(self, page_size=100, page_number=0,
+ def find_video_by_id(self, video_id, fields=None):
+ """
+ Finds a single video with the specified id.
+
+ video_id
+ The id of the video you would like to retrieve.
+
+ fields
+ A comma-separated list of the fields you wish to have populated
+ in the Video returned object. Passing null populates with all
+ fields.
+ """
+ return self._base_get_command(command="find_video_by_id",
+ video_id=video_id, fields=fields, single=True)
+
+ def find_related_videos(self, video_id=None, reference_id=None,
+ page_size=100, page_number=0, fields=None, get_item_count=True):
+ """
+ Finds videos related to the given video. Combines the name and short
+ description of the given video and searches for any partial matches in
+ the name, description, and tags of all videos in the Brightcove media
+ library for this account. More precise ways of finding related videos
+ include tagging your videos by subject and using the
+ find_videos_by_tags method to find videos that share the same tags: or
+ creating a playlist that includes videos that you know are related.
+
+ video_id
+ The id of the video we'd like related videos for.
+
+ reference_id
+ The publisher-assigned reference id of the video we'd like related
+ videos for.
+
+ page_size:
+ Integer Number of items returned per page. A page is a subset of
+ all of the items that satisfy the request. The maximum page size
+ is 100; if you do not set this argument, or if you set it to an
+ integer > 100, your results will come back as if you had set
+ page_size=100.
+
+ page_number:
+ Integer The zero-indexed number of the page to return.
+
+ fields:
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing None populates with all
+ fields.
+
+ get_item_count:
+ If set to True, return a total_count value with the payload.
+ """
+ return self._base_get_command(command="find_related_videos",
+ video_id=video_id, reference_id=reference_id, page_size=page_size,
+ page_number=page_number, fields=fields,
+ get_item_count=get_item_count)
+
+ def find_videos_by_ids(self, video_ids, fields=None):
+ """
+ Find multiple videos, given their ids.
+
+ video_ids
+ The list of video ids for the videos we'd like to retrieve.
+
+ fields
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing null populates with all
+ fields.
+ """
+ return self._base_get_command(command="find_videos_by_ids",
+ video_ids=video_ids, fields=fields)
+
+ def find_video_by_reference_id(self, reference_id, fields=None):
+ """
+ Find a video based on its publisher-assigned reference id.
+
+ reference_id
+ The publisher-assigned reference id for the video we're
+ searching for.
+
+ fields
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing null populates with all
+ fields.
+ """
+ return self._base_get_command(command="find_video_by_reference_id",
+ reference_id=reference_id, fields=fields, single=True)
+
+ def find_videos_by_reference_ids(self, reference_ids, fields=None):
+ """
+ Find multiple videos based on their publisher-assigned reference ids.
+
+ reference_ids
+ The list of reference ids for the videos we'd like to retrieve
+
+ fields
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing null populates with all
+ fields.
+ """
+ return self._base_get_command(command="find_videos_by_reference_ids",
+ reference_ids=reference_ids, fields=fields)
+
+ def find_videos_by_user_id(self, user_id, page_size=100, page_number=0,
sort_by=SortByType.CREATION_DATE, sort_order=SortByOrderType.ASC,
fields=None, get_item_count=True):
"""
+ Retrieves the videos uploaded by the specified user id. This method can
+ be used to find videos submitted using the consumer-generated media
+ (CGM) module.
+
+ user_id
+ The id of the user whose videos we'd like to retrieve.
+
page_size:
Integer Number of items returned per page. A page is a subset of
all of the items that satisfy the request. The maximum page size
@@ -169,25 +267,134 @@ def find_all_videos(self, page_size=100, page_number=0,
get_item_count:
If set to True, return a total_count value with the payload.
"""
- return self._base_get_command(command="find_all_videos",
- page_size=page_size, page_number=page_number, sort_by=sort_by,
- sort_order=sort_order, fields=fields,
+ return self._base_get_command(command="find_videos_by_user_id",
+ user_id=user_id, page_size=page_size, page_number=page_number,
+ sort_by=sort_by, sort_order=sort_order, fields=fields,
get_item_count=get_item_count)
- def find_video_by_id(self, video_id, fields=None):
+ def find_videos_by_campaign_id(self, campaign_id, page_size=100,
+ page_number=0, sort_by=SortByType.CREATION_DATE,
+ sort_order=SortByOrderType.ASC, fields=None, get_item_count=True):
"""
- Finds a single video with the specified id.
+ Gets all the videos associated with the given campaign id. Campaigns
+ are a feature of the consumer-generated media (CGM) module
- video_id
- The id of the video you would like to retrieve.
+ campaign_id
+ The id of the campaign you'd like to fetch videos for.
- fields
- A comma-separated list of the fields you wish to have populated
- in the Video returned object. Passing null populates with all
+ page_size:
+ Integer Number of items returned per page. A page is a subset of
+ all of the items that satisfy the request. The maximum page size
+ is 100; if you do not set this argument, or if you set it to an
+ integer > 100, your results will come back as if you had set
+ page_size=100.
+
+ page_number:
+ Integer The zero-indexed number of the page to return.
+
+ sort_by:
+ The field by which to sort the results. A SortByType: One of
+ PUBLISH_DATE, CREATION_DATE, MODIFIED_DATE, PLAYS_TOTAL,
+ PLAYS_TRAILING_WEEK.
+
+ sort_order:
+ How to order the results: ascending (ASC) or descending (DESC).
+
+ fields:
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing None populates with all
+ fields.
+
+ get_item_count:
+ If set to True, return a total_count value with the payload.
+ """
+ return self._base_get_command(command="find_videos_by_campaign_id",
+ campaign_id=campaign_id, page_size=page_size,
+ page_number=page_number, sort_by=sort_by, sort_order=sort_order,
+ fields=fields, get_item_count=get_item_count)
+
+ def find_videos_by_text(self, text, page_size=100, page_number=0,
+ fields=None, get_item_count=True):
+ """
+ Searches through all the videos in this account, and returns a
+ collection of videos whose name, short description, or long
+ description contain a match for the specified text.
+
+ text
+ The text we're searching for.
+
+ page_size:
+ Integer Number of items returned per page. A page is a subset of
+ all of the items that satisfy the request. The maximum page size
+ is 100; if you do not set this argument, or if you set it to an
+ integer > 100, your results will come back as if you had set
+ page_size=100.
+
+ page_number:
+ Integer The zero-indexed number of the page to return.
+
+ fields:
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing None populates with all
fields.
+
+ get_item_count:
+ If set to True, return a total_count value with the payload.
"""
- return self._base_get_command(command="find_video_by_id",
- video_id=video_id, fields=fields, single=True)
+ return self._base_get_command(command="find_videos_by_text",
+ text=text, page_size=page_size, page_number=page_number,
+ fields=fields, get_item_count=get_item_count)
+
+ def find_videos_by_tags(self, and_tags=None, or_tags=None, page_size=100,
+ page_number=0, sort_by=SortByType.MODIFIED_DATE,
+ sort_order=SortByOrderType.ASC, get_item_count=True, fields=None):
+ """
+ Performs a search on all the tags of the videos in this account,
+ and returns a collection of videos that contain the specified tags.
+
+ Note that tags are case-sensitive.
+
+ and_tags:
+ Limit the results to those that contain all of these tags.
+
+ or_tags
+ Limit the results to those that contain at least one of these tags.
+
+ page_size:
+ Integer Number of items returned per page. A page is a subset of
+ all of the items that satisfy the request. The maximum page size
+ is 100; if you do not set this argument, or if you set it to an
+ integer > 100, your results will come back as if you had set
+ page_size=100.
+
+ page_number:
+ Integer The zero-indexed number of the page to return.
+
+ sort_by:
+ The field by which to sort the results. A SortByType: One of
+ PUBLISH_DATE, CREATION_DATE, MODIFIED_DATE, PLAYS_TOTAL,
+ PLAYS_TRAILING_WEEK.
+
+ sort_order:
+ How to order the results: ascending (ASC) or descending (DESC).
+
+ fields:
+ List of the fields you wish to have populated in the videos
+ contained in the returned object. Passing None populates with all
+ fields.
+
+ get_item_count:
+ If set to True, return a total_count value with the payload.
+ """
+ if sort_by not in (SortByType.MODIFIED_DATE,
+ SortByType.PLAYS_TRAILING_WEEK):
+ raise Exception("Invalid sort by type.")
+
+ return self._base_get_command(command="find_videos_by_tags",
+ page_size=page_size, page_number=page_number, sort_by=sort_by,
+ sort_order=sort_order, fields=fields,
+ get_item_count=get_item_count, and_tags=and_tags,
+ or_tags=or_tags)
def create_video(self, filename, video, do_checksum=True,
create_multiple_renditions=True, preserve_source_rendition=True):

0 comments on commit 70eb5fe

Please sign in to comment.