Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
6d1dc0c
Update readme.md
vipzero Apr 27, 2022
0176754
Create LICENSE
vipzero Apr 28, 2022
66fdf91
Merge pull request #18 from vipzero/add-license-1
vipzero Apr 28, 2022
c5b4e80
update sample
vipzero Apr 28, 2022
5482df4
refactor
vipzero Apr 28, 2022
11af869
add alogrithm description
vipzero Apr 29, 2022
484f1f5
add archive script
vipzero Apr 30, 2022
ce9c312
add batch
vipzero May 1, 2022
3e536d1
add ee
vipzero May 1, 2022
b8d9e6f
add reset book count
vipzero May 2, 2022
ab446b4
add pefo
vipzero May 2, 2022
da5d24c
add tests
vipzero May 2, 2022
afd6d4c
add esbuild
vipzero May 2, 2022
c8748b2
add ee
vipzero May 2, 2022
8c36f03
update normalize
vipzero May 2, 2022
297a364
add book init
vipzero May 2, 2022
f52da9b
add ee
vipzero May 3, 2022
18e93ff
fix time
vipzero May 3, 2022
b31b4a1
add ee
vipzero May 4, 2022
52b12eb
update normalize
vipzero May 4, 2022
4bcc725
update algo
vipzero May 4, 2022
9ab2243
add word
vipzero May 4, 2022
c8c678b
update search word
vipzero May 4, 2022
a07befb
update random
vipzero May 6, 2022
ba47c59
update seed algo
vipzero May 6, 2022
ff9cc52
add doc
vipzero May 6, 2022
9251e33
add words
vipzero May 6, 2022
d1017fa
add ep word to search
vipzero May 7, 2022
1119ec5
update normalize
vipzero May 8, 2022
3b9f7fd
update snap
vipzero May 8, 2022
c0e1fa9
add ee
vipzero Jun 8, 2022
8fac032
add ee
vipzero Aug 5, 2022
ba5c10d
update ee
vipzero Aug 5, 2022
0bc42a0
add emol
vipzero Aug 8, 2022
efe0070
fix emol service
vipzero Aug 8, 2022
a1e322c
fix emol text
vipzero Aug 8, 2022
6e54384
update
vipzero Aug 8, 2022
a777975
add filter
vipzero Aug 11, 2022
57ff716
add keep phatse
vipzero Aug 11, 2022
b555420
add wikipedia
vipzero Aug 11, 2022
3f4c265
update wikipedia
vipzero Aug 12, 2022
c9244a6
update
vipzero Aug 13, 2022
c3d0ef0
add filtering
vipzero Aug 16, 2022
537b320
valid
vipzero Dec 9, 2022
03ebe0f
udpate docs
vipzero Dec 21, 2022
43b7645
add restore
vipzero Dec 23, 2022
2052446
add normalize case
vipzero Dec 24, 2022
d2cb41d
update query
vipzero Dec 26, 2022
5e843d3
update query
vipzero Dec 26, 2022
e1e57cb
add black list
vipzero Dec 27, 2022
f1fbf5d
swithc mode
vipzero Dec 28, 2022
55e00f3
catch imgmin error
vipzero Dec 28, 2022
2dc72c3
fix to buffer
vipzero Dec 28, 2022
1fe6752
non-skip imagemin failed
vipzero Dec 28, 2022
0f76a42
remove emol
vipzero Dec 28, 2022
8591eb3
update sotrage url
vipzero Dec 28, 2022
c2aaa98
fix
vipzero Dec 28, 2022
12acb6d
silent error
vipzero Dec 29, 2022
902cb12
add word counting additionals
vipzero Dec 29, 2022
b612e5f
update word count algo
vipzero Dec 29, 2022
ca23861
fix parser
vipzero Dec 29, 2022
a59c362
add replacement batch
vipzero Dec 29, 2022
db184dc
fix time filter
vipzero Dec 29, 2022
2f05c35
add convert tags
vipzero Dec 29, 2022
70a7379
add timeTag
vipzero Dec 29, 2022
2920ad3
parse creators
vipzero Dec 29, 2022
a3d3128
add Timeout
vipzero Dec 30, 2022
45ddda6
update file-type detection
vipzero Jan 1, 2023
306396c
remove log
vipzero Jan 1, 2023
9755cf9
add ee
vipzero Jan 1, 2023
362a3e5
update image optimaze
vipzero Jan 1, 2023
666b0fa
fix test
vipzero Jan 2, 2023
da4aa3d
add artwork to imageLinks
vipzero Jan 2, 2023
d666e53
fix download
vipzero Jan 2, 2023
ee96ada
fix tests
vipzero Jan 2, 2023
08052d3
refactor
vipzero Jan 2, 2023
02b975e
update warnDec logger
vipzero Jan 2, 2023
383a194
update performance log
vipzero Jan 2, 2023
7824f80
fix catch
vipzero Jan 3, 2023
d3bc2fb
fix doc
vipzero Apr 28, 2023
4fafae5
fix archive
vipzero Apr 28, 2023
538df59
add jimp timeout
vipzero Apr 28, 2023
5b39895
add infos
vipzero Apr 28, 2023
a35e5e5
update compact algo
vipzero Apr 28, 2023
58f8567
add shape timeout
vipzero Apr 28, 2023
f3300bf
add self download timeout
vipzero Apr 28, 2023
67c459a
fix promise
vipzero Apr 28, 2023
a071bce
change log timing
vipzero Apr 29, 2023
bd31168
update new table logger
vipzero Apr 30, 2023
5ae6182
update marker
vipzero Apr 30, 2023
4b3405c
add id shorter
vipzero Apr 30, 2023
65296d7
add print
vipzero Apr 30, 2023
f04dd3b
remove size log
vipzero Apr 30, 2023
45edd2c
off printer
vipzero Apr 30, 2023
e9076ac
update image table log
vipzero Apr 30, 2023
190ba8a
fix logs
vipzero Apr 30, 2023
bb6e641
refactor
vipzero Apr 30, 2023
c911e40
add fix count script
vipzero May 2, 2023
c263e3d
add fix history 4
vipzero May 5, 2023
0acf2fa
safe
vipzero May 5, 2023
bb9a6ac
add empty search word
vipzero May 6, 2023
274ede4
update empty word
vipzero May 6, 2023
5e8d675
fix empty search word
vipzero May 6, 2023
11cfc14
fix ignore search not query enable
vipzero May 6, 2023
a858e59
fix ignore pattenr
vipzero May 6, 2023
3bc8daf
Update all non-major dependencies
renovate[bot] May 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .envrc.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export SPOTIFY_CLIENT_ID=""
export SPOTIFY_CLIENT_SECRET=""

