{"size": 3342, "ext": "js", "max_stars_repo_path": "node_modules/@discord-player/extractor/lib/internal/Vimeo.js", "max_stars_repo_name": "Bombo43453/EA-BOT", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/@discord-player/extractor/lib/internal/Vimeo.js", "max_issues_repo_name": "Bombo43453/EA-BOT", "max_issues_repo_issues_event_min_datetime": "2021-09-11T17:40:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-11T17:40:53.000Z", "max_forks_repo_path": "node_modules/@discord-player/extractor/lib/internal/Vimeo.js", "max_forks_repo_name": "Bombo43453/Bombot-Discord", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 41.2592592593, "max_line_length": 125, "alphanum_fraction": 0.5305206463}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vimeo = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
const http_1 = __importDefault(require("http"));
const https_1 = __importDefault(require("https"));
class Vimeo {
    constructor() {
        throw new Error(`The ${this.constructor.name} class may not be instantiated!`);
    }
    /**
     * @typedef {Readable} Readable
     */
    /**
     * Downloads from vimeo
     * @param {number} id Vimeo video id
     * @returns {Promise<Readable>}
     */
    static download(id) {
        return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
            const info = yield Vimeo.getInfo(id);
            if (!info)
                return null;
            const downloader = info.stream.url.startsWith('https://') ? https_1.default : http_1.default;
            downloader.get(info.stream.url, (res) => {
                resolve(res);
            });
        }));
    }
    /**
     * Returns video info
     * @param {number} id Video id
     */
    static getInfo(id) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!id)
                throw new Error('Invalid id');
            const url = `https://player.vimeo.com/video/${id}`;
            try {
                const res = yield node_fetch_1.default(url);
                const data = yield res.text();
                const json = JSON.parse(data.split('<script> (function(document, player) { var config = ')[1].split(';')[0]);
                const obj = {
                    id: json.video.id,
                    duration: json.video.duration,
                    title: json.video.title,
                    url: json.video.url,
                    thumbnail: json.video.thumbs['1280'] || json.video.thumbs.base,
                    width: json.video.width,
                    height: json.video.height,
                    stream: json.request.files.progressive[0],
                    author: {
                        accountType: json.video.owner.account_type,
                        id: json.video.owner.id,
                        name: json.video.owner.name,
                        url: json.video.owner.url,
                        avatar: json.video.owner.img_2x || json.video.owner.img
                    }
                };
                return obj;
            }
            catch (_a) {
                return null;
            }
        });
    }
}
exports.Vimeo = Vimeo;
