forked from bernorieder/YouTube-Data-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_channel_info.php
More file actions
executable file
·205 lines (150 loc) · 5.32 KB
/
mod_channel_info.php
File metadata and controls
executable file
·205 lines (150 loc) · 5.32 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php include("html_head.php"); ?>
<div class="rowTab">
<div class="sectionTab">
<h1>Channel Info Module</h1>
</div>
</div>
<div class="rowTab">
<div class="fullTab">
<p>This module retrieves different kinds of information for a channel from the <a href="https://developers.google.com/youtube/v3/docs/channels/list" target="_blank">channels/list</a> API endpoint
from a specified channel id. The following resources are requested: brandingSettings, status, id, snippet, contentDetails, contentOwnerDetails, statistics, topicDetails, invideoPromotion.</p>
<p>Output is a direct print of the API response.</p>
<p>You can use comma-separated hashes to retrieve information for more than one channel as a list (tab file).</p>
</div>
</div>
<div class="rowTab">
<div class="sectionTab"><h1>Parameters</h1></div>
</div>
<form action="mod_channel_info.php" method="get">
<div class="rowTab">
<div class="leftTab">Channel id:</div>
<div class="rightTab">
<input type="text" name="hash" value="<?php if(isset($_GET["hash"])) { echo $_GET["hash"]; } ?>" /> (channel ids can be found in URLs, e.g. https://www.youtube.com/channel/<b>UCtxGqPJPPi8ptAzB029jpYA</b>)
</div>
</div>
<div class="g-recaptcha" data-sitekey="6Lf093MUAAAAAIRLVzHqfIq9oZcOnX66Dju7e8sr"></div>
<div class="rowTab">
<div class="leftTab"></div>
<div class="rightTab">
<input type="submit" />
</div>
</div>
</form>
<?php
if(isset($_GET["hash"])) {
echo '<div class="rowTab">
<div class="sectionTab"><h1>Results</h1></div>
</div>
<div class="rowTab">';
if($_GET["hash"] == "") {
echo "Missing channel id.";
exit;
}
if($_GET["g-recaptcha-response"] == "") {
echo "Recaptcha missing.";
exit;
}
testcaptcha($_GET["g-recaptcha-response"]);
$hash = $_GET["hash"];
if(preg_match("/,/", $hash)) {
getInfos($hash);
} else {
getInfo($hash);
}
}
function getInfos($hash) {
global $apikey,$datafolder;
$hashes = explode(",",$hash);
$channels = array();
foreach($hashes as $hash) {
$restquery = "https://www.googleapis.com/youtube/v3/channels?part=id,snippet,statistics&id=".$hash."&key=".$apikey;
$reply = doAPIRequest($restquery);
//print_r($reply);
$channel = array();
$channel["id"] = $reply->items[0]->id;
$channel["title"] = $reply->items[0]->snippet->title;
$channel["description"] = $reply->items[0]->snippet->description;
$channel["publishedAt"] = $reply->items[0]->snippet->publishedAt;
$channel["defaultLanguage"] = $reply->items[0]->snippet->defaultLanguage;
$channel["country"] = $reply->items[0]->snippet->country;
$channel["viewCount"] = $reply->items[0]->statistics->viewCount;
$channel["subscriberCount"] = $reply->items[0]->statistics->subscriberCount;
$channel["videoCount"] = $reply->items[0]->statistics->videoCount;
$channels[] = $channel;
}
$filename = "channellist_channels" . count($hashes) . "_" . date("Y_m_d-H_i_s") . ".tab";
$fp = fopen($datafolder.$filename, 'w');
fputcsv($fp,array_keys($channel),"\t");
foreach($channels as $channel) {
fputcsv($fp,$channel,"\t");
}
echo '<br /><br />The script has retrieved information for '.count($hashes).' channels.<br /><br />
your file:<br />
<a href="'.$datafolder.$filename.'" download>'.$filename."</a><br />";
}
function getInfo($hash) {
global $apikey;
$restquery = "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings,status,id,snippet,contentDetails,contentOwnerDetails,statistics,topicDetails,invideoPromotion&id=".$hash."&key=".$apikey;
// example
//$hash = "LLP2X3cVGXP0r56gOGhiRDlA";
//$restquery = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=".$hash."&maxResults=50&key=".$apikey;
$reply = doAPIRequest($restquery);
/*
echo '<pre>';
print_r($reply->items[0]);
echo '</pre>';
*/
echo '<table class="resulttable">';
foreach($reply->items[0] as $key => $var) {
echo '<tr class="resulttable">';
echo '<td class="resulttableHi"><b>'.$key.'</b></td>';
if(gettype($var) != "object" && gettype($var2) != "array") {
echo '<td class="resulttable">'.$var.'</td>';
} else {
echo '<td class="resulttable">';
echo '<table style="display:inline">';
foreach($var as $key2 => $var2) {
echo '<tr>';
echo '<td><b>'.$key2.'</b></td>';
if(gettype($var2) != "object" && gettype($var2) != "array") {
echo '<td>'.$var2.'</td>';
} else {
echo '<td class="resulttable">';
echo '<table style="display:inline">';
foreach($var2 as $key3 => $var3) {
echo '<tr>';
echo '<td><b>'.$key3.'</b></td>';
if(gettype($var3) != "object" && gettype($var3) != "array") {
echo '<td>'.$var3.'</td>';
} else {
echo '<td class="resulttable">';
echo '<table style="display:inline">';
foreach($var3 as $key4 => $var4) {
echo '<tr>';
echo '<td><b>'.$key4.'</b></td>';
if(gettype($var4) != "object" && gettype($var) != "array") {
echo '<td>'.$var4.'</td>';
} else {
echo '<td>'.$var4.'</td>';
}
echo '</tr>';
}
echo '</table>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
echo '</td>';
}
echo '</tr>';
}
echo '</table></div>';
}
?>
<?php include("html_foot.php"); ?>