YouTube Data API V3: Download caption - javascript

I’m working on a project that will need to read caption(s) from YouTube videos, and then parse the caption to make a dictionary of words. Right now I’m only working on getting caption data first!
I made this API call, and it didn’t work as expected!
I need to read caption data of a video and then parse it somehow!
API call:
async function getCaptionByVideoId(id) {
try {
const request = await gapi.client.youtube.captions.list({
part: ["snippet, id"],
videoId: id,
tlang: 'en',
tfmt: 'ttml'
});
const response = await request.result;
if (response.items.length > 1) {
return response.items.filter(item => item.snippet.language === 'en')
}
return response;
} catch (error) {
console.log(error);
}
}
Response:
[
{
kind: "youtube#caption",
etag: "qt7kpc07o-McD5N8SFENONZ-FiI",
id: "AUieDaafzkx3-EUGGaap0OIkgWRbLbfU0Bqv2M9iRhanbyW5TNU",
snippet: {
videoId: "8jPQjjsBbIc",
lastUpdated: "2021-10-10T19:35:21.164143Z",
trackKind: "asr",
language: "en",
name: "",
audioTrackType: "unknown",
isCC: false,
isLarge: false,
isEasyReader: false,
isDraft: false,
isAutoSynced: false,
status: "serving",
},
},
{
kind: "youtube#caption",
etag: "2MG45WYjwBv-zopacDaEe5hikyU",
id: "AUieDaZVpbT7DmC_9OEHWLvRaJRr58EF7xLsvjhBprQ-",
snippet: {
videoId: "8jPQjjsBbIc",
lastUpdated: "2017-10-26T04:17:05.804457Z",
trackKind: "standard",
language: "en",
name: "",
audioTrackType: "unknown",
isCC: false,
isLarge: false,
isEasyReader: false,
isDraft: false,
isAutoSynced: false,
status: "serving",
},
},
];

You are using YouTube Data API v3 Captions: list endpoint while you were thinking about using YouTube Data API v3 Captions: download endpoint.
Note that YouTube Data API v3 interesting Captions: download endpoint is only usable by the channel owning the given videos we want the captions of (source: this Stack Overflow comment, I verified this fact).
So the alternatives are using:
youtube-dl/yt-dlp
my low-level approach

Related

how to manually render data from editor-js

I'm using editor.js for the first time, and I got stuck on this part: After selecting image from my gallery I want to re-render editor js with new image: this is my code for now
let url = `/${this.selectedImg.image.id}/${this.selectedImg.image.name}`
this.editor.configuration.data.blocks.push({
data: {
caption: "",
file: {url: url},
stretched: false,
withBackground: false,
withBorder: false,
},
type: "image"
})
console.log(this.editor,'editor')
this.editor.render()
but this.editor.render() doesn't work, what am I missing?
this is console.log screenshot
I would appreciate any help!
editor.save().then((data) => {
data.blocks.push({
type: "image",
data: {
caption: "",
file: {url: url},
stretched: false,
withBackground: false,
withBorder: false,
},
})
this.editor.render(data)
this.$emit('close', true)
})
this was the answer, I misread the docs :)

Proper way to change color of embed (discord.js)

I am wondering if their is a way to edit the color of an embed that is already sent earlier. I want to update the color after the user has reacted with a certain emoji?
After some debugging I found to get this from messageReaction.message.embeds
[
MessageEmbed {
type: 'rich',
title: null,
description: 'Its the description thats showing this, kinda cool inst it?',
url: null,
color: 9807270,
timestamp: 1607934639684,
fields: [],
thumbnail: {
url: 'https://cdn.discordapp.com/avatars/501923384448385025/2a50751b22710319060b3b3af8e4952b.webp',
proxyURL: 'https://images-ext-1.discordapp.net/external/cKWwFnPdQCHFZ_o3x4-g17bDb4Yi8JfKiNkkd7qiXao/https/cdn.discordapp.com/avatars/501923384448385025/2a50751b22710319060b3b3af8e4952b.webp',
height: 128,
width: 128
},
image: null,
video: null,
author: null,
provider: null,
footer: {
text: 'I am a nice little footer that is for testing because test.',
iconURL: undefined,
proxyIconURL: undefined
},
files: []
}
]
But when I use console.log(messageReaction.message.embeds.description) it returns undefined..
So editing the message with the .edit function won't work because the description, timestamp, footer, thumbnail etc that was in that embed already is going to be lost..
Found the issue, because it returns an array I needed to use messageReaction.message.embeds[0].description instead.

