feat: use JSON for image metadata format

This commit is contained in:
Natsumi
2023-02-15 01:37:04 +13:00
parent c46c97e51a
commit edba9f6468
4 changed files with 82 additions and 54 deletions
+12 -17
View File
@@ -635,26 +635,21 @@ namespace VRCX
} }
} }
public void AddScreenshotMetadata(string path, string worldName, string worldId, bool changeFilename = false) public void AddScreenshotMetadata(string path, string metadataString, string worldId, bool changeFilename = false)
{ {
try var fileName = Path.GetFileNameWithoutExtension(path);
if (!File.Exists(path) || !path.EndsWith(".png") || !fileName.StartsWith("VRChat_"))
return;
if (changeFilename)
{ {
string fileName = Path.GetFileNameWithoutExtension(path); var newFileName = $"{fileName}_{worldId}";
if (!File.Exists(path) || !path.EndsWith(".png") || !fileName.StartsWith("VRChat_")) return; var newPath = Path.Combine(Path.GetDirectoryName(path), newFileName + Path.GetExtension(path));
File.Move(path, newPath);
if (changeFilename) path = newPath;
{
var newFileName = $"{fileName}_{worldId}";
var newPath = Path.Combine(Path.GetDirectoryName(path), newFileName + Path.GetExtension(path));
File.Move(path, newPath);
path = newPath;
}
string metadataString = $"{Program.Version}||{worldId}||{worldName}";
ScreenshotHelper.WritePNGDescription(path, metadataString);
} }
catch { }
ScreenshotHelper.WritePNGDescription(path, metadataString);
} }
} }
} }
+68 -35
View File
@@ -9201,13 +9201,14 @@ speechSynthesis.getVoices();
} }
break; break;
case 'location': case 'location':
var worldName = this.replaceBioSymbols(gameLog.worldName);
if (this.isGameRunning) { if (this.isGameRunning) {
this.lastLocationReset(gameLog.dt); this.lastLocationReset(gameLog.dt);
this.clearNowPlaying(); this.clearNowPlaying();
this.lastLocation = { this.lastLocation = {
date: Date.parse(gameLog.dt), date: Date.parse(gameLog.dt),
location: gameLog.location, location: gameLog.location,
name: gameLog.worldName, name: worldName,
playerList: new Map(), playerList: new Map(),
friendList: new Map() friendList: new Map()
}; };
@@ -9224,7 +9225,7 @@ speechSynthesis.getVoices();
type: 'Location', type: 'Location',
location: gameLog.location, location: gameLog.location,
worldId: L.worldId, worldId: L.worldId,
worldName: gameLog.worldName, worldName,
time: 0 time: 0
}; };
this.addGamelogLocationToDatabase(entry); this.addGamelogLocationToDatabase(entry);
@@ -9282,7 +9283,7 @@ speechSynthesis.getVoices();
break; break;
case 'player-left': case 'player-left':
if (!this.lastLocation.playerList.has(gameLog.displayName)) { if (!this.lastLocation.playerList.has(gameLog.displayName)) {
return; break;
} }
var time = 0; var time = 0;
var ref = this.lastLocation.playerList.get(gameLog.displayName); var ref = this.lastLocation.playerList.get(gameLog.displayName);
@@ -9306,7 +9307,7 @@ speechSynthesis.getVoices();
break; break;
case 'portal-spawn': case 'portal-spawn':
if (this.ipcEnabled && this.isGameRunning) { if (this.ipcEnabled && this.isGameRunning) {
return; break;
} }
var entry = { var entry = {
created_at: gameLog.dt, created_at: gameLog.dt,
@@ -9322,32 +9323,57 @@ speechSynthesis.getVoices();
case 'video-play': case 'video-play':
gameLog.videoUrl = decodeURI(gameLog.videoUrl); gameLog.videoUrl = decodeURI(gameLog.videoUrl);
if (this.lastVideoUrl === gameLog.videoUrl) { if (this.lastVideoUrl === gameLog.videoUrl) {
return; break;
} }
this.lastVideoUrl = gameLog.videoUrl; this.lastVideoUrl = gameLog.videoUrl;
this.addGameLogVideo(gameLog, location, userId); this.addGameLogVideo(gameLog, location, userId);
return; break;
case 'video-sync': case 'video-sync':
var timestamp = gameLog.timestamp.replace(/,/g, ''); var timestamp = gameLog.timestamp.replace(/,/g, '');
if (this.nowPlaying.playing) { if (this.nowPlaying.playing) {
this.nowPlaying.offset = parseInt(timestamp, 10); this.nowPlaying.offset = parseInt(timestamp, 10);
} }
return; break;
case 'screenshot': case 'screenshot':
if (!this.isGameRunning || !this.screenshotHelper) return; if (!this.isGameRunning || !this.screenshotHelper) {
break;
var entry = { }
created_at: gameLog.dt, // var entry = {
type: 'Event', // created_at: gameLog.dt,
//location: location, // type: 'Event',
data: "Screenshot Processed: " + gameLog.screenshotPath.replace(/^.*[\\\/]/, ''), // data: `Screenshot Processed: ${gameLog.screenshotPath.replace(
// /^.*[\\/]/,
// ''
// )}`
// };
// database.addGamelogEventToDatabase(entry);
var location = API.parseLocation(this.lastLocation.location);
var metadata = {
application: 'VRCX',
version: 1,
author: {
id: API.currentUser.id,
displayName: API.currentUser.displayName
},
world: {
id: location.worldId,
name: this.lastLocation.name,
instanceId: this.lastLocation.location
},
players: []
}; };
for (var user of this.lastLocation.playerList.values()) {
let world = API.parseLocation(this.lastLocation.location); metadata.players.push({
let worldID = world.worldId; id: user.userId,
displayName: user.displayName
database.addGamelogEventToDatabase(entry); });
AppApi.AddScreenshotMetadata(gameLog.screenshotPath, this.lastLocation.name, worldID, this.screenshotHelperModifyFilename); }
AppApi.AddScreenshotMetadata(
gameLog.screenshotPath,
JSON.stringify(metadata),
location.worldId,
this.screenshotHelperModifyFilename
);
break; break;
case 'api-request': case 'api-request':
var bias = Date.parse(gameLog.dt) + 60 * 1000; var bias = Date.parse(gameLog.dt) + 60 * 1000;
@@ -9357,7 +9383,7 @@ speechSynthesis.getVoices();
this.lastLocation.location === 'traveling' || this.lastLocation.location === 'traveling' ||
bias < Date.now() bias < Date.now()
) { ) {
return; break;
} }
var userId = ''; var userId = '';
try { try {
@@ -9375,7 +9401,7 @@ speechSynthesis.getVoices();
if (userId && !API.cachedUsers.has(userId)) { if (userId && !API.cachedUsers.has(userId)) {
API.getUser({userId}); API.getUser({userId});
} }
return; break;
case 'vrcx': case 'vrcx':
// VideoPlay(PyPyDance) "https://jd.pypy.moe/api/v1/videos/jr1NX4Jo8GE.mp4",0.1001,239.606,"0905 : [J-POP] 【まなこ】金曜日のおはよう 踊ってみた (vernities)" // 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(' ')); var type = gameLog.data.substr(0, gameLog.data.indexOf(' '));
@@ -9388,10 +9414,10 @@ speechSynthesis.getVoices();
} else if (type === 'LSMedia') { } else if (type === 'LSMedia') {
this.addGameLogLSMedia(gameLog, location); this.addGameLogLSMedia(gameLog, location);
} }
return; break;
case 'photon-id': case 'photon-id':
if (!this.isGameRunning || !this.friendLogInitStatus) { if (!this.isGameRunning || !this.friendLogInitStatus) {
return; break;
} }
var photonId = parseInt(gameLog.photonId, 10); var photonId = parseInt(gameLog.photonId, 10);
var ref = this.photonLobby.get(photonId); var ref = this.photonLobby.get(photonId);
@@ -9400,7 +9426,7 @@ speechSynthesis.getVoices();
if (ctx.displayName === gameLog.displayName) { if (ctx.displayName === gameLog.displayName) {
this.photonLobby.set(photonId, ctx); this.photonLobby.set(photonId, ctx);
this.photonLobbyCurrent.set(photonId, ctx); this.photonLobbyCurrent.set(photonId, ctx);
return; break;
} }
} }
var ctx = { var ctx = {
@@ -9410,14 +9436,14 @@ speechSynthesis.getVoices();
this.photonLobbyCurrent.set(photonId, ctx); this.photonLobbyCurrent.set(photonId, ctx);
this.getCurrentInstanceUserList(); this.getCurrentInstanceUserList();
} }
return; break;
case 'notification': case 'notification':
// var entry = { // var entry = {
// created_at: gameLog.dt, // created_at: gameLog.dt,
// type: 'Notification', // type: 'Notification',
// data: gameLog.json // data: gameLog.json
// }; // };
return; break;
case 'event': case 'event':
var entry = { var entry = {
created_at: gameLog.dt, created_at: gameLog.dt,
@@ -9433,7 +9459,7 @@ speechSynthesis.getVoices();
!this.isGameRunning || !this.isGameRunning ||
bias < Date.now() bias < Date.now()
) { ) {
return; break;
} }
AppApi.QuitGame().then((processCount) => { AppApi.QuitGame().then((processCount) => {
if (processCount > 1) { if (processCount > 1) {
@@ -13554,8 +13580,12 @@ speechSynthesis.getVoices();
'VRCX_progressPieFilter' 'VRCX_progressPieFilter'
); );
$app.data.screenshotHelper = configRepository.getBool('VRCX_screenshotHelper'); $app.data.screenshotHelper = configRepository.getBool(
$app.data.screenshotHelperModifyFilename = configRepository.getBool('VRCX_screenshotHelperModifyFilename'); 'VRCX_screenshotHelper'
);
$app.data.screenshotHelperModifyFilename = configRepository.getBool(
'VRCX_screenshotHelperModifyFilename'
);
$app.methods.updateVRConfigVars = function () { $app.methods.updateVRConfigVars = function () {
var notificationTheme = 'relax'; var notificationTheme = 'relax';
@@ -20143,11 +20173,14 @@ speechSynthesis.getVoices();
// Screenshot Helper // Screenshot Helper
$app.methods.saveScreenshotHelper = function () { $app.methods.saveScreenshotHelper = function () {
configRepository.setBool('VRCX_screenshotHelper', this.screenshotHelper); configRepository.setBool(
}; 'VRCX_screenshotHelper',
this.screenshotHelper
$app.methods.saveScreenshotHelperModifyFilename = function () { );
configRepository.setBool('VRCX_screenshotHelperModifyFilename', this.screenshotHelperModifyFilename); configRepository.setBool(
'VRCX_screenshotHelperModifyFilename',
this.screenshotHelperModifyFilename
);
}; };
// YouTube API // YouTube API
+1 -1
View File
@@ -1457,7 +1457,7 @@ html
span.name {{ $t('view.settings.advanced.advanced.screenshot_helper.modify_filename') }} span.name {{ $t('view.settings.advanced.advanced.screenshot_helper.modify_filename') }}
el-tooltip(placement="top" style="margin-left:5px" :content="$t('view.settings.advanced.advanced.screenshot_helper.modify_filename_tooltip')") el-tooltip(placement="top" style="margin-left:5px" :content="$t('view.settings.advanced.advanced.screenshot_helper.modify_filename_tooltip')")
i.el-icon-info i.el-icon-info
el-switch(v-model="screenshotHelperModifyFilename" @change="saveScreenshotHelperModifyFilename") el-switch(v-model="screenshotHelperModifyFilename" @change="saveScreenshotHelper")
div.options-container(v-if="photonLoggingEnabled") div.options-container(v-if="photonLoggingEnabled")
span.header {{ $t('view.settings.advanced.photon.header') }} span.header {{ $t('view.settings.advanced.photon.header') }}
div.options-container-item div.options-container-item
+1 -1
View File
@@ -383,7 +383,7 @@
}, },
"screenshot_helper": { "screenshot_helper": {
"header": "Screenshot Helper", "header": "Screenshot Helper",
"description": "Will store the world ID and world name in the file metadata of any pictures you take in-game.", "description": "Will store the world ID, world name and players in instance inside the file metadata of any pictures you take in-game.",
"description_tooltip": "Unfortunately, windows doesn't support viewing PNG text chunks(few things do) natively, but you can view it using a command-line tool like exiftool, a png chunk inspector, or a hex editor.", "description_tooltip": "Unfortunately, windows doesn't support viewing PNG text chunks(few things do) natively, but you can view it using a command-line tool like exiftool, a png chunk inspector, or a hex editor.",
"enable": "Enable", "enable": "Enable",
"modify_filename": "Modify Filename", "modify_filename": "Modify Filename",