Skip to content

Commit

Permalink
Merge branch 'yargs→clite'
Browse files Browse the repository at this point in the history
  • Loading branch information
jersou committed Oct 13, 2024
2 parents 696b784 + 3cadd3b commit 94c9ebc
Show file tree
Hide file tree
Showing 57 changed files with 514 additions and 6,244 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- BREAKING : `--skip-extract-image-from-mp3``--skip-extract-image-from-mp-3`

## [0.5.10](https://github.com/jersou/studio-pack-generator/compare/v0.5.9...v0.5.10) (2024-10-12)

### Features
Expand Down
92 changes: 47 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,51 +218,53 @@ http://localhost:5555/
## CLI usage
```
deno run -A studio_pack_generator.ts [options] <story path | RSS URL> convert a folder or a RSS URL to Studio pack
Usage: studio-pack-generator [options] [--] <story path | RSS URL> convert a folder or RSS url to Studio pack
Options:
-h, --help Show help [boolean]
-d, --add-delay add 1 second at the beginning and the end of audio files [boolean] [default: false]
-n, --auto-next-story-transition go to next story of group at end of stories [boolean] [default: false]
-b, --select-next-story-at-end select the next story in the menu at end [boolean] [default: false]
-l, --lang the lang used to generate menu and items. Auto detected by default [string]
-t, --night-mode enable night mode : add transitions to an uniq endpoint [boolean] [default: false]
-o, --output-folder zip output folder [string]
-c, --seek-story cut the beginning of stories: 'HH:mm:ss' format or 'N' sec [string]
-v, --skip-audio-convert skip convert audio (and skip increase volume) [boolean] [default: false]
-j, --skip-image-convert skip image convert [boolean] [default: false]
-a, --skip-audio-item-gen skip audio item generation [boolean] [default: false]
-m, --skip-extract-image-from-mp3 skip extract item image from story mp3 [boolean] [default: false]
-i, --skip-image-item-gen skip image item generation [boolean] [default: false]
--image-item-gen-font font used for image item generation [string] [default: "Arial"]
--thumbnail-from-first-item gen thumbnail from first item instead of first chapter [boolean] [default: false]
-s, --skip-not-rss skip all except download RSS files [boolean] [default: false]
--rss-split-length RSS will be split in parts of N length [number] [default: 10]
--rss-split-seasons RSS create different packs per season [boolean] [default: false]
--rss-episode-numbers add RSS episode number to stages [boolean] [default: false]
--rss-min-duration RSS min episode duration [number] [default: 0]
--rss-use-subtitle-as-title Use rss items subtitle as title [boolean] [default: false]
--rss-use-image-as-thumbnail Use rss image (first item with image) as thumbnail [boolean] [default: false]
--use-thumbnail-as-root-image Use thumbnail as 'root' image instead of generated one [boolean] [default: false]
-r, --skip-rss-image-dl skip RSS image download of items [boolean] [default: false]
-w, --skip-wsl disable WSL usage [boolean] [default: false]
-z, --skip-zip-generation only process item generation, don't create zip [boolean] [default: false]
-e, --use-open-ai-tts generate missing audio item with Open AI TTS [boolean] [default: false]
-k, --open-ai-api-key the OpenAI API key [string]
-g, --open-ai-model OpenAi model : tts-1, tts-1-hd [string] [default: "tts-1"]
-p, --open-ai-voice OpenAi voice : alloy, echo, fable, onyx, nova, shimmer [string] [default: "onyx"]
--use-coqui-tts use coqui TTS [boolean] [default: false]
--coqui-tts-model coqui TTS model [string] [default: "tts_models/multilingual/multi-dataset/xtts_v2"]
--coqui-tts-language-idx coqui TTS language_idx [string] [default: "fr"]
--coqui-tts-speaker-idx coqui TTS speaker_idx [string] [default: "Abrahan Mack"]
-x, --extract extract a zip pack (reverse mode) [boolean] [default: false]
-u, --gui open GUI (on localhost:5555) [boolean] [default: false]
--port port of GUI server [number] [default: 5555]
--config-file json config file [string]
--skip-read-tts-cache disable the TTS cache usage [boolean] [default: false]
--skip-write-tts-cache disable the TTS cache write [boolean] [default: false]
--tts-cache-path path to the TTS cache [string] [default: "<SPG dir>/.spg-TTS-cache"]
--custom-script custom script to be used for custom image... handling [string]
-h, --help Show this help [default: false]
--config The json config file [string]
-d, --add-delay add 1 second at the beginning and the end of audio files [default: false]
-n, --auto-next-story-transition go to next story of group at end of stories [default: false]
-b, --select-next-story-at-end select the next story in the menu at end [default: false]
-l, --lang the lang used to generate menu and items. Auto detected by default [default: ""]
-t, --night-mode enable night mode : add transitions to an uniq endpoint [default: false]
-o, --output-folder zip output folder [string]
-c, --seek-story cut the beginning of stories: 'HH:mm:ss' format or 'N' sec [string]
-v, --skip-audio-convert skip convert audio (and skip increase volume) [default: false]
-j, --skip-image-convert skip image convert [default: false]
-a, --skip-audio-item-gen skip audio item generation [default: false]
-m, --skip-extract-image-from-mp-3 skip extract item image from story mp3 [default: false]
-i, --skip-image-item-gen skip image item generation [default: false]
--image-item-gen-font font used for image item generation [default: "Arial"]
--thumbnail-from-first-item gen thumbnail from first item instead of first chapter [default: false]
-s, --skip-not-rss skip all except download RSS files [default: false]
--rss-split-length RSS will be split in parts of N length [default: 10]
--rss-split-seasons RSS create different packs per season [default: false]
--rss-episode-numbers add RSS episode number to stages [default: false]
--rss-min-duration RSS min episode duration [default: 0]
--rss-use-subtitle-as-title Use rss items subtitle as title [default: false]
--rss-use-image-as-thumbnail Use rss image (first item with image) as thumbnail [default: false]
--use-thumbnail-as-root-image Use thumbnail as 'root' image instead of generated one [default: false]
-r, --skip-rss-image-dl skip RSS image download of items [default: false]
-w, --skip-wsl disable WSL usage [default: false]
-z, --skip-zip-generation only process item generation, don't create zip [default: false]
-e, --use-open-ai-tts generate missing audio item with Open AI TTS [default: false]
-k, --open-ai-api-key the OpenAI API key [string]
-g, --open-ai-model OpenAi model : tts-1, tts-1-hd [default: "tts-1"]
-p, --open-ai-voice OpenAi voice : alloy, echo, fable, onyx, nova, shimmer [default: "onyx"]
--use-coqui-tts use coqui TTS [default: false]
--coqui-tts-model coqui TTS model [default: "tts_models/multilingual/multi-dataset/xtts_v2"]
--coqui-tts-language-idx coqui TTS language_idx [default: "fr"]
--coqui-tts-speaker-idx coqui TTS speaker_idx [default: "Abrahan Mack"]
-x, --extract extract a zip pack (reverse mode) [default: false]
-u, --gui open GUI (on localhost:5555) [default: false]
--port port of GUI server [default: 5555]
--skip-read-tts-cache disable the TTS cache usage [default: false]
--skip-write-tts-cache disable the TTS cache write [default: false]
--tts-cache-path path to the TTS cache [default: "<Studio-Pack-Generator dir>/.spg-TTS-cache"]
--custom-script custom script to be used for custom image... handling [string]
--metadata Metadata of the pack [object]
--i-18-n Custom i18n [object]
```