Sequelize how to return column of joined table in the results

I'm using the sequelize module for my node.js mvc project and the query i'd like to execute is the following
SELECT answer_text, isNew, name FROM answer JOIN topic ON answer.topic_id = topic.id
answer_text and isNew are columns of the answer table while name is a column that only exists in the topic table.
How can i have the topic table name column appear in the results next to isNew column so that i can access it easily? Does sequelize provide such a feature or it's my responsibility to format the result?
I've tried to add various things in attributes like 'topic.name' but none worked.
The way i've set up the file structure is based on their documentation Sequelize usage with express
var models = require('../models')
var answers = await models.Answer.findAll({
include: [{
model: models.Topic
}],
attributes: [
'answer_text',
'isNew'
]
})
console.log(answers)
The output of the following is
{ answer_text: 'maybe it is robots',
isNew: true,
Topic:
Topic {
dataValues:
{ id: 830,
mid: 'm.0bjmp5',
name: 'Robot Arena',
description:
'Robot Arena is a computer game made by Infogrames. It features robotic combat similar to that of Battlebots Robotica and Robot Wars. There are a number of different chassis and on top of that there are numerous attachments. Weapons accessories tires and other forms of mobility batteries and air tanks are among the customization choices. A sequel called Robot Arena 2 Design and Destroy was made which allows for total customization of your
robot.',
type: 'cvg.computer_videogame' },
_previousDataValues:
{ id: 830,
mid: 'm.0bjmp5',
name: 'Robot Arena',
description:
'Robot Arena is a computer game made by Infogrames. It features robotic combat similar to that of Battlebots Robotica and Robot Wars. There are a number of different chassis and on top of that there are numerous attachments. Weapons accessories tires and other forms of mobility batteries and air tanks are among the customization choices. A sequel called Robot Arena 2 Design and Destroy was made which allows for total customization of your
robot.',
type: 'cvg.computer_videogame' },
_changed: {},
_modelOptions:
{ timestamps: false,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: null,
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: [Object],
omitNull: false,
sequelize: [Sequelize],
hooks: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: undefined,
includeNames: undefined,
includeMap: undefined,
includeValidated: true,
raw: true,
attributes: undefined },
isNewRecord: false } }
Please try the following sequelize statement -
var answers = await models.Answer.findAll({
include: [{
model: models.Topic,
attributes: ['name']
}],
attributes: [
'answer_text',
'isNew'
],
raw: true
})
I hope it helps!
Working answer:
Sequelize must be required in order to use [sequelize.col('Topic.name'), 'name'] inside attributes so that we can fetch name column of Topic table and rename 'Topics.name' to name. (Tried models.col but it is not a function)
raw: true is required if you want to get only the columns inside answers[0]
attributes:[] is required inside include because if you don't put it the result will include all the columns from the joined table (Topic).
const models = require('../models')
const sequelize = require('sequelize');
var answers = await models.Answer.findAll({
include: [{
model: models.Topic,
attributes: []
}],
attributes: [
'answer_text',
'isNew',
[sequelize.col('Topic.name'), 'name']
],
raw: true
})
console.log(answers[0])
output:
{ answer_text: 'robot arena',
isNew: 'true',
name: 'Robot Arena' }

Why Kendo dataSouce.transport.update method do not send data to the server?

