-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCdaScript.js
344 lines (288 loc) · 10.6 KB
/
CdaScript.js
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
const PLATFORM = "CDA";
var config = {};
const VIDEO_SEARCH_URL = "api.cda.pl/video/search";
const VIDEO_URL = "www.cda.pl/video/";
const BASE_URL = "www.cda.pl";
const LOGIN = "{{login}}";
const PASSWORD = "{{password}}";
const REQUEST_PARAMS = {
Accept: "application/vnd.cda.public+json",
}
const BASE_AUTH = "Basic NzdjMGYzYzUtMzZhMC00YzNkLWIwZDQtMGM0ZGZiZmQ1NmQ1Ok5wbU1MQldSZ3RFWDh2cDNLZjNkMHRhc0JwRnQwdHVHc3dMOWhSMHF0N2JRZGF4dXZER29jekZHZXFkNjhOajI";
function getToken() {
let params = REQUEST_PARAMS;
params["Authorization"] = BASE_AUTH;
const res = http.POST(`https://api.cda.pl/oauth/token?grant_type=password&login=${encodeURI(LOGIN)}&password=${PASSWORD}`, "", params);
if (res.code != 200) {
return null;
}
return JSON.parse(res.body).access_token;
}
function id_from_username(username) {
const jrpc = http.POST("https://www.cda.pl/api.php", JSON.stringify({
"jsonrpc": "2.0",
"method": "boxNoweFilmyGetPage",
"params": [
username,1,{}
],
"id":1
}), REQUEST_PARAMS);
if (jrpc.code != 200) {
return null;
}
const doc = JSON.parse(jrpc.body).result;
if (!doc) {
return null;
}
const v_id = domParser.parseFromString(doc, 'text/html').querySelector("a.thumbnail-link").getAttribute("href").replace("/video/","");
const video = http.GET(`https://api.cda.pl/video/${v_id}`, REQUEST_PARAMS);
if (video.code != 200) {
return null;
}
return JSON.parse(video.body).video.author.id;
}
//Source Methods
source.enable = function(conf, settings, savedState){
config = conf ?? {};
}
source.getHome = function() {
return new ContentPager([], false);
};
source.searchSuggestions = function(query) {
throw new ScriptException("This is a sample");
};
source.getSearchCapabilities = () => {
return {
types: [Type.Feed.Mixed],
sorts: [Type.Order.Chronological],
filters: [ ]
};
};
source.search = function (query, type, order, filters) {
console.log(`query: ${query}`);
return getVideoPager(VIDEO_SEARCH_URL, {
search: query,
sort: order
}, 1);
// return new ContentPager([]. false);
};
source.getSearchChannelContentsCapabilities = function () {
return {
types: [Type.Feed.Mixed],
sorts: [Type.Order.Chronological, "Views"],
filters: []
};
};
source.searchChannelContents = function (channelUrl, query, type, order, filters) {
throw new ScriptException("This is a sample");
};
source.searchChannels = function (query) {
throw new ScriptException("This is a sample");
};
//Channel
source.isChannelUrl = function(url) {
return url.includes(BASE_URL) && !url.includes(VIDEO_URL);
};
source.getChannel = function(url) {
console.log(url);
let author = url.replace("/vfilm", "").split("/").at(-1);
author = id_from_username(author);
let params = REQUEST_PARAMS;
params["Authorization"] = "Bearer " + getToken();
const res = http.GET("https://api.cda.pl/user/" + author, params);
if (res.code != 200) {
return null;
}
const data = JSON.parse(res.body);
return new PlatformChannel({
id: new PlatformID(PLATFORM, data.id, config.id),
name: data.login,
url: url,
thumbnail: data.avatar,
banner: data.header,
subscribers: 0,
description: "",
links: null
});
};
source.getChannelContents = function(url, type, order, filters) {
console.log(url);
let author = url.replace("/vfilm", "").split("/").at(-1);
author = id_from_username(author);
let params = REQUEST_PARAMS;
params["Authorization"] = "Bearer " + getToken();
if (order == "Views") {
order = "popular";
} else {
order = "last";
}
return getVideoPager("https://api.cda.pl/user/" + author + "/videos", {
sort: order
}, 1);
};
source.getChannelPlaylists = function(url) {
return getPlaylistPager(url, {
token: getToken(),
//author:
}, []);
};
//Video
source.isContentDetailsUrl = function(url) {
return url.includes(VIDEO_URL) && !url.includes(VIDEO_SEARCH_URL);
};
source.getContentDetails = function(url) {
const res = http.GET(url.replace("https://www.cda.pl", "https://api.cda.pl").replace("/vfilm", ""), REQUEST_PARAMS);
if (res.code != 200) {
return null;
}
const data = JSON.parse(res.body).video;
let rating = new RatingLikes(0);
if (data.premium) {
rating = new RatingScaler(Number(data.imdb.average) / 10.);
} else {
rating = new RatingScaler(Number(data.rating) / 10.);
}
return new PlatformVideoDetails({
id: new PlatformID(PLATFORM, data.id, config.id),
name: data.title,
url,
author: new PlatformAuthorLink(new PlatformID(PLATFORM, data.author.id, config.id), data.author.login, `https://www.cda.pl/${data.author.login}`, data.author.avatar, ""),
thumbnails: new Thumbnails([new Thumbnail(data.thumb)]),
viewCount: data.views,
duration: data.duration,
rating,
video: new VideoSourceDescriptor(data.qualities.map(quality => new VideoUrlSource({
url: quality.file,
}))),
});
};
//Comments
source.getComments = function (url) {
return getCommentsPager(url, {}, 1);
}
source.getSubComments = function (comment) {
throw new ScriptException("This is a sample");
}
function getPlaylistVideos(path, params) {
let r_params = REQUEST_PARAMS;
r_params["Authorization"] = "Bearer " + params.token;
const res = http.GET(path, r_params);
}
function getPlaylistPager(path, params, page) {
path = path.replace("https://www.cda.pl", "https://api.cda.pl");
path = path.replace("/vfilm", "");
path += "/folders";
const res = http.GET(path, REQUEST_PARAMS);
if (res.code != 200) {
return new ContentPager([], false);
}
let body = JSON.parse(res.body);
let list = [new ]
}
function getVideoPager(path, params, page) {
let url = "";
if (params.search) {
url = VIDEO_SEARCH_URL + "?query=" + encodeURI(params.search) + `&page=${page}&limit=20`;
const res = http.GET(`https://${url}`, REQUEST_PARAMS);
console.log(res.code);
if (res.code != 200) {
return new VideoPager([], false);
}
const data = JSON.parse(res.body);
return new CDAVideoPager(data.data.map(video => {
return new PlatformVideo({
id: new PlatformID(PLATFORM, video.id, config.id),
name: video.title,
thumbnails: new Thumbnails([new Thumbnail(video.thumb)]),
author: new PlatformAuthorLink(new PlatformID(PLATFORM, video.author.id, config.id), video.author.login, `https://www.cda.pl/${video.author.login}`, video.author.avatar, ""),
uploadDate: 0,
duration: video.duration,
viewCount: video.views,
url: "https://"+VIDEO_URL+video.id+"/vfilm",
isLive: false
});
}), data.paginator.total_pages > page, path, params, page);
} else {
let token = getToken();
if (token == null) {
return new VideoPager([], false);
}
url = path + `?order=${params.sort}&page=${page}&limit=100`;
let r_params = REQUEST_PARAMS;
r_params["Authorization"] = "Bearer " + token;
const res = http.GET(url, r_params);
console.log(res.code);
if (res.code != 200) {
return new VideoPager([], false);
}
let author = path.replace("/videos", "");
author = http.GET(author, r_params);
if (author.code != 200) {
return new VideoPager([], false);
}
return new CDAVideoPager(JSON.parse(res.body).data.map(video => {
return new PlatformVideo({
id: new PlatformID(PLATFORM, video.id, config.id),
name: video.title,
thumbnails: new Thumbnails([new Thumbnail(video.thumb)]),
author: new PlatformAuthorLink(new PlatformID(PLATFORM, author.id, config.id), author.login, `https://www.cda.pl/${author.login}`, author.avatar, ""),
uploadDate: video.published,
duration: video.duration,
viewCount: video.views,
url: "https://"+VIDEO_URL+video.id+"/vfilm",
isLive: false
});
}), JSON.parse(res.body).paginator.total_pages > page, path, params, page);
}
}
function getCommentsPager(path, params, page) {
let url = path.replace("www.cda.pl", "api.cda.pl").replace("/vfilm", `/comments?page=${page}`);
if (!url.startsWith("https://")) {
url = "https://" + url;
}
const res = http.GET(url, REQUEST_PARAMS);
console.log(res.code);
if (res.code != 200) {
return new CommentPager([], false);
}
const data = JSON.parse(res.body);
return new CDACommentPager(data.data.map(comment => {
let reply_count = 0;
if (comment.answers != null) {
reply_count = comment.answers.length;
}
return new Comment({
contextUrl: url,
author: new PlatformAuthorLink(new PlatformID(PLATFORM, comment.author.id, config.id), comment.author.name, `https://www.cda.pl/${comment.author.login}`, comment.author.avatar, ""),
message: comment.content,
rating: new RatingLikes(Number(comment.rating)),
date: comment.time,
replyCount: reply_count
});
}), data.paginator.total_pages > page, url, params, page);
}
class CDAPlaylistPages extends PlaylistPager {
constructor(results, hasMore, path, params, page) {
super(results, hasMore, { path, params, page });
}
nextPage() {
return getPlaylistPager(this.context.path, this.context.params, (this.context.page ?? 0) + 1);
}
}
class CDAVideoPager extends VideoPager {
constructor(results, hasMore, path, params, page) {
super(results, hasMore, { path, params, page });
}
nextPage() {
return getVideoPager(this.context.path, this.context.params, (this.context.page ?? 0) + 1);
}
}
class CDACommentPager extends CommentPager {
constructor(results, hasMore, path, params, page) {
super(results, hasMore, { path, params, page });
}
nextPage() {
return getCommentPager(this.context.path, this.context.params, (this.context.page ?? 0) + 1);
}
}
console.log('LOADED')