export MUSIXMATCH_API_KEY=""
export EVENT_ID=""
export STRAGE_URL=""
export EVENT_ID="todo"
export STORAGE_ID=""
export STORAGE_URL=""

export THREAD_TITLE_WORD=""
export EMPTY_MODE_SEARCH_WORD="探偵 クイズ 推理 アニメ " # クイズなど

export THREAD_TITLE_WORD="ならアニソン"
export DIRECT_MODE=0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 vipzero

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
97 changes: 97 additions & 0 deletions maintanace-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## メンテフロー

### Event 作成

```
$ vi .envrc EVENT_ID
EVENT_ID=xxxxxx
$ yarn setup # EVENT_ID から動作
$ yarn setup:anison
```

```mermaid
sequenceDiagram

participant you_ as You
participant envB as BackEnd環境設定
participant appB as haikei-server
participant fbdb as Firestore
participant andb as AnisonDb

you_ ->> envB : .envrc EVENT_ID 更新
you_ ->> appB : yarn setup
envB ->> appB : EVENT_ID
appB ->> fbdb : event 追加
```

```mermaid
sequenceDiagram

participant you_ as You
participant envB as BackEnd環境設定 data/*.csv
participant appB as haikei-server
participant andb as AnisonDb

you_ ->> appB : yarn setup:anison
appB ->> andb : get
andb ->> envB : 同期
```

### FrontEnd のセットアップ

rekka-haikei の `src/config/incdex.ts`

- イベント追加 `xxxxxx`
- 終了時間指定

### サーバー起動

```mermaid

sequenceDiagram

participant you_ as You
participant appB as haikei-server
participant fbhi as Firestore/hist
participant fbco as Firestore/counts
participant strm as Stream

you_ ->> appB : yarn start
appB ->> fbhi : get [eventId]
fbhi ->> appB : lastSong
appB ->> fbco : get [eventId]
fbco ->> appB : all cache

appB ->> strm : subscribe

```

### 動作中

```mermaid

sequenceDiagram

participant strm as Stream
participant appB as haikei-server
participant fbhi as Firestore/hist
participant fbso as Firestore/song
participant fbco as Firestore/counts


strm ->> appB : icy
appB ->> appB : 解析
appB ->> fbhi : update
appB ->> fbso : push
appB ->> fbco : update

```

### 終了

アーカイブする。
イベント中の履歴は Firestore からロードするが、アーカイブ後は履歴を Cloud Storage からダウンロードするようになる。

```
yarn close:archive {event_ia}
```
43 changes: 28 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,45 @@
"type": "commonjs",
"dependencies": {
"@types/jest": "^27.4.1",
"axios": "0.21.1",
"axios": "0.27.2",
"chalk": "4.1.2",
"chch": "2.8.0",
"cheerio": "1.0.0-rc.10",
"csv-parse": "4.16.0",
"date-fns": "2.23.0",
"file-type": "16.5.3",
"got": "11.8.2",
"cheerio": "1.0.0-rc.12",
"csv-parse": "4.16.3",
"csv-stringify": "^6.0.5",
"date-fns": "2.30.0",
"esbuild": "^0.17.0",
"esbuild-register": "^3.3.2",
"file-type": "16.5.4",
"got": "11.8.6",
"iconv-lite": "0.6.3",
"icy": "2.1.0",
"jaco": "^4.0.0",
"jest": "^27.5.1",
"jimp": "^0.22.0",
"jptext-to-emoji": "0.3.0",
"luxon": "^3.3.0",
"node-spotify-api": "1.1.1",
"sharp": "0.28.3"
"sharp": "0.32.1"
},
"scripts": {
"start": "ts-node src/index.ts",
"start": "yarn start:esbuild",
"start:esbuild": "node -r esbuild-register src/index.ts",
"start:ts-node": "ts-node src/index.ts",
"get_history": "curl http://w.hoshinoa.me:8000/play.txt -o data/history.txt",
"setup": "ts-node scripts/setupEvent.ts",
"setup:ee": "ts-node scripts/setupEasterEgg.ts",
"setup:anison": "./scripts/updateAnisonDb.mjs",
"close:archive": "ts-node ./scripts/archiveEvent/index.ts",
"import2": "ts-node scripts/batch/importHistoryFromCells.ts",
"map:watch": "./scripts/hourly-yarn-map.sh",
"map": "yarn map-load-thread && yarn map-save",
"map-load-thread": "ts-node scripts/loadThreads.ts",
"map-save": "ts-node scripts/makePostCountMap.ts",
"fix:counts": "ts-node scripts/batch/migrateWordCounts.ts",
"active-thread": "chch dump-threads |jq -r '.threads[] | \"\\(.url),\\(.title)\"' |grep \"ならアニソン\"",
"test": "jest"
"test": "jest",
"test:type": "npx tsc --noEmit"
},
"devDependencies": {
"@swc/core": "^1.2.168",
Expand All @@ -39,18 +51,19 @@
"@types/imagemin": "7.0.1",
"@types/imagemin-gifsicle": "7.0.1",
"@types/imagemin-mozjpeg": "8.0.1",
"@types/luxon": "^3.3.0",
"@types/node": "17.0.24",
"@types/sharp": "0.28.5",
"@typescript-eslint/eslint-plugin": "4.29.1",
"@typescript-eslint/parser": "4.29.1",
"eslint": "8.13.0",
"firebase-admin": "9.11.0",
"@typescript-eslint/eslint-plugin": "5.21.0",
"@typescript-eslint/parser": "5.21.0",
"eslint": "8.14.0",
"firebase-admin": "9.12.0",
"imagemin": "7.0.1",
"imagemin-gifsicle": "7.0.0",
"imagemin-mozjpeg": "9.0.0",
"imagemin-pngquant": "9.0.2",
"rimraf": "3.0.2",
"ts-node": "10.7.0",
"typescript": "4.6.3"
"ts-node": "10.9.1",
"typescript": "4.9.5"
}
}
25 changes: 23 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,29 @@ iTunes API (認証なし)
- spotify: アートワーク・アルバム名・(邦楽・アニソンあまり取れないため)
- musixmatch: アートワーク・アルバム名・歌詞の出だし(有料 API では FULL)

調整・アルゴリズム関係

## 検索文字生成部分や調整しているアルゴリズムなど
https://github.com/vipzero/haikei-server/wiki/algo
## 画像検索文字列の生成部分

方針

- 関連性のあるものが出るように
- meme やキャプ画像が出るように
- 平凡な公式タイトル画像以外が出るように

コード

https://github.com/vipzero/haikei-server/blob/main/src/utils/makeSearchWord.ts

## 画像選択

imagemin などで Optimize 後のメタデータで
ソートして上から 3 つ

コード

https://github.com/vipzero/haikei-server/blob/main/src/imageIo/uploadManage.ts

## メンテフロー

[./maintanace-flow.md](./maintanace-flow.md)
38 changes: 38 additions & 0 deletions scripts/archiveEvent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { assert } from 'console'
import { stringify } from 'csv-stringify/sync'
import { writeFile } from 'fs/promises'

import {
archiveUrl,
loadHistEventSongs,
uploadStorageArchive,
} from '../../src/service/firebase'
import { log } from '../../src/utils/logger'

const archiveEventCsv = async (id: string) => {
log({ id })
if (!id) return
const data = await loadHistEventSongs(id)
const dataWithN = data.map((d) => ({ ...d, n: d.n || 0 }))
const csvText = stringify(dataWithN, {
header: true,
columns: ['time', 'title', 'n'].map((key) => ({ key, header: key })),
})

await saveFile(id, csvText)
}

const saveFile = async (id: string, text: string) => {
const paths = archiveUrl(id)
const { localFile } = paths

await writeFile(localFile, text)
await uploadStorageArchive(paths)
log({ paths })
}

const eventId = process.argv[2]

assert(eventId, 'need arg [event_id]')

archiveEventCsv(eventId).then(() => log('doae'))
2 changes: 1 addition & 1 deletion scripts/batch/importHistoryFromCells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
const { title, time } = parseLine(line)
await sleep(200)
await addHistory(title, time)
anaCounts(title, {})
anaCounts([title], {}, [], true)

process.stdout.write('.')
}
Expand Down
31 changes: 31 additions & 0 deletions scripts/batch/importHistoryFromCells2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { readFileSync } from 'fs'
import { addHistory } from '../../src/service/firebase'
import { sleep } from '../../src/utils'
import { anaCounts } from '../../src/utils/wordCounts'

const parseLine = (text: string) => {
const [time, title] = text.split(',')

return { time, title }
}

const importFile = './data/20220501_0200-0800.mid.csv'
const text = readFileSync(importFile, 'utf8')

const lines = text.trim().split('\r\n')

async function main() {
// for (let i = 0; i < 3; i++) {
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const { title, time } = parseLine(line)

await sleep(200)
await addHistory(title.trim(), Number(time), 0)
anaCounts([title], {}, [], true)

process.stdout.write('.')
}
}

main().then(() => console.log('fin'))
32 changes: 32 additions & 0 deletions scripts/batch/importHistoryFromCells3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { readFileSync } from 'fs'
import { addHistory } from '../../src/service/firebase'
import { sleep } from '../../src/utils'
import { anaCounts } from '../../src/utils/wordCounts'

const parseLine = (text: string) => {
const [title, artist, time] = text.split(',')

return { time, title: `${title} - ${artist}` }
}

const importFile = './data/archive/history_1214.txt'
const text = readFileSync(importFile, 'utf8')

const lines = text.trim().split('\n')

async function main() {
// for (let i = 0; i < 3; i++) {
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const { title, time } = parseLine(line)

await sleep(200)

await addHistory(title.trim(), Number(time), 0)
anaCounts([title], {}, [], true)

process.stdout.write('.')
}
}

main().then(() => console.log('fin'))
Loading