I have a Kendo UI TreeList where every row has a checkbox displayed. If the user clicks on the checkbox then a request goes to the server and save the data. Unfortunately, I did something wrong because:
the update method does not send data to the server
and the sync method is not called automatically
What I did wrong?
I think the problem around how I set up that which item has changed. As you can see I iterate over the dataset coming from dataSource.data() and the item.checked and item.dirty properties are updated. If I understand correctly the documentation then this changes should trigger the sync method. It does not trigger the sync method and this it the reason I call it in the method.
My other question is related to the data structure should be sent to the server. It is based on the schema, right? So, once I can achieve that the request sends an object to the server I should create a similar C# POCO as model and I can read the data in the webapi controller.
In the documentation there is a saveRow() method, but I cannot translate that code to angular. Can somebody help me in this case?
//this row is my problem
var treeList = $("#treeList").data("kendoTreeList");
var dataSource = new kendo.data.TreeListDataSource({
transport: {
read: {
url: configurationService.goNoGoWebApiRootUrl + 'AreaPathDependencies/Get/ChildrenMarked/' + selectedAreaPathIdFromModalService,
dataType: "json",
type: "get"
},
update:
{
url: configurationService.goNoGoWebApiRootUrl + 'AreaPathDependencies/Update/AreaPathDependencies',
dataType: "json",
type: "post"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "id",
parentId: "parentId",
fields: {
Id: { type: "number", editable: false, nullable: true },
ParentId: { type: "number", editable: false, nullable: true },
Name: { type: "string", editable: false, nullable: true },
Checked: { type: "boolean", editable: true, nullable: false }
}
}
}
});
vm.treeListOptions = {
dataSource: dataSource,
sortable: false,
editable: false,
columns: [
{
field: "checked",
title: "Selected",
template: checkBoxTemplate,
width: 32
},
{ field: "name", title: "Area Path", width: "200px", expandable: true },
{ field: "fullPath", title: "FullPath", width: "500px" },
],
save: onSave,
change: onChange,
sync: sync,
autoSync: true,
};
}
function checkboxOnclick(selectedId) {
console.log('checkboxOnclick', selectedId);
var data = vm.treeListOptions.dataSource.data();
for (var i = 0; i < data.length; i++) {
if (selectedId == data[i].id) {
data[i].set("checked", true);
//data[i].dirty = true;
}
}
vm.treeListOptions.dataSource.sync();
//console.log('flush', vm.treeListOptions.dataSource.data());
}
Well batch: true has to be set to get parameterMap working, because models parameters will be available only when the batch option is enabled. (parameterMap docs)
And to second question - I am not so sure but as noted in sync docs,
The sync method will request the remote service if:
the transport.create option is set and the data source contains new data items
the transport.destroy option is set and data items have been removed from the data source
the transport.update option is set and the data source contains updated data items
How I understand to that - to get sync method working you need to return updated records. Please check, if your server method for update/delete returns that.

How to load JSON Data in jQuery-jTable plugin?

I am working on creating a table form using jTable plugin. It mainly focus for ASP or PHP MVC but I'm trying to implement it with javascript/html and mongo backend.
I went through entire jTable API documentation and I found out there is possibility of populating json schema api into table, quite similiar in flexigrid.
The code looks like:
$(document).ready(function () {
$('#feeds-table').jtable({
title: 'Accounts',
pageSize: 15,
ajaxSettings: {
type: 'GET',
dataType: 'json'
},
actions: {
},
fields: {
id: {
key: true,
list: false
},
username: {
title: 'Username',
width: '10%'
},
email: {
title: 'Email',
width: '10%'
},
applications: {
title: 'Applications',
width: '10%'
},
sites: {
title: 'Sites',
width: '10%'
},
verticals: {
title: 'Verticals',
width: '10%'
},
roles: {
title: 'Roles',
width: '10%'
},
profiles: {
title: 'Record date',
width: '30%',
type: 'date',
create: false,
edit: false
}
}
});
});
If anyone can help me to find out where should I use URL property or is there any other method in the API reference to GET the data and display in table. Please let me know!
You can directly load JSON data by setting the 'listAction' to a JSON document .
Example:
actions: {
listAction: 'url/file.json',
},
Your JSON file needs to have the same fields specified and the next structure:
{
"Result":"OK",
"Records":[
{"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},
{"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},
{"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},
{"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}
]
}
The common way is to point the 'listAction' to a server side script (PHP,ASP.NET...) that return the above JSON object.
Check the listAction API reference for more information:
ApiReference-listAction
Use the addRecord action. It gives you the option to specify clientOnly: true which will prevent jtable from making a server call when you edit a row.
More Information - jtable.org-addRecord

Categories

Resources