Skip to content

Commit

Permalink
Change libs to not use Freetube components anymore. Closes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal-Szczepaniak committed May 23, 2023
1 parent 7b2e0fa commit 3dc7564
Show file tree
Hide file tree
Showing 50 changed files with 957 additions and 384 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/translations
DESTINATION share/microtube
FILES_MATCHING PATTERN "*.qm"
)
install(FILES microtube.desktop
install(FILES microtube.desktop microtube-url.desktop
DESTINATION share/applications
)
install(FILES icons/86x86/microtube.png
Expand Down
2 changes: 1 addition & 1 deletion js/basicVideoInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ytdl = require('ytdl-core');
import ytdl from 'ytdl-core';

let query = process.argv[2];

Expand Down
15 changes: 9 additions & 6 deletions js/channelInfo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const ytch = require('yt-channel-info')
import { Innertube } from 'youtubei.js';

let channelId = process.argv[2];
const payload = {
channelId: channelId,
}
const youtube = await Innertube.create({
lang: 'en',
location: 'US',
});

ytch.getChannelInfo(payload).then(d => console.log(JSON.stringify(d, null, 2)), e => console.error(JSON.stringify(e, null, 2)));
const channelId = process.argv[2];
const channel = await youtube.getChannel(channelId)

console.log(JSON.stringify(channel, null, 2))
43 changes: 29 additions & 14 deletions js/channelVideos.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
const ytch = require('yt-channel-info')
import { Innertube, YTNodes } from 'youtubei.js';

let channelId = process.argv[2];
let sortBy = process.argv[3];
let continuation = process.argv[4];
const yt = await Innertube.create({
lang: 'en',
location: 'US',
});

if (continuation) {
const payload = {
continuation: continuation,
}
ytch.getChannelVideosMore(payload).then(d => console.log(JSON.stringify(d, null, 2)), e => console.error(JSON.stringify(e, null, 2)));
const channelId = process.argv[2];
const continuation = JSON.parse(process.argv[3])

let videos = null
let continuationData = null
if (Object.keys(continuation).length) {
const response = await yt.actions.execute(continuation.endpoint.metadata.api_url, {
...continuation.endpoint.payload,
parse: true
});

videos = response.on_response_received_actions_memo.getType(YTNodes.Video)
continuationData = response.on_response_received_actions_memo.getType(YTNodes.ContinuationItem).at(0)
} else {
const payload = {
channelId: channelId,
sortBy: sortBy,
}
ytch.getChannelVideos(payload).then(d => console.log(JSON.stringify(d, null, 2)), e => console.error(JSON.stringify(e, null, 2)));
const channel = await yt.getChannel(channelId)
const channelVideos = await channel.getVideos()
continuationData = channelVideos.memo.getType(YTNodes.ContinuationItem).at(0)
videos = channelVideos.memo.getType(YTNodes.Video)
}

const result = {
items: videos,
continuation: continuationData
}

console.log(JSON.stringify(result, null, 2))
35 changes: 28 additions & 7 deletions js/commentReplies.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
const ytcm = require("@freetube/yt-comment-scraper");
import { Innertube, YTNodes } from 'youtubei.js';

let query = process.argv[2];
let replyToken = process.argv[3];
const yt = await Innertube.create({
lang: 'en',
location: 'US',
});

const payload = {
videoId: query,
replyToken: replyToken,
const continuation = JSON.parse(process.argv[2]);

const response = await yt.actions.execute(continuation.endpoint.metadata.api_url, {
...continuation.endpoint.payload,
parse: true
});


let comments = []
let continuationData = null
response.on_response_received_endpoints[0].contents.forEach(element => {
if (element.type === "Comment") {
comments.push(element)
} else if (element.type === "ContinuationItem") {
continuationData = element
}
})


const result = {
items: comments,
continuation: continuationData
}

ytcm.getCommentReplies(payload).then(d => console.log(JSON.stringify(d, null, 2)), e => console.error(JSON.stringify(e, null, 2)));
console.log(JSON.stringify(result, null, 2))
43 changes: 35 additions & 8 deletions js/comments.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
const ytcm = require("@freetube/yt-comment-scraper");
import { Innertube, YTNodes } from 'youtubei.js';

let query = process.argv[2];
let continuation = process.argv[3];
const yt = await Innertube.create({
lang: 'en',
location: 'US',
});

const payload = {
videoId: query,
sortByNewest: false,
continuation: continuation,
const channelId = process.argv[2];
const continuation = JSON.parse(process.argv[3])

let comments = null
let continuationData = null
if (Object.keys(continuation).length) {
const response = await yt.actions.execute(continuation.endpoint.metadata.api_url, {
...continuation.endpoint.payload,
parse: true
});

comments = []
response.on_response_received_endpoints[0].contents.forEach(element => {
if (element.type === "CommentThread") {
comments.push(element)
} else if (element.type === "ContinuationItem") {
continuationData = element
}
})
} else {
const commentsData = await yt.getComments(channelId);

continuationData = commentsData.page.on_response_received_endpoints.at(1).contents.firstOfType(YTNodes.ContinuationItem);
comments = commentsData.contents;
}

const result = {
items: comments,
continuation: continuationData
}

ytcm.getComments(payload).then(d => console.log(JSON.stringify(d, null, 2)), e => console.error(JSON.stringify(e, null, 2)));
console.log(JSON.stringify(result, null, 2))
Loading

0 comments on commit 3dc7564

Please sign in to comment.