forked from AlexandrosD/YouTube
/
youtube.playlist.php
99 lines (87 loc) · 1.86 KB
/
youtube.playlist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* YouTube PHP library
*
* @author Alexandros D
* @copyright Alexandros D 2011
* @license GNU/GPL v2
* @since 0.6.0
*
*/
require_once 'youtube.php';
require_once 'youtube.video.php';
require_once 'youtube.videolist.php';
class YouTubePlaylist extends YouTubeVideoList {
private $_title;
private $_subtitle;
private $_id;
/**
* Load playlist data
*
* @param String $playlistId The playlist id
*/
public function __construct( $playlistId , $developerKey = NULL ) {
$this->_id = $playlistId;
$this->_developerKey = $developerKey;
}
/**
* Get Playlist ID
*
* @return int the Playlist ID
*/
public function getID() {
return $this->_id;
}
/**
* Load Playlist
*
* @return boolean
*/
public function loadPlaylist( $maxResults = 0 , $startIndex = 0 ) {
$this->_maxResults = $maxResults;
$this->_startIndex = $startIndex;
return $this->_loadVideos();
}
/**
* Fetch playlist's title
*
* @return String The playlist's title
*/
public function getTitle() {
return $this->_title;
}
/**
* Fetch playlist's subtitle
*
* @return String The playlist's subtitle
*/
public function getSubtitle() {
return $this->_subtitle;
}
/**
* Set playlist's title
*
* @param String $title The playlist's title
*/
public function setTitle( $title ) {
$this->_title = $title;
}
/**
* Set playlist's subtitle
*
* @param String $subtitle The playlist's subtitle
*/
public function setSubtitle( $subtitle ) {
$this->_subtitle = $subtitle;
}
private function _loadVideos(){
$youtube = new YouTube( $this->_developerKey );
$playlist = $youtube->getPlaylist( $this->_id , $this->_maxResults , $this->_startIndex );
//load playlist data
$xml = new SimpleXMLElement( $playlist );
$this->_title = (string) $xml->title;
$this->_subtitle = (string) $xml->subtitle;
//load videos
return parent::populate( $playlist );
}
}