Skip to content

Commit

Permalink
Merge pull request #35 from kamakiri01/add-image-download-log-parser
Browse files Browse the repository at this point in the history
add image download log parser
  • Loading branch information
kamakiri01 authored Jan 27, 2024
2 parents 1f085be + 15108ea commit 5f934ca
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ChangeLog

## 7.2.0
- 画像ダウンロードのログをパースできるよう変更

## 7.1.1
- `--import` オプション指定時にDB更新が二重に実行されていた問題を修正

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vrchat-activity-viewer",
"version": "7.1.1",
"version": "7.2.0",
"description": "VRChat log viewer",
"main": "lib/index.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/app/showActivityLog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActivityLog, ActivityType, MoveActivityLog, EnterActivityLog, SendNotificationActivityLog, ReceiveNotificationActivityLog, AuthenticationActivityLog, CheckBuildActivityLog, ShutdownActivityLog, ReceiveNotificationDetails, VideoPlayActivityLog, USharpVideoStartedActivityLog, SDK2PlayerStartedActivityLog, ExitActivityLog } from "..";
import { ImageDownloadActivityLog } from "../type/activityLogType/imageDownloadType";
import { RemoveNotificationActivityLog, RemoveNotificationDetails } from "../type/activityLogType/removeType";
import { TopazPlayActivityLog } from "../type/activityLogType/videoPlayType";
import { ViewerAppParameterObject } from "../type/AppConfig";
Expand Down Expand Up @@ -101,6 +102,8 @@ function messageGenerator(e: ActivityLog, verbose?: boolean) {
return generateSDK2PlayerStartedMessage(e as SDK2PlayerStartedActivityLog);
case ActivityType.TopazPlay:
return generateTopazPlayMessage(e as TopazPlayActivityLog);
case ActivityType.ImageDownload:
return generateImageDownloadMessage(e as ImageDownloadActivityLog);
}
}

Expand Down Expand Up @@ -253,3 +256,8 @@ function generateTopazPlayMessage(log: TopazPlayActivityLog): string {
const message = "topazchat play " + log.url;
return message;
}

function generateImageDownloadMessage(log: ImageDownloadActivityLog): string {
const message = "image Download " + log.url;
return message;
}
3 changes: 2 additions & 1 deletion src/type/activityLogType/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const ActivityType = {
VideoPlay: "videoPlay", // 動画再生
TopazPlay: "topazPlay", // TopazChatによる動画再生
USharpVideoStarted: "usharpVideoStarted", // USharpVideoの動画リクエスト
SDK2PlayerStarted: "sdk2PlayerStarted" // SDK2プレイヤーの動画リクエストと再生
SDK2PlayerStarted: "sdk2PlayerStarted", // SDK2プレイヤーの動画リクエストと再生
ImageDownload: "imageDownload" // 画像ダウンロード
} as const;
export type ActivityType = typeof ActivityType[keyof typeof ActivityType];

Expand Down
6 changes: 6 additions & 0 deletions src/type/activityLogType/imageDownloadType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ActivityLog, ActivityType } from "./common";

export interface ImageDownloadActivityLog extends ActivityLog {
activityType: typeof ActivityType.ImageDownload;
url: string;
}
12 changes: 12 additions & 0 deletions src/util/parseVRChatLog/activityLogGenerator/imageDownload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ActivityType } from "../../..";
import { ImageDownloadActivityLog } from "../../../type/activityLogType/imageDownloadType";

export function createImageDownloadActivityLog(utcTime: number, message: string): ImageDownloadActivityLog {
const reg = /\[Image Download\] Attempting to load image from URL '(.+)'/.exec(message)!;
const activity: ImageDownloadActivityLog = {
date: utcTime,
activityType: ActivityType.ImageDownload,
url: reg[1],
};
return activity;
}
7 changes: 6 additions & 1 deletion src/util/parseVRChatLog/parseVRChatLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createSendNotificationActivityLog } from "./activityLogGenerator/send";
import { createShutdownActivityLog } from "./activityLogGenerator/shutdown";
import { parseMessageBodyFromLogLine, parseSquareBrackets } from "./parseUtil";
import { parseUserDataMessage } from "./userDataGenerator";
import { createImageDownloadActivityLog } from "./activityLogGenerator/imageDownload";

/**
* ログファイル全体のパース結果
Expand Down Expand Up @@ -72,7 +73,8 @@ const JudgeLogType = {
isUSharpVideoStarted: (message: string) => { return message.indexOf("[USharpVideo] Started video load for URL:") !== -1 },
isSDK2PlayerVideoStarted: (message: string) => { return /User (.+) added URL (http.+)/.test(message) },
isTopazPlay: (message: string) => { return message.indexOf("[Video Playback] Resolving URL") !== -1 },
isFetchUserData: (message: string) => { return message.indexOf("Fetched APIUser") !== -1 }
isFetchUserData: (message: string) => { return message.indexOf("Fetched APIUser") !== -1 },
isImageDownload: (message: string) => { return message.indexOf("[Image Download] Attempting") !== -1 }
}

// ログ1行のパース結果
Expand Down Expand Up @@ -139,6 +141,9 @@ function parseLogLineToActivityOrUserData(
} else if (JudgeLogType.isFetchUserData(message)) {
// Fetched APIUser
userData = parseUserDataMessage(logLines[index+1])!;
} else if (JudgeLogType.isImageDownload(message)) {
// image Download
activityLog = createImageDownloadActivityLog(utcTime, message);
}

if (activityLog) return { data: activityLog, type: "ActivityLog" };
Expand Down

0 comments on commit 5f934ca

Please sign in to comment.