Separate options by spaces, ex :
Expand Down Expand Up @@ -362,8 +364,8 @@ Usage : `--custom-script=<path>`
```
export interface CustomModule {
fetchRssItemImage?: (item: RssItem, opt: ModOptions) => Promise<string>;
fetchRssItemTitle?: (item: RssItem, opt: ModOptions) => Promise<string>;
fetchRssItemImage?: (item: RssItem, opt: StudioPackGenerator) => Promise<string>;
fetchRssItemTitle?: (item: RssItem, opt: StudioPackGenerator) => Promise<string>;
}
```
Expand Down
58 changes: 0 additions & 58 deletions common-types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@david/dax": "jsr:@david/dax@^0.42.0",
"@dbushell/audio-duration": "jsr:@dbushell/audio-duration@^0.6.0",
"@es-toolkit/es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.23.0",
"@jersou/clite": "jsr:@jersou/clite@^0.6.1",
"@jersou/clite": "jsr:@jersou/clite@^0.6.3",
"@libs/xml": "jsr:@libs/xml@^6.0.0",
"@std/assert": "jsr:@std/assert@^1.0.6",
"@std/crypto": "jsr:@std/crypto@^1.0.3",
Expand Down
11 changes: 7 additions & 4 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions extract_pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
SerializedPack,
StageNode,
} from "./serialize/serialize-types.ts";
import type { ModOptions } from "./types.ts";
import { Queue } from "./utils/queue.ts";
import type { StudioPackGenerator } from "./studio_pack_generator.ts";

type StageType = "STORY" | "FOLDER" | "ITEM";
export class PackExtractor {
Expand All @@ -30,7 +30,7 @@ export class PackExtractor {
transitionCount = new Map<string, number>();
nightAction?: string;
questions = new Set<string>();
constructor(opt: ModOptions) {
constructor(opt: StudioPackGenerator) {
this.packPath = opt.storyPath;
this.outputPath = opt.outputFolder ?? opt.storyPath + "-extract";
}
Expand Down Expand Up @@ -240,10 +240,10 @@ export class PackExtractor {
}

if (import.meta.main) {
// await extractPack({ storyPath: "test_data/zip/2-full.zip" } as ModOptions);
// await extractPack({ storyPath: "test_data/zip/2-full.zip" } as StudioPackGenerator);
const opt = {
storyPath: Deno.args[0] ??
"test_data/zip/2-full.zip",
} as ModOptions;
} as StudioPackGenerator;
await (new PackExtractor(opt).extractPack());
}
26 changes: 11 additions & 15 deletions gen_pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import { bgRed } from "@std/fmt/colors";
import { basename, join } from "@std/path";
import {
checkRunPermission,
cleanOption,
convertToImageItem,
fileImageItemRegEx,
folderImageItemRegEx,
getNightModeAudioItem,
isFolder,
} from "./utils/utils.ts";
import { getLang, initI18n } from "./utils/i18n.ts";
import { convertImageOfFolder } from "./utils/convert_image.ts";
import { fileImageItemRegEx } from "./utils/utils.ts";
import type { ModOptions } from "./types.ts";
import $ from "@david/dax";
import type { StudioPackGenerator } from "./studio_pack_generator.ts";

async function genThumbnail(
folder: Folder,
Expand Down Expand Up @@ -60,9 +59,10 @@ async function genThumbnail(
}
}

export async function generatePack(opt: ModOptions) {
export async function generatePack(opt: StudioPackGenerator) {
if (
opt.nightMode && (opt.autoNextStoryTransition || opt.selectNextStoryAtEnd)
opt.nightMode &&
(opt.autoNextStoryTransition || opt.selectNextStoryAtEnd)
) {
console.log(
bgRed(
Expand Down Expand Up @@ -92,13 +92,7 @@ export async function generatePack(opt: ModOptions) {
await genThumbnail(folder, storyPath, opt.thumbnailFromFirstItem);
}
if (!opt.skipImageItemGen || !opt.skipAudioItemGen) {
await genMissingItems(
folder,
lang,
true,
storyPath,
opt,
);
await genMissingItems(folder, lang, true, storyPath, opt);
folder = await fsToFolder(storyPath, false);
}
if (!opt.skipAudioConvert) {
Expand All @@ -123,7 +117,9 @@ export async function generatePack(opt: ModOptions) {
nightModeAudioItemName,
});
const assets = getAssetsPaths(serializedPack, folder);
const date = new Date().toISOString().substring(0, 19)
const date = new Date()
.toISOString()
.substring(0, 19)
.replace("T", "--")
.replaceAll(":", "-");
const zipPath = opt.outputFolder
Expand All @@ -138,14 +134,14 @@ export async function generatePack(opt: ModOptions) {
}
}
await $.path(`${storyPath}/0-config.json`).writeText(
JSON.stringify(cleanOption(opt), null, " "),
JSON.stringify(opt, null, " "),
);
}
}

export async function getMetadata(
storyPath: string,
opt: ModOptions,
opt: StudioPackGenerator,
): Promise<Metadata> {
const metadataPath = `${storyPath}/metadata.json`;
if (await exists(metadataPath)) {
Expand Down
Loading

0 comments on commit 94c9ebc

Please sign in to comment.