Skip to content

Commit

Permalink
better filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
KentoNishi committed May 28, 2024
1 parent 7fe0e1c commit a3688ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"eslint-plugin-svelte3": "^3.2.0",
"exio": "^0.6.47",
"express": "4.17.3",
"filenamify": "^6.0.0",
"html2canvas": "^1.4.1",
"iframe-translator": "^0.3.5",
"is-dark-color": "^1.2.0",
Expand All @@ -61,5 +62,6 @@
"typescript": "4.3.5",
"vite": "2.9.16",
"vite-plugin-web-extension": "^1.4.0"
}
},
"dependencies": {}
}
2 changes: 1 addition & 1 deletion src/components/YtcFilterWelcome.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<br />
<strong>v{version}:</strong>
<span>
auto-open setting + more.
auto-open, filenames, + more.
</span>
</p>
</div>
Expand Down
22 changes: 17 additions & 5 deletions src/ts/ytcf-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getRandomString } from './chat-utils';
import parseRegex from 'regex-parser';
import { isLangMatch, parseTranslation } from './tl-tag-detect';
import { YTCF_MESSAGEDUMPINFOS_KEY, isLiveTL } from './chat-constants';
import { filenamifyPath } from 'filenamify';

const browserObject = chrome;

Expand Down Expand Up @@ -608,11 +609,22 @@ export const getAllMessageDumpInfoItems = async (): Promise<YtcF.MessageDumpInfo
};

const getTitle = (obj: YtcF.MessageDumpExportItem | undefined): string => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return ((obj?.info?.video?.title) ?? '') || obj?.info?.channel?.name ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
obj?.info?.video?.videoId || obj?.info?.channel?.channelId ||
(obj?.lastEdited !== undefined ? new Date(obj?.lastEdited) : new Date()).toISOString();
// // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
// return ((obj?.info?.video?.title) ?? '') || obj?.info?.channel?.name ||
// // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
// obj?.info?.video?.videoId || obj?.info?.channel?.channelId ||
// (obj?.lastEdited !== undefined ? new Date(obj?.lastEdited) : new Date()).toISOString();
// cut title to 100 characters
const title = (obj?.info?.video?.title || '').slice(0, 100);
const channelName = obj?.info?.channel?.name;
const videoId = obj?.info?.video?.videoId;
const channelId = obj?.info?.channel?.channelId;
const lastEdited = obj?.lastEdited !== undefined ? new Date(obj?.lastEdited) : new Date();
const result = (title ? title : '') + (channelName ? ` - ${channelName}` : (channelId ? ` - ${channelId}` : '')) + (videoId ? ` - ${videoId}` : '');
if (!result) {
return lastEdited.toISOString();
}
return filenamifyPath(result, {replacement: '_'});
};

export const downloadAsJson = async (item: YtcF.MessageDumpInfoItem): Promise<void> => {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,11 @@ filename-reserved-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
integrity sha1-q/c9+rc10EVECr/qLZHzieu/oik=

filename-reserved-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/filename-reserved-regex/-/filename-reserved-regex-3.0.0.tgz#3d5dd6d4e2d73a3fed2ebc4cd0b3448869a081f7"
integrity sha512-hn4cQfU6GOT/7cFHXBqeBg2TbrMBgdD0kcjLhvSQYYwm3s4B6cjvBfb7nBALJLAXqmU5xajSa7X2NnUud/VCdw==

filenamify@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/filenamify/-/filenamify-3.0.0.tgz#9603eb688179f8c5d40d828626dcbb92c3a4672c"
Expand All @@ -2798,6 +2803,13 @@ filenamify@^3.0.0:
strip-outer "^1.0.0"
trim-repeated "^1.0.0"

filenamify@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/filenamify/-/filenamify-6.0.0.tgz#38def94098c62154c42a41d822650f5f55bcbac2"
integrity sha512-vqIlNogKeyD3yzrm0yhRMQg8hOVwYcYRfjEoODd49iCprMn4HL85gK3HcykQE53EPIpX3HcAbGA5ELQv216dAQ==
dependencies:
filename-reserved-regex "^3.0.0"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz"
Expand Down

0 comments on commit a3688ca

Please sign in to comment.