Skip to content

Commit

Permalink
added basic metadata search
Browse files Browse the repository at this point in the history
  • Loading branch information
JijaProGamer authored and JijaProGamer committed Nov 19, 2022
1 parent 3950089 commit ebc68e9
Show file tree
Hide file tree
Showing 9 changed files with 18,362 additions and 19 deletions.
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022-2023 JijaProGamer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ module.exports = () => {
connectBrowser: require("./application/connectBrowser.js"),
handleNewPage: require("./application/handleNewPage.js"),
initWatcher: require("./application/initWatcher.js"),
getPlayerStatistics: require("./application/getPlayerStatistics"),
getVideoMetadata: require("./application/getVideoMetadata"),
}
}
24 changes: 7 additions & 17 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let {

let runApp = async (index) => {
let browserConnection = api.connectBrowser("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", {
browserWSEndpoint: "wss://chrome.browserless.io?token=3ef2a4af-925a-4165-9371-b4b850790f88",
//browserWSEndpoint: "wss://chrome.browserless.io?",
//proxyServer: "bloxxy213.asuscomm.com:31280",
userDataDir: path.join(__dirname, `/testUserDataDir/${index}`),
saveBandwith: true,
Expand All @@ -29,30 +29,20 @@ let runApp = async (index) => {
let browser = await browserConnection.browser()
let page = await api.handleNewPage()

await sleep(100000000)
await page.goto("https://www.youtube.com/watch?v=bdAzFR3JzLg", {waitUntil: "networkidle0"})
await api.initWatcher(page)

let videoElement = await waitForSelector(page, "video")
let videoDuration = await page.evaluate((e) => Math.floor(e.duration), videoElement)

let interval = setInterval(async () => {
let time = await page.evaluate((e) => Math.floor(e.currentTime), videoElement)

console.log(time, videoDuration, index)

if(time > 60 * 5){
//console.log(time, bandwithUsed)
clearInterval(interval)
await browser.close()
}
setInterval(async () => {
console.log(await api.getPlayerStatistics(page))
}, 1000)
}

//runApp(999)
runApp(999)

for (let i = 0; i < 10; i += 2){
setTimeout(async () => {
runApp(i + 1)
runApp(i + 2)
//runApp(i + 1)
//runApp(i + 2)
}, i * 5 * 1000)
}
30 changes: 30 additions & 0 deletions application/getPlayerStatistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
let {
uploadFileXPath, uploadFileSelector, clickSelector, clickXPath, goto,
waitForSelector,waitForXPath, typeSelector, typeXPath, sleep,
jiggleMouse, confirmNavigation, random} = require("./publicFunctions.js")

/**
* Gets information about the video being played in the page
* @param {Object} page result of api.handleNewPage()
*/

function getPlayerStatistics(page) {
return new Promise(async (resolve, reject) => {
let info = {}
this.data.emit(`debug`, `Started gathering player statistics`)

let videoPlayer = await waitForSelector(page, `video`)
let time = await page.evaluate((v) => v.currentTime, videoPlayer)
let duration = await page.evaluate((v) => v.duration, videoPlayer)

info.time = Math.floor(time)
info.duration = Math.floor(duration)
info.percentWatched = (time * 100) / duration

this.data.emit(`debug`, `Sucesfully grabbed video information ${info}`)

resolve(info)
})
}

module.exports = getPlayerStatistics
31 changes: 31 additions & 0 deletions application/getVideoMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const ytdl = require('ytdl-core');

/**
* Gets information about a video from an id
* @param {String} id Id of the video
*/

function getVideoMetadata(id) {
return new Promise(async (resolve, reject) => {
ytdl.getBasicInfo(`https://www.youtube.com/watch?v=${id}`).then((fullInfo) => {
fullInfo = fullInfo.videoDetails

let info = {
id: id,
title: fullInfo.title,
description: fullInfo.description,
duration: parseFloat(fullInfo.lengthSeconds),
author: fullInfo.author.name,
views: parseFloat(fullInfo.viewCount),
uploadDate: fullInfo.uploadDate,
chapters: fullInfo.chapters
}

resolve(info)
}).catch((err) => {
reject(new Error(`Error getting video metadata: ${err}`))
})
})
}

module.exports = getVideoMetadata
5 changes: 5 additions & 0 deletions application/initWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ let {
waitForSelector,waitForXPath, typeSelector, typeXPath, sleep,
jiggleMouse, confirmNavigation, random} = require("./publicFunctions.js")

/**
* Initialises the video player, should be run only once per page
* @param {Object} page result of api.handleNewPage()
*/

function initWatcher(page) {
return new Promise(async (resolve, reject) => {
if (!this.__handled) reject(new Error(`Please call api.connectBrowser first`))
Expand Down
Loading

0 comments on commit ebc68e9

Please sign in to comment.