Skip to content

Commit 71e469a

Browse files
committed
🎨 [annict] armにないデータでも大まかに引っ張られるように
1 parent b6f1c31 commit 71e469a

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

src/miraktest-annict/annictAPI.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios from "axios"
22
import { MeProgramsGetRequestQuery } from "./annict.js/types/me/programs"
3+
import { WorksGetRequestQuery } from "./annict.js/types/works"
34
import { getSdk } from "./gql"
45
import { GraphQLClient } from "./graphqlRequestLoader"
56

@@ -15,6 +16,21 @@ export class AnnictRESTAPI {
1516
})
1617
}
1718

19+
async getWorks(params: Partial<WorksGetRequestQuery>) {
20+
return this.client.get<{
21+
works: {
22+
id: number
23+
title: string
24+
}[]
25+
}>("works", {
26+
params: {
27+
...params,
28+
filter_title: params.filter_title?.join(","),
29+
filter_season: params.filter_season?.join(","),
30+
},
31+
})
32+
}
33+
1834
async getMyPrograms(params: MeProgramsGetRequestQuery) {
1935
return this.client.get<{
2036
next_page: 2

src/miraktest-annict/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const ANNICT_META = {
3636
id: ANNICT_PLUGIN_ID,
3737
name: "Annict",
3838
author: "ci7lus",
39-
version: "0.3.5",
39+
version: "0.3.6",
4040
description: "視聴中の番組をAnnictで記録する",
4141
authorUrl: "https://github.com/ci7lus",
4242
url: "https://github.com/ci7lus/miraktest-plugins/tree/master/src/miraktest-annict",

src/miraktest-annict/findWork.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ import { ARM } from "./types"
1010
dayjs.extend(isSameOrAfter)
1111
dayjs.extend(isSameOrBefore)
1212

13+
export const getAnnictSeasonByMonth = (n: number) => {
14+
if (n <= 3) {
15+
return "winter"
16+
} else if (n <= 6) {
17+
return "spring"
18+
} else if (n <= 9) {
19+
return "summer"
20+
} else {
21+
return "autumn"
22+
}
23+
}
24+
1325
export const detectProgramInfo = async ({
1426
rest,
1527
channel,
@@ -65,6 +77,36 @@ export const detectProgramInfo = async ({
6577
number: syobocalProgram.Count,
6678
},
6779
}
80+
} else {
81+
const workReq = await SyobocalAPI.TitleLookup({
82+
TID: syobocalProgram.TID.toString(),
83+
})
84+
const syobocalWork = workReq.slice(0).shift()
85+
if (!syobocalWork) {
86+
return
87+
}
88+
const season = getAnnictSeasonByMonth(syobocalWork.FirstMonth)
89+
for (const term of [
90+
syobocalWork.Title,
91+
syobocalWork.TitleYomi,
92+
syobocalWork.ShortTitle,
93+
syobocalWork.TitleEN,
94+
].filter((s): s is string => !!s)) {
95+
const annictWorkSearchReq = await rest.getWorks({
96+
filter_title: [term],
97+
filter_season: [`${syobocalWork.FirstYear}-${season}`],
98+
})
99+
const annictWork = annictWorkSearchReq.data.works.slice(0).shift()
100+
if (annictWork) {
101+
return {
102+
annictId: annictWork.id,
103+
episode: {
104+
title: syobocalProgram.SubTitle,
105+
number: syobocalProgram.Count,
106+
},
107+
}
108+
}
109+
}
68110
}
69111
} else {
70112
console.warn("番組が見つかりませんでした")

src/miraktest-annict/syobocalAPI.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ type ProgLookupResponse =
4444
}
4545
}
4646

47+
type TitleItem = {
48+
Title: string
49+
ShortTitle?: string
50+
TitleYomi?: string
51+
TitleEN?: string
52+
FirstYear: number
53+
FirstMonth: number
54+
}
55+
56+
type TitleLookupResponse =
57+
| {
58+
TitleItems: {
59+
TitleItem: TitleItem[]
60+
}
61+
Result: {
62+
Code: 200
63+
Message: ""
64+
}
65+
}
66+
| {
67+
TitleItems: {
68+
TitleItem: TitleItem[]
69+
}
70+
Result: {
71+
Code: 404
72+
Message: "条件に一致するデータは存在しません"
73+
}
74+
}
75+
4776
export class SyobocalAPI {
4877
static async ProgLookup(params: {
4978
TID?: string
@@ -72,4 +101,24 @@ export class SyobocalAPI {
72101
return [ProgLookupResponse.ProgItems.ProgItem].flat()
73102
})
74103
}
104+
static async TitleLookup(params: { TID?: string }) {
105+
return client
106+
.get<string>("db.php", {
107+
params: {
108+
Command: "TitleLookup",
109+
...params,
110+
},
111+
})
112+
.then((r) => {
113+
const {
114+
TitleLookupResponse,
115+
}: {
116+
TitleLookupResponse: TitleLookupResponse
117+
} = new XMLParser().parse(r.data)
118+
if (TitleLookupResponse.Result.Code === 404) {
119+
return []
120+
}
121+
return [TitleLookupResponse.TitleItems.TitleItem].flat()
122+
})
123+
}
75124
}

0 commit comments

Comments
 (0)