Skip to content

Commit

Permalink
api work
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrekB416 committed Mar 20, 2024
1 parent 7e158c8 commit f8821c6
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions CdaScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ const PLATFORM = "CDA";

var config = {};

const VIDEO_SEARCH_URL = "www.cda.pl/video/show/";
const VIDEO_SEARCH_URL = "api.cda.pl/video/search";
const VIDEO_URL = "www.cda.pl/video/";
const ANONYMOUS_REQUEST_PARAMS = {
Authorization: "Basic NzdjMGYzYzUtMzZhMC00YzNkLWIwZDQtMGM0ZGZiZmQ1NmQ1Ok5wbU1MQldSZ3RFWDh2cDNLZjNkMHRhc0JwRnQwdHVHc3dMOWhSMHF0N2JRZGF4dXZER29jekZHZXFkNjhOajI",
Accept: "application/vnd.cda.public+json",
};

//Source Methods
source.enable = function(conf, settings, savedState){
Expand Down Expand Up @@ -109,42 +113,29 @@ source.getSubComments = function (comment) {
}

function getVideoPager(path, params, page) {
const url = VIDEO_SEARCH_URL + params.search.replace(/ /g, "_") + `/p${page}?s=best`;
const res = http.GET(`https://${url}`, {});
const url = VIDEO_SEARCH_URL + "?query=" + encodeURI(params.search) + `&page=${page}&limit=20`;
const res = http.GET(`https://${url}`, ANONYMOUS_REQUEST_PARAMS);

//log(res);
log(res.code);
if (res.code != 200) {
return new VideoPager([], false);
}
log(res.body.data);
//const parser = new DOMParser();

const html = domParser.parseFromString(res.body.substring(res.body.indexOf("<body"), res.body.lastIndexOf("</body>") + 7));;

const durationsConvert = [3600, 60, 1];
return new CDAVideoPager(html.querySelectorAll(".video-clip-wrapper").map(video => {
const videoHref = video.querySelector("a.link-title-visit");
const videoID = videoHref.getAttribute("href").replace(`https://${VIDEO_URL}`, "").replace("/vfilm", "");
const durationArray = video.querySelector("span.timeElem").text.split(":");
let duration = 0;
log(durationArray);
for (let i = 1; i <= durationArray.length; i++) {
duration += durationArray[durationArray.length - i] * durationsConvert[3-i];
}

const imgSrc = video.querySelector("img").getAttribute("src");

return new CDAVideoPager(res.body.data.map(video => {
return new PlatformVideo({
id: new PlatformID(PLATFORM, videoID, config.id),
name: videoHref.text,
thumbnails: new Thumbnails([new Thumbnail("https:" + imgSrc , 0)]),
id: new PlatformID(PLATFORM, video.id, config.id),
name: video.title,
thumbnails: new Thumbnails([new Thumbnail(video.thumb)]),
author: new PlatformAuthorLink(new PlatformID(PLATFORM, "", config.id), "", "", ""),
uploadDate: 0,
duration,
viewCount: 0,
duration: video.duration,
viewCount: video.views,
url: "https://"+VIDEO_URL+videoID+"/vfilm",
isLive: false
});
}), html.querySelectorAll(".sbmNext").length > 0, url, params, page);
}), res.body.paginator.totalPages > page, url, params, page);
}

class CDAVideoPager extends VideoPager {
Expand Down

0 comments on commit f8821c6

Please sign in to comment.