
Hai guys.. Setelah menonton video youtube Agung Hapsah yang judul videonya bisa update otomatis sesuai jumlah views jadi tertarik bikin sendiri.
Membuat Judul Youtube Update Otomatis
- Silahkan kunjungi https://script.google.com/home
- Klik tombol new project di kiri atas.
- Hapus script default project.
- Salin kode dibawah ini kemudian paste ke dalam project kamu.
- Ganti
VIDEO_ID
dengan id video dari video YouTube yang ingin kamu gunakan untuk eksperimen ini. Jika URL video adalahyoutube.com/watch?v=xxx
, id video adalahxxx
. - Buka Setelan Project, centang
Tampilkan file manifes "appsscript.json" di editor
. - Buka kembali editor dan ganti dengan script dibawah ini.
- Klik Run di dalam editor Apps Script, pilih Run dan pilih
updateYouTubeVideo
. Izinkan script untuk mengelola akun YouTube kamu
/*
This Google Script will auto-update the title of your
YouTube video based on the number of views and comments
Tutorial: https://www.abengkris.com/2022/08/youtube-title-auto-update.html
Author: Abengkris https://www.abengkris.com/
Original Idea by Tom Scott youtu.be/BxV14h0kFs0
*/
const updateYouTubeVideo = (e = null) => {
const id = "VIDEO_ID";
const template = "This video has VIEWCOUNT views and COMMENTCOUNT comments";
// The cron job is created only when the script is run manually
if (e === null) {
const triggerName = "updateYouTubeVideo";
const triggers = ScriptApp.getProjectTriggers().filter((trigger) => {
return trigger.getHandlerFunction() === triggerName;
});
// If time based trigger doesn't exist, create one that runs every 5 minutes
if (triggers.length === 0) {
ScriptApp.newTrigger(triggerName).timeBased().everyMinutes(5).create();
}
}
// Get the watch statistics of the video
const { items: [video = {}] = [] } = YouTube.Videos.list(
"snippet,statistics",
{
id
}
);
// Parse the YouTube API response to get views and comment count
const {
snippet: { title: oldTitle, categoryId } = {},
statistics: { viewCount, commentCount } = {}
} = video;
if (viewCount && commentCount) {
const newTitle = template
.replace("VIEWCOUNT", viewCount)
.replace("COMMENTCOUNT", commentCount);
// If the video title has not changed, skip this step
if (oldTitle !== newTitle) {
YouTube.Videos.update(
{ id: id, snippet: { title: newTitle, categoryId } },
"snippet"
);
}
}
};
{
"timeZone": "Asia/Jakarta",
"dependencies": {
"enabledAdvancedServices": [
{
"userSymbol": "YouTube",
"serviceId": "youtube",
"version": "v3"
}
]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
Script akan berjalan setiap lima menit dan memperbarui judul video YouTube kamu secara otomatis. Sesimpel itu!
Cara Menghentikan Script Google YouTube
Buka script.google.com dan cari script YouTube di dasbor Project Saya. Buka menu pemicu dan hapus pemicunya. Script akan berhenti memperbarui judul video di latar belakang.