8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Gdata_Extension_Comments
27 require_once 'Zend/Gdata/Extension/Comments.php';
30 * @see Zend_Gdata_Extension_FeedLink
32 require_once 'Zend/Gdata/Extension/FeedLink.php';
35 * @see Zend_Gdata_YouTube_MediaEntry
37 require_once 'Zend/Gdata/YouTube/MediaEntry.php';
40 * @see Zend_Gdata_YouTube_Extension_MediaGroup
42 require_once 'Zend/Gdata/YouTube/Extension/MediaGroup.php';
45 * @see Zend_Gdata_YouTube_Extension_NoEmbed
47 require_once 'Zend/Gdata/YouTube/Extension/NoEmbed.php';
50 * @see Zend_Gdata_YouTube_Extension_Statistics
52 require_once 'Zend/Gdata/YouTube/Extension/Statistics.php';
55 * @see Zend_Gdata_YouTube_Extension_Link
57 require_once 'Zend/Gdata/YouTube/Extension/Link.php';
60 * @see Zend_Gdata_YouTube_Extension_Racy
62 require_once 'Zend/Gdata/YouTube/Extension/Racy.php';
65 * @see Zend_Gdata_Extension_Rating
67 require_once 'Zend/Gdata/Extension/Rating.php';
70 * @see Zend_Gdata_Geo_Extension_GeoRssWhere
72 require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php';
75 * @see Zend_Gdata_YouTube_Extension_Control
77 require_once 'Zend/Gdata/YouTube/Extension/Control.php';
80 * @see Zend_Gdata_YouTube_Extension_Recorded
82 require_once 'Zend/Gdata/YouTube/Extension/Recorded.php';
85 * @see Zend_Gdata_YouTube_Extension_Location
87 require_once 'Zend/Gdata/YouTube/Extension/Location.php';
90 * Represents the YouTube video flavor of an Atom entry
95 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
96 * @license http://framework.zend.com/license/new-bsd New BSD License
98 class Zend_Gdata_YouTube_VideoEntry extends Zend_Gdata_YouTube_MediaEntry
101 const YOUTUBE_DEVELOPER_TAGS_SCHEMA = 'http://gdata.youtube.com/schemas/2007/developertags.cat';
102 const YOUTUBE_CATEGORY_SCHEMA = 'http://gdata.youtube.com/schemas/2007/categories.cat';
103 protected $_entryClassName = 'Zend_Gdata_YouTube_VideoEntry';
106 * If null, the video can be embedded
108 * @var Zend_Gdata_YouTube_Extension_NoEmbed|null
110 protected $_noEmbed = null;
113 * Specifies the statistics relating to the video.
115 * @var Zend_Gdata_YouTube_Extension_Statistics
117 protected $_statistics = null;
120 * If not null, specifies that the video has racy content.
122 * @var Zend_Gdata_YouTube_Extension_Racy|null
124 protected $_racy = null;
127 * If not null, specifies that the video is private.
129 * @var Zend_Gdata_YouTube_Extension_Private|null
131 protected $_private = null;
134 * Specifies the video's rating.
136 * @var Zend_Gdata_Extension_Rating
138 protected $_rating = null;
141 * Specifies the comments associated with a video.
143 * @var Zend_Gdata_Extensions_Comments
145 protected $_comments = null;
152 protected $_feedLink = array();
155 * Geo location for the video
157 * @var Zend_Gdata_Geo_Extension_GeoRssWhere
159 protected $_where = null;
162 * Recording date for the video
164 * @var Zend_Gdata_YouTube_Extension_Recorded|null
166 protected $_recorded = null;
169 * Location informtion for the video
171 * @var Zend_Gdata_YouTube_Extension_Location|null
173 protected $_location = null;
176 * Creates a Video entry, representing an individual video
178 * @param DOMElement $element (optional) DOMElement from which this
179 * object should be constructed.
181 public function __construct($element = null)
183 $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
184 parent::__construct($element);
188 * Retrieves a DOMElement which corresponds to this element and all
189 * child properties. This is used to build an entry back into a DOM
190 * and eventually XML text for sending to the server upon updates, or
191 * for application storage/persistence.
193 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
194 * @return DOMElement The DOMElement representing this element and all
197 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
199 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
200 if ($this->_noEmbed != null) {
201 $element->appendChild($this->_noEmbed->getDOM(
202 $element->ownerDocument));
204 if ($this->_statistics != null) {
205 $element->appendChild($this->_statistics->getDOM(
206 $element->ownerDocument));
208 if ($this->_racy != null) {
209 $element->appendChild($this->_racy->getDOM(
210 $element->ownerDocument));
212 if ($this->_recorded != null) {
213 $element->appendChild($this->_recorded->getDOM(
214 $element->ownerDocument));
216 if ($this->_location != null) {
217 $element->appendChild($this->_location->getDOM(
218 $element->ownerDocument));
220 if ($this->_rating != null) {
221 $element->appendChild($this->_rating->getDOM(
222 $element->ownerDocument));
224 if ($this->_comments != null) {
225 $element->appendChild($this->_comments->getDOM(
226 $element->ownerDocument));
228 if ($this->_feedLink != null) {
229 foreach ($this->_feedLink as $feedLink) {
230 $element->appendChild($feedLink->getDOM(
231 $element->ownerDocument));
234 if ($this->_where != null) {
235 $element->appendChild($this->_where->getDOM(
236 $element->ownerDocument));
242 * Creates individual Entry objects of the appropriate type and
243 * stores them in the $_entry array based upon DOM data.
245 * @param DOMNode $child The DOMNode to process
247 protected function takeChildFromDOM($child)
249 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
251 switch ($absoluteNodeName) {
252 case $this->lookupNamespace('yt') . ':' . 'statistics':
253 $statistics = new Zend_Gdata_YouTube_Extension_Statistics();
254 $statistics->transferFromDOM($child);
255 $this->_statistics = $statistics;
257 case $this->lookupNamespace('yt') . ':' . 'racy':
258 $racy = new Zend_Gdata_YouTube_Extension_Racy();
259 $racy->transferFromDOM($child);
260 $this->_racy = $racy;
262 case $this->lookupNamespace('yt') . ':' . 'recorded':
263 $recorded = new Zend_Gdata_YouTube_Extension_Recorded();
264 $recorded->transferFromDOM($child);
265 $this->_recorded = $recorded;
267 case $this->lookupNamespace('yt') . ':' . 'location':
268 $location = new Zend_Gdata_YouTube_Extension_Location();
269 $location->transferFromDOM($child);
270 $this->_location = $location;
272 case $this->lookupNamespace('gd') . ':' . 'rating':
273 $rating = new Zend_Gdata_Extension_Rating();
274 $rating->transferFromDOM($child);
275 $this->_rating = $rating;
277 case $this->lookupNamespace('gd') . ':' . 'comments':
278 $comments = new Zend_Gdata_Extension_Comments();
279 $comments->transferFromDOM($child);
280 $this->_comments = $comments;
282 case $this->lookupNamespace('yt') . ':' . 'noembed':
283 $noEmbed = new Zend_Gdata_YouTube_Extension_NoEmbed();
284 $noEmbed->transferFromDOM($child);
285 $this->_noEmbed = $noEmbed;
287 case $this->lookupNamespace('gd') . ':' . 'feedLink':
288 $feedLink = new Zend_Gdata_Extension_FeedLink();
289 $feedLink->transferFromDOM($child);
290 $this->_feedLink[] = $feedLink;
292 case $this->lookupNamespace('georss') . ':' . 'where':
293 $where = new Zend_Gdata_Geo_Extension_GeoRssWhere();
294 $where->transferFromDOM($child);
295 $this->_where = $where;
297 case $this->lookupNamespace('atom') . ':' . 'link';
298 $link = new Zend_Gdata_YouTube_Extension_Link();
299 $link->transferFromDOM($child);
300 $this->_link[] = $link;
302 case $this->lookupNamespace('app') . ':' . 'control':
303 $control = new Zend_Gdata_YouTube_Extension_Control();
304 $control->transferFromDOM($child);
305 $this->_control = $control;
308 parent::takeChildFromDOM($child);
314 * Sets when the video was recorded.
316 * @param Zend_Gdata_YouTube_Extension_Recorded $recorded When the video was recorded
317 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
319 public function setRecorded($recorded = null)
321 $this->_recorded = $recorded;
326 * Gets the date that the video was recorded.
328 * @return Zend_Gdata_YouTube_Extension_Recorded|null
330 public function getRecorded()
332 return $this->_recorded;
336 * Sets the location information.
338 * @param Zend_Gdata_YouTube_Extension_Location $location Where the video
340 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
342 public function setLocation($location = null)
344 $this->_location = $location;
349 * Gets the location where the video was recorded.
351 * @return Zend_Gdata_YouTube_Extension_Location|null
353 public function getLocation()
355 return $this->_location;
359 * If an instance of Zend_Gdata_YouTube_Extension_NoEmbed is passed in,
360 * the video cannot be embedded. Otherwise, if null is passsed in, the
361 * video is able to be embedded.
363 * @param Zend_Gdata_YouTube_Extension_NoEmbed $noEmbed Whether or not the
364 * video can be embedded.
365 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
367 public function setNoEmbed($noEmbed = null)
369 $this->_noEmbed = $noEmbed;
374 * If the return value is an instance of
375 * Zend_Gdata_YouTube_Extension_NoEmbed, this video cannot be embedded.
377 * @return Zend_Gdata_YouTube_Extension_NoEmbed|null Whether or not the video can be embedded
379 public function getNoEmbed()
381 return $this->_noEmbed;
385 * Checks whether the video is embeddable.
387 * @return bool Returns true if the video is embeddable.
389 public function isVideoEmbeddable()
391 if ($this->getNoEmbed() == null) {
399 * Sets the statistics relating to the video.
401 * @param Zend_Gdata_YouTube_Extension_Statistics $statistics The statistics relating to the video
402 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
404 public function setStatistics($statistics = null)
406 $this->_statistics = $statistics;
411 * Returns the statistics relating to the video.
413 * @return Zend_Gdata_YouTube_Extension_Statistics The statistics relating to the video
415 public function getStatistics()
417 return $this->_statistics;
421 * Specifies that the video has racy content.
423 * @param Zend_Gdata_YouTube_Extension_Racy $racy The racy flag object
424 * @throws Zend_Gdata_App_VersionException
425 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
427 public function setRacy($racy = null)
429 if ($this->getMajorProtocolVersion() == 2) {
430 require_once 'Zend/Gdata/App/VersionException.php';
431 throw new Zend_Gdata_App_VersionException(
432 'Calling getRacy() on a YouTube VideoEntry is deprecated ' .
433 'as of version 2 of the API.');
436 $this->_racy = $racy;
441 * Returns the racy flag object.
443 * @throws Zend_Gdata_App_VersionException
444 * @return Zend_Gdata_YouTube_Extension_Racy|null The racy flag object
446 public function getRacy()
448 if ($this->getMajorProtocolVersion() == 2) {
449 require_once 'Zend/Gdata/App/VersionException.php';
450 throw new Zend_Gdata_App_VersionException(
451 'Calling getRacy() on a YouTube VideoEntry is deprecated ' .
452 'as of version 2 of the API.');
458 * Sets the rating relating to the video.
460 * @param Zend_Gdata_Extension_Rating $rating The rating relating to the video
461 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
463 public function setRating($rating = null)
465 $this->_rating = $rating;
470 * Returns the rating relating to the video.
472 * @return Zend_Gdata_Extension_Rating The rating relating to the video
474 public function getRating()
476 return $this->_rating;
480 * Sets the comments relating to the video.
482 * @param Zend_Gdata_Extension_Comments $comments The comments relating to the video
483 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
485 public function setComments($comments = null)
487 $this->_comments = $comments;
492 * Returns the comments relating to the video.
494 * @return Zend_Gdata_Extension_Comments The comments relating to the video
496 public function getComments()
498 return $this->_comments;
502 * Sets the array of embedded feeds related to the video
504 * @param array $feedLink The array of embedded feeds relating to the video
505 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
507 public function setFeedLink($feedLink = null)
509 $this->_feedLink = $feedLink;
514 * Get the feed link property for this entry.
517 * @param string $rel (optional) The rel value of the link to be found.
518 * If null, the array of links is returned.
519 * @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
520 * object corresponding to the requested rel value is returned
521 * if found, or null if the requested value is not found. If
522 * $rel is null or not specified, an array of all available
523 * feed links for this entry is returned, or null if no feed
526 public function getFeedLink($rel = null)
529 return $this->_feedLink;
531 foreach ($this->_feedLink as $feedLink) {
532 if ($feedLink->rel == $rel) {
541 * Returns the link element relating to video responses.
543 * @return Zend_Gdata_App_Extension_Link
545 public function getVideoResponsesLink()
547 return $this->getLink(Zend_Gdata_YouTube::VIDEO_RESPONSES_REL);
551 * Returns the link element relating to video ratings.
553 * @return Zend_Gdata_App_Extension_Link
555 public function getVideoRatingsLink()
557 return $this->getLink(Zend_Gdata_YouTube::VIDEO_RATINGS_REL);
561 * Returns the link element relating to video complaints.
563 * @return Zend_Gdata_App_Extension_Link
565 public function getVideoComplaintsLink()
567 return $this->getLink(Zend_Gdata_YouTube::VIDEO_COMPLAINTS_REL);
571 * Gets the YouTube video ID based upon the atom:id value
573 * @return string The video ID
575 public function getVideoId()
577 if ($this->getMajorProtocolVersion() == 2) {
578 $videoId = $this->getMediaGroup()->getVideoId()->text;
580 $fullId = $this->getId()->getText();
581 $position = strrpos($fullId, '/');
582 if ($position === false) {
583 require_once 'Zend/Gdata/App/Exception.php';
584 throw new Zend_Gdata_App_Exception(
585 'Slash not found in atom:id of ' . $fullId);
587 $videoId = substr($fullId, $position + 1);
594 * Gets the date that the video was recorded.
596 * @return string|null The date that the video was recorded
598 public function getVideoRecorded()
600 $recorded = $this->getRecorded();
601 if ($recorded != null) {
602 return $recorded->getText();
609 * Sets the date that the video was recorded.
611 * @param string $recorded The date that the video was recorded, in the
612 * format of '2001-06-19'
614 public function setVideoRecorded($recorded)
617 new Zend_Gdata_YouTube_Extension_Recorded($recorded));
622 * Gets the georss:where element
624 * @return Zend_Gdata_Geo_Extension_GeoRssWhere
626 public function getWhere()
628 return $this->_where;
632 * Sets the georss:where element
634 * @param Zend_Gdata_Geo_Extension_GeoRssWhere $value The georss:where class value
635 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
637 public function setWhere($value)
639 $this->_where = $value;
644 * Gets the title of the video as a string. null is returned
645 * if the video title is not available.
647 * @return string|null The title of the video
649 public function getVideoTitle()
651 $this->ensureMediaGroupIsNotNull();
652 if ($this->getMediaGroup()->getTitle() != null) {
653 return $this->getMediaGroup()->getTitle()->getText();
660 * Sets the title of the video as a string.
662 * @param string $title Title for the video
663 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
665 public function setVideoTitle($title)
667 $this->ensureMediaGroupIsNotNull();
668 $this->getMediaGroup()->setTitle(
669 new Zend_Gdata_Media_Extension_MediaTitle($title));
674 * Sets the description of the video as a string.
676 * @param string $description Description for the video
677 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
679 public function setVideoDescription($description)
681 $this->ensureMediaGroupIsNotNull();
682 $this->getMediaGroup()->setDescription(
683 new Zend_Gdata_Media_Extension_MediaDescription($description));
689 * Gets the description of the video as a string. null is returned
690 * if the video description is not available.
692 * @return string|null The description of the video
694 public function getVideoDescription()
696 $this->ensureMediaGroupIsNotNull();
697 if ($this->getMediaGroup()->getDescription() != null) {
698 return $this->getMediaGroup()->getDescription()->getText();
705 * Gets the URL of the YouTube video watch page. null is returned
706 * if the video watch page URL is not available.
708 * @return string|null The URL of the YouTube video watch page
710 public function getVideoWatchPageUrl()
712 $this->ensureMediaGroupIsNotNull();
713 if ($this->getMediaGroup()->getPlayer() != null &&
714 array_key_exists(0, $this->getMediaGroup()->getPlayer())) {
715 $players = $this->getMediaGroup()->getPlayer();
716 return $players[0]->getUrl();
723 * Gets an array of the thumbnails representing the video.
724 * Each thumbnail is an element of the array, and is an
725 * array of the thumbnail properties - time, height, width,
726 * and url. For convient usage inside a foreach loop, an
727 * empty array is returned if there are no thumbnails.
729 * @return array An array of video thumbnails.
731 public function getVideoThumbnails()
733 $this->ensureMediaGroupIsNotNull();
734 if ($this->getMediaGroup()->getThumbnail() != null) {
736 $thumbnailArray = array();
738 foreach ($this->getMediaGroup()->getThumbnail() as $thumbnailObj) {
739 $thumbnail = array();
740 $thumbnail['time'] = $thumbnailObj->time;
741 $thumbnail['height'] = $thumbnailObj->height;
742 $thumbnail['width'] = $thumbnailObj->width;
743 $thumbnail['url'] = $thumbnailObj->url;
744 $thumbnailArray[] = $thumbnail;
746 return $thumbnailArray;
753 * Gets the URL of the flash player SWF. null is returned if the
754 * duration value is not available.
756 * @return string|null The URL of the flash player SWF
758 public function getFlashPlayerUrl()
760 $this->ensureMediaGroupIsNotNull();
761 foreach ($this->getMediaGroup()->getContent() as $content) {
762 if ($content->getType() === 'application/x-shockwave-flash') {
763 return $content->getUrl();
770 * Gets the duration of the video, in seconds. null is returned
771 * if the duration value is not available.
773 * @return string|null The duration of the video, in seconds.
775 public function getVideoDuration()
777 $this->ensureMediaGroupIsNotNull();
778 if ($this->getMediaGroup()->getDuration() != null) {
779 return $this->getMediaGroup()->getDuration()->getSeconds();
786 * Checks whether the video is private.
788 * @return bool Return true if video is private
790 public function isVideoPrivate()
792 $this->ensureMediaGroupIsNotNull();
793 if ($this->getMediaGroup()->getPrivate() != null) {
801 * Sets video to private.
803 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
805 public function setVideoPrivate()
807 $this->ensureMediaGroupIsNotNull();
808 $this->getMediaGroup()->setPrivate(new Zend_Gdata_YouTube_Extension_Private());
813 * Sets a private video to be public.
815 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
817 public function setVideoPublic()
819 $this->ensureMediaGroupIsNotNull();
820 $this->getMediaGroup()->private = null;
825 * Gets an array of the tags assigned to this video. For convient
826 * usage inside a foreach loop, an empty array is returned when there
827 * are no tags assigned.
829 * @return array An array of the tags assigned to this video
831 public function getVideoTags()
833 $this->ensureMediaGroupIsNotNull();
834 if ($this->getMediaGroup()->getKeywords() != null) {
836 $keywords = $this->getMediaGroup()->getKeywords();
837 $keywordsString = $keywords->getText();
838 if (strlen(trim($keywordsString)) > 0) {
839 return preg_split('/(, *)|,/', $keywordsString);
846 * Sets the keyword tags for a video.
848 * @param mixed $tags Either a comma-separated string or an array
849 * of tags for the video
850 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
852 public function setVideoTags($tags)
854 $this->ensureMediaGroupIsNotNull();
855 $keywords = new Zend_Gdata_Media_Extension_MediaKeywords();
856 if (is_array($tags)) {
857 $tags = implode(', ', $tags);
859 $keywords->setText($tags);
860 $this->getMediaGroup()->setKeywords($keywords);
865 * Gets the number of views for this video. null is returned if the
866 * number of views is not available.
868 * @return string|null The number of views for this video
870 public function getVideoViewCount()
872 if ($this->getStatistics() != null) {
873 return $this->getStatistics()->getViewCount();
880 * Gets the location specified for this video, if available. The location
881 * is returned as an array containing the keys 'longitude' and 'latitude'.
882 * null is returned if the location is not available.
884 * @return array|null The location specified for this video
886 public function getVideoGeoLocation()
888 if ($this->getWhere() != null &&
889 $this->getWhere()->getPoint() != null &&
890 ($position = $this->getWhere()->getPoint()->getPos()) != null) {
892 $positionString = $position->__toString();
894 if (strlen(trim($positionString)) > 0) {
895 $positionArray = explode(' ', trim($positionString));
896 if (count($positionArray) == 2) {
897 $returnArray = array();
898 $returnArray['latitude'] = $positionArray[0];
899 $returnArray['longitude'] = $positionArray[1];
908 * Gets the rating information for this video, if available. The rating
909 * is returned as an array containing the keys 'average' and 'numRaters'.
910 * null is returned if the rating information is not available.
912 * @return array|null The rating information for this video
914 public function getVideoRatingInfo()
916 if ($this->getRating() != null) {
917 $returnArray = array();
918 $returnArray['average'] = $this->getRating()->getAverage();
919 $returnArray['numRaters'] = $this->getRating()->getNumRaters();
927 * Gets the category of this video, if available. The category is returned
928 * as a string. Valid categories are found at:
929 * http://gdata.youtube.com/schemas/2007/categories.cat
930 * If the category is not set, null is returned.
932 * @return string|null The category of this video
934 public function getVideoCategory()
936 $this->ensureMediaGroupIsNotNull();
937 $categories = $this->getMediaGroup()->getCategory();
938 if ($categories != null) {
939 foreach($categories as $category) {
940 if ($category->getScheme() == self::YOUTUBE_CATEGORY_SCHEMA) {
941 return $category->getText();
949 * Sets the category of the video as a string.
951 * @param string $category Categories for the video
952 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
954 public function setVideoCategory($category)
956 $this->ensureMediaGroupIsNotNull();
957 $this->getMediaGroup()->setCategory(array(new Zend_Gdata_Media_Extension_MediaCategory($category, self::YOUTUBE_CATEGORY_SCHEMA)));
962 * Gets the developer tags for the video, if available and if client is
963 * authenticated with a valid developerKey. The tags are returned
965 * If no tags are set, null is returned.
967 * @return array|null The developer tags for this video or null if none were set.
969 public function getVideoDeveloperTags()
971 $developerTags = null;
972 $this->ensureMediaGroupIsNotNull();
974 $categoryArray = $this->getMediaGroup()->getCategory();
975 if ($categoryArray != null) {
976 foreach ($categoryArray as $category) {
977 if ($category instanceof Zend_Gdata_Media_Extension_MediaCategory) {
978 if ($category->getScheme() == self::YOUTUBE_DEVELOPER_TAGS_SCHEMA) {
979 $developerTags[] = $category->getText();
983 return $developerTags;
989 * Adds a developer tag to array of tags for the video.
991 * @param string $developerTag DeveloperTag for the video
992 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
994 public function addVideoDeveloperTag($developerTag)
996 $this->ensureMediaGroupIsNotNull();
997 $newCategory = new Zend_Gdata_Media_Extension_MediaCategory($developerTag, self::YOUTUBE_DEVELOPER_TAGS_SCHEMA);
999 if ($this->getMediaGroup()->getCategory() == null) {
1000 $this->getMediaGroup()->setCategory($newCategory);
1002 $categories = $this->getMediaGroup()->getCategory();
1003 $categories[] = $newCategory;
1004 $this->getMediaGroup()->setCategory($categories);
1010 * Set multiple developer tags for the video as strings.
1012 * @param array $developerTags Array of developerTag for the video
1013 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface
1015 public function setVideoDeveloperTags($developerTags)
1017 foreach($developerTags as $developerTag) {
1018 $this->addVideoDeveloperTag($developerTag);
1025 * Get the current publishing state of the video.
1027 * @return Zend_Gdata_YouTube_Extension_State|null The publishing state of this video
1029 public function getVideoState()
1031 $control = $this->getControl();
1032 if ($control != null &&
1033 $control->getDraft() != null &&
1034 $control->getDraft()->getText() == 'yes') {
1036 return $control->getState();
1042 * Get the VideoEntry's Zend_Gdata_YouTube_Extension_MediaGroup object.
1043 * If the mediaGroup does not exist, then set it.
1047 public function ensureMediaGroupIsNotNull()
1049 if ($this->getMediagroup() == null) {
1050 $this->setMediagroup(new Zend_Gdata_YouTube_Extension_MediaGroup());
1055 * Helper function to conveniently set a video's rating.
1057 * @param integer $ratingValue A number representing the rating. Must
1058 * be between 1 and 5 inclusive.
1059 * @throws Zend_Gdata_Exception
1060 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface.
1062 public function setVideoRating($ratingValue)
1064 if ($ratingValue < 1 || $ratingValue > 5) {
1065 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
1066 throw new Zend_Gdata_App_InvalidArgumentException(
1067 'Rating for video entry must be between 1 and 5 inclusive.');
1070 require_once 'Zend/Gdata/Extension/Rating.php';
1071 $rating = new Zend_Gdata_Extension_Rating(null, 1, 5, null,
1073 $this->setRating($rating);
1078 * Retrieve the URL for a video's comment feed.
1080 * @return string|null The URL if found, or null if not found.
1082 public function getVideoCommentFeedUrl()
1084 $commentsExtension = $this->getComments();
1085 $commentsFeedUrl = null;
1086 if ($commentsExtension) {
1087 $commentsFeedLink = $commentsExtension->getFeedLink();
1088 if ($commentsFeedLink) {
1089 $commentsFeedUrl = $commentsFeedLink->getHref();
1092 return $commentsFeedUrl;