YouTube API 2

This commit is contained in:
Natsumi
2021-09-07 09:04:14 +12:00
parent 1673a0745c
commit 405bc2caf9
+70 -18
View File
@@ -4604,7 +4604,7 @@ speechSynthesis.getVoices();
// don't play noty twice // don't play noty twice
if ( if (
this.notyMap[displayName] && this.notyMap[displayName] &&
this.notyMap[displayName] > noty.created_at this.notyMap[displayName] >= noty.created_at
) { ) {
return; return;
} }
@@ -7324,7 +7324,10 @@ speechSynthesis.getVoices();
gameLog.userDisplayName, gameLog.userDisplayName,
userMap userMap
); );
if (this.friends.has(userId)) { if (
this.friends.has(userId) ||
API.currentUser.displayName === gameLog.userDisplayName
) {
this.lastLocation.friendList.set( this.lastLocation.friendList.set(
gameLog.userDisplayName, gameLog.userDisplayName,
userMap userMap
@@ -7381,6 +7384,13 @@ speechSynthesis.getVoices();
case 'video-play': case 'video-play':
this.addGameLogVideo(gameLog, location, userId, pushToTable); this.addGameLogVideo(gameLog, location, userId, pushToTable);
return; return;
case 'vrcx':
// VideoPlay(PyPyDance) "https://jd.pypy.moe/api/v1/videos/jr1NX4Jo8GE.mp4",0.1001,239.606,"0905 : [J-POP] 【まなこ】金曜日のおはよう 踊ってみた (vernities)"
var type = gameLog.data.substr(0, gameLog.data.indexOf(' '));
if (type === 'VideoPlay(PyPyDance)') {
this.addGameLogPyPyDance(gameLog, location, pushToTable);
}
return;
case 'notification': case 'notification':
var entry = { var entry = {
created_at: gameLog.dt, created_at: gameLog.dt,
@@ -7418,34 +7428,71 @@ speechSynthesis.getVoices();
if (typeof gameLog.displayName !== 'undefined') { if (typeof gameLog.displayName !== 'undefined') {
displayName = gameLog.displayName; displayName = gameLog.displayName;
} }
var L = API.parseLocation(location);
if (L.worldId !== 'wrld_f20326da-f1ac-45fc-a062-609723b097b1') {
// skip PyPyDance videos
try { try {
var url = new URL(videoUrl); var url = new URL(videoUrl);
var id1 = url.pathname; var id1 = url.pathname;
var id2 = url.searchParams.get('v'); var id2 = url.searchParams.get('v');
if (id1 && id1.length === 12) { if (id1 && id1.length === 12) {
youtubeVideoId = id2.substring(1, 12); youtubeVideoId = id1.substring(1, 12);
} }
if (id2 && id2.length === 11) { if (id2 && id2.length === 11) {
youtubeVideoId = id2; youtubeVideoId = id2;
} }
if (this.youTubeApi && youtubeVideoId) { if (this.youTubeApi && youtubeVideoId) {
var data = await this.lookupYouTubeVideo(youtubeVideoId); var data = await this.lookupYouTubeVideo(youtubeVideoId);
if ( if (data || data.pageInfo.totalResults !== 0) {
data ||
(data.status === 200 && data.pageInfo.totalResults !== 0)
) {
videoId = 'YouTube'; videoId = 'YouTube';
videoName = data.items[0].snippet.title; videoName = data.items[0].snippet.title;
videoLength = this.convertYoutubeTime( videoLength = this.convertYoutubeTime(
data.items[0].contentDetails.duration data.items[0].contentDetails.duration
); );
} else {
console.error(`YouTube video lookup failed status: ${status}`);
} }
} }
} catch { } catch {
console.error(`Invalid URL: ${url}`); console.error(`Invalid URL: ${url}`);
} }
var entry = {
created_at: gameLog.dt,
type: 'VideoPlay',
videoUrl,
videoId,
videoName,
videoLength,
location,
displayName,
userId
};
if (pushToTable) {
this.queueGameLogNoty(entry);
this.gameLogTable.data.push(entry);
}
if (this.youTubeApi && youtubeVideoId) {
var data = await this.lookupYouTubeVideo(youtubeVideoId);
if (
data ||
(data.status === 200 && data.pageInfo.totalResults !== 0)
) {
videoId = 'YouTube';
videoName = data.items[0].snippet.title;
videoLength = this.convertYoutubeTime(
data.items[0].contentDetails.duration
);
} else {
console.error(`YouTube video lookup failed status: ${status}`);
}
}
}
if (videoId === 'URL') {
var entry = {
dt: gameLog.dt,
videoUrl,
displayName
};
this.addGameLogVideo(entry, location, userId, pushToTable);
} else {
var entry = { var entry = {
created_at: gameLog.dt, created_at: gameLog.dt,
type: 'VideoPlay', type: 'VideoPlay',
@@ -7462,10 +7509,11 @@ speechSynthesis.getVoices();
this.gameLogTable.data.push(entry); this.gameLogTable.data.push(entry);
} }
database.addGamelogVideoPlayToDatabase(entry); database.addGamelogVideoPlayToDatabase(entry);
}
}; };
$app.methods.lookupYouTubeVideo = async function (videoId) { $app.methods.lookupYouTubeVideo = async function (videoId) {
var data = {}; var data = null;
var apiKey = 'AIzaSyA-iUQCpWf5afEL3NanEOSxbzziPMU3bxY'; var apiKey = 'AIzaSyA-iUQCpWf5afEL3NanEOSxbzziPMU3bxY';
if (this.youTubeApiKey) { if (this.youTubeApiKey) {
apiKey = this.youTubeApiKey; apiKey = this.youTubeApiKey;
@@ -7479,8 +7527,12 @@ speechSynthesis.getVoices();
Referer: 'https://vrcx.pypy.moe' Referer: 'https://vrcx.pypy.moe'
} }
}); });
data = JSON.parse(response.data); var json = JSON.parse(response.data);
data.status = response.status; if (response.status === 200) {
data = json;
} else {
throw new Error(`Error: ${response.data}`);
}
} catch { } catch {
console.error(`YouTube video lookup failed for ${videoId}`); console.error(`YouTube video lookup failed for ${videoId}`);
} }
@@ -7521,13 +7573,13 @@ speechSynthesis.getVoices();
var ref = API.cachedWorlds.get(L.worldId); var ref = API.cachedWorlds.get(L.worldId);
if (ref) { if (ref) {
L.worldName = ref.name; L.worldName = ref.name;
L.worldCapacity = ref.capacity; L.worldCapacity = ref.capacity * 2;
} else { } else {
API.getWorld({ API.getWorld({
worldId: L.worldId worldId: L.worldId
}).then((args) => { }).then((args) => {
L.worldName = args.ref.name; L.worldName = args.ref.name;
L.worldCapacity = args.ref.capacity; L.worldCapacity = args.ref.capacity * 2;
return args; return args;
}); });
} }
@@ -7554,7 +7606,7 @@ speechSynthesis.getVoices();
} }
switch (API.currentUser.status) { switch (API.currentUser.status) {
case 'active': case 'active':
L.statusName = 'Active'; L.statusName = 'Online';
L.statusImage = 'active'; L.statusImage = 'active';
break; break;
case 'join me': case 'join me':
@@ -13972,10 +14024,10 @@ speechSynthesis.getVoices();
return; return;
} }
var data = await this.lookupYouTubeVideo('dQw4w9WgXcQ'); var data = await this.lookupYouTubeVideo('dQw4w9WgXcQ');
if (!data || data.status !== 200) { if (!data) {
this.youTubeApiKey = ''; this.youTubeApiKey = '';
this.$message({ this.$message({
message: `Invalid YouTube API key, error code: ${data.status}`, message: 'Invalid YouTube API key',
type: 'error' type: 'error'
}); });
} else { } else {
@@ -13987,8 +14039,8 @@ speechSynthesis.getVoices();
message: 'YouTube API key valid!', message: 'YouTube API key valid!',
type: 'success' type: 'success'
}); });
}
this.youTubeApiDialog.visible = false; this.youTubeApiDialog.visible = false;
}
}; };
$app.methods.changeYouTubeApi = function () { $app.methods.changeYouTubeApi = function () {