Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
xrz-cloud committed Jul 30, 2024
0 parents commit f791e25
Show file tree
Hide file tree
Showing 32 changed files with 8,708 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3,
"modules": false
}
]
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.vscode
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# L1

A tool to parse the title of bangumi etc. Its name and function logic originate from L1(LabelFirstTitleParser) of open-ani/ani.
这是一个解析番剧标题的工具,它的名字和功能逻辑源自于 [open-ani/ani](https://github.com/open-ani/ani) 中的L1(LabelFirstTitleParser)。

## Usage 使用

[npm](https://www.npmjs.com/package/@bili-vd-bak/l1)
[jsr](https://jsr.io/@bvd/l1)

The lib is written in TypeScript, and the usage is detailed in the code hint after import.
本库使用TypeScript编写,使用方法详见导入后的代码提示。

```sh
pnpm add @bvd/l1
```

```ts
import L1 from '@bvd/l1';

const result = L1("[DBD-Raws][约会大作战 第一季/Date a Live S1/デート・ア・ライブ][导演剪辑版/Director's Cut/ディレクターズカット版][01-12TV全集+OAD][1080P][BDRip][HEVC-10bit][简繁外挂][FLAC][MKV]");

console.log(result);
```

## Contribution 贡献

Welcome Issue or PR.
欢迎提交Issue和Pull Request。

Logic function are also suggested to be submitted to the upstream open-ani/Ani.
逻辑功能建议同时向上游 open-ani/Ani 提交。

## LICENSE 许可证

Released under the GUN 3.0 License.
本库采用 GNU 3.0 许可证发布。
23 changes: 23 additions & 0 deletions __test__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import main from "../src";

const test_list = [
"[DBD-Raws][约会大作战 第一季/Date a Live S1/デート・ア・ライブ][导演剪辑版/Director's Cut/ディレクターズカット版][01-12TV全集+OAD][1080P][BDRip][HEVC-10bit][简繁外挂][FLAC][MKV]",
"【喵萌奶茶屋】★07月新番★[败犬女主角也太多了! / 败犬女主太多了! / 负けヒロインが多すぎる! / Make Heroine ga Oosugiru!][02][1080p][简日双语][招募翻译时轴]",
"[LoliHouse] 关于我转生变成史莱姆这档事 第三季 / Tensei Shitara Slime Datta Ken 3rd Season - 16(64) [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]",
"[DBD-Raws][泽塔奥特曼/Ultraman Z/ウルトラマンゼット][01-25TV全集+特别篇+特典映像][1080P][BDRip][HEVC-10bit][FLAC][MKV]",
"[DBD-Raws][进击的巨人 最终季/Shingeki no Kyojin: The Final Season/進撃の巨人 The Final Season][01-28TV全集+完结篇+特典映像][1080P][BDRip][HEVC-10bit][简繁日双语外挂][FLAC][MKV]",
"[.subbers project] 剧场版 紫罗兰永恒花园 / 劇場版 ヴァイオレット・エヴァーガーデン / Violet Evergarden the Movie [BDRip][4K HDR+2K SDR][简繁日字幕内封](附BD及剧场扫图、相关音乐、小说翻译等)",
"【F宅】吹响吧!上低音号 SP特典合集 01-07 简 1080P MP4",
];

describe("L1", () => {
test("main", () => {
test_list.forEach((t) => {
const r = main(t);
console.log(`Testing ${t}`);
console.log(r);
console.log(r.episodeRange);
console.log("=============");
});
});
});
74 changes: 74 additions & 0 deletions dist/EpisodeRange.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { EpisodeSort } from "./EpisodeSort";
export declare class EpisodeRange {
type: "Empty" | "Single" | "Range" | "Combined" | "Season";
ep: {
value?: string;
start?: string;
end?: string;
first?: EpisodeRange;
second?: EpisodeRange;
rawNumber?: number;
};
/**
* 是否知道具体集数
*/
get isKnown(): boolean;
constructor(type: "Empty" | "Single" | "Range" | "Combined" | "Season", ep: {
value?: string;
start?: string;
end?: string;
first?: EpisodeRange;
second?: EpisodeRange;
rawNumber?: number;
});
getIns(): Empty | Single | Range | Combined | Season;
/**
* 已知的集数列表. 若未知 (例如 [unknownSeason]), 则返回空序列.
*/
get knownSorts(): EpisodeSort[];
toString(): string;
}
declare class Empty {
knownSorts: EpisodeSort[];
toString(): string;
}
declare class Single {
value: EpisodeSort;
constructor(value: EpisodeSort);
get knownSorts(): EpisodeSort[];
toString(): string;
}
declare class Range {
start: EpisodeSort;
end: EpisodeSort;
constructor(start: EpisodeSort, end: EpisodeSort);
get knownSorts(): EpisodeSort[];
toString(): string;
}
declare class Combined {
first: EpisodeRange;
second: EpisodeRange;
constructor(first: EpisodeRange, second: EpisodeRange);
get knownSorts(): EpisodeSort[];
toString(): string;
}
/**
* 季度全集, 但是不知道具体包含哪些集数
*/
export declare class Season {
/**
* 第几季
*/
rawNumber: number;
isKnown: boolean;
constructor(
/**
* 第几季
*/
rawNumber: number);
get numberOrZero(): number;
get numberOrNull(): number | null;
get knownSorts(): EpisodeSort[];
toString(): string;
}
export {};
56 changes: 56 additions & 0 deletions dist/EpisodeSort.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
declare class Normal {
number: number;
constructor(number: number);
get raw(): string;
get isPartial(): boolean;
toString(): string;
}
declare class Special {
raw: string;
constructor(raw: string);
get number(): number | null;
toString(): string;
}
/**
* 剧集序号, 例如 "01", "24.5", "OVA".
*
* - [Normal] 代表普通正片剧集, 例如 "01", "24.5". 注意, 只有整数和 ".5" 的浮点数会被解析为 Normal 类型.
* - [Special] 代表任何其他剧集, 统称为特殊剧集, 例如 "OVA", "SP".
*
*
* 在使用 [EpisodeSort] 时, 建议根据用途定义不同的变量名:
* - `val episodeSort: EpisodeSort`: 在系列中的集数, 例如第二季的第一集为 26
* - `val episodeEp: EpisodeSort`: 在当前季度中的集数, 例如第二季的第一集为 01
*
* @see EpisodeRange
*/
export declare class EpisodeSort {
/**
* "1", "1.5", "SP". 对于小于 10 的序号, 前面没有 "0".
*
* @see toString
*/
raw: string;
constructor(
/**
* "1", "1.5", "SP". 对于小于 10 的序号, 前面没有 "0".
*
* @see toString
*/
raw: string);
get Ins(): Normal | Special;
get isNormal(): boolean;
get isPartial(): boolean;
/**
* 若是普通剧集, 则返回序号, 例如 ``, 否则返回 null.
*/
get number(): number | null;
/**
* 返回该剧集的人类易读名称.
*
* 为普通剧集补零了的字符串.
* 例如 1 -> "01", 1.5 -> "1.5", SP -> "SP".
*/
toString(): string;
}
export {};
4 changes: 4 additions & 0 deletions dist/FrameRate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface FrameRate {
value: number;
}
export declare function tryParse(text: string): FrameRate | null;
5 changes: 5 additions & 0 deletions dist/MediaOrigin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface MediaOrigin {
id: string;
otherNames?: string[];
}
export declare function tryParse(text: string): MediaOrigin | null;
7 changes: 7 additions & 0 deletions dist/Resolution.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Resolution {
id: string;
size: number;
otherNames: string[];
displayName: string;
}
export declare function tryParse(text: string): Resolution | null;
22 changes: 22 additions & 0 deletions dist/SubtitleLanguage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
interface Ret_Templete {
id: string;
displayName: string;
isChinese: boolean;
}
export declare class SubtitleLanguage {
id: string;
isChinese: boolean;
displayName: string;
constructor(m: Ret_Templete);
toString(): string;
}
export declare const ret_templete: {
CHC: SubtitleLanguage;
CHS: SubtitleLanguage;
CHT: SubtitleLanguage;
JPN: SubtitleLanguage;
ENG: SubtitleLanguage;
ERR: SubtitleLanguage;
};
export declare function match(title: string): SubtitleLanguage[];
export {};
15 changes: 15 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as SubtitleLanguage from "./SubtitleLanguage";
import * as Resolution from "./Resolution";
import * as FrameRate from "./FrameRate";
import * as MediaOrigin from "./MediaOrigin";
import * as EpisodeRange from "./EpisodeRange";
interface Builder {
tags: string[];
subtitleLanguages: SubtitleLanguage.SubtitleLanguage[];
resolution: Resolution.Resolution;
frameRate: FrameRate.FrameRate;
mediaOrigin: MediaOrigin.MediaOrigin;
episodeRange: EpisodeRange.EpisodeRange;
}
export default function main(title: string): Builder;
export {};
Loading

0 comments on commit f791e25

Please sign in to comment.