-
Notifications
You must be signed in to change notification settings - Fork 9
224 lines (223 loc) · 8.88 KB
/
stt.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: stt
on:
workflow_dispatch:
inputs:
bvid:
description: 'Bilibili bvid'
required: false
category:
description: 'category'
type: choice
options:
- btnews
- commercial
- opinion
required: false
schedule:
- cron: '0 13 * * *'
# 21:00 in CN
jobs:
# fetch audio by input & auto schedule
prepare-video-meta:
runs-on: ubuntu-latest
outputs:
exist: ${{ steps.get-video.outputs.exist }}
filepath: ${{ steps.get-video.outputs.filepath }}
path: ${{ steps.get-video.outputs.path }}
index: ${{ steps.get-video.outputs.index }}
date: ${{ steps.get-video.outputs.date }}
avid: ${{ steps.get-video.outputs.avid }}
bvid: ${{ steps.get-video.outputs.bvid }}
cid: ${{ steps.get-video.outputs.cid }}
title: ${{ steps.get-video.outputs.title }}
description: ${{ steps.get-video.outputs.description }}
category: ${{ steps.get-video.outputs.category }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: install deps
run: npm install
- name: fetch user audio video
id: get-video
run: npm run get-video -- --category ${{ github.event.inputs.category }} --bv ${{ github.event.inputs.bvid }}
fetch-audio:
runs-on: ubuntu-latest
needs: [prepare-video-meta]
if: ${{ needs.prepare-video-meta.outputs.exist == 'false' }}
env:
url: https://www.bilibili.com/video/${{needs.prepare-video-meta.outputs.bvid }}
title: ${{ needs.prepare-video-meta.outputs.title }}
category: ${{ needs.prepare-video-meta.outputs.category }}
steps:
- name: install ffmpeg
# https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
run: |
wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
mkdir -p $PWD/ffmpeg
tar -xvJf ffmpeg-release-amd64-static.tar.xz -C $PWD
mv $PWD/ffmpeg-7.0.2-amd64-static/* $PWD/ffmpeg
- name: install downloader
# https://github.com/iawia002/lux/releases/download/v0.24.1/lux_0.24.1_Linux_x86_64.tar.gz
# https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
run: |
wget https://github.com/nilaoda/BBDown/releases/download/1.6.3/BBDown_1.6.3_20240814_linux-x64.zip
unzip BBDown_1.6.3_20240814_linux-x64.zip -d /usr/local/bin
chmod +x /usr/local/bin/BBDown
# download with a downloader
# - name: download audio
# run: |
# export PATH=/usr/local/bin:$PATH
# export PATH=$PWD/ffmpeg:$PATH
# echo $PATH
# ffmpeg -version
# BBDown --debug --file-pattern test/output.mp4 ${{env.url}}
# ls -l
# download with curl
- name: get stream
id: get-stream
run: |
echo 'cid:${{ needs.prepare-video-meta.outputs.cid }}'
echo 'avid:${{ needs.prepare-video-meta.outputs.avid }}'
echo 'bvid:${{ needs.prepare-video-meta.outputs.bvid }}'
curl '${{ secrets.BILI_PROXY }}?bvid=${{ needs.prepare-video-meta.outputs.bvid }}&cid=${{ needs.prepare-video-meta.outputs.cid }}&avid=${{ needs.prepare-video-meta.outputs.avid }}' \
-H 'referer: https://www.bilibili.com/' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0' > resp.txt
cat resp.txt
cat resp.txt | jq -r '.data.durl[0].url' | xargs -I {} echo "BACKUP_STREAM_URL={}" >> "$GITHUB_OUTPUT"
cat resp.txt | jq -r '.data.durl[0].backup_url[0]' | xargs -I {} echo "STREAM_URL={}" >> "$GITHUB_OUTPUT"
- name: get video
id: get-video-main
run: |
mkdir -p test
mkdir -p test
curl '${{ steps.get-stream.outputs.STREAM_URL }}' \
-H 'referer: https://www.bilibili.com/' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0' --output test/output.mp4 || true
if [ $? -ne 0 ]; then
echo "Downloading main video failed. Trying backup."
curl '${{ steps.get-stream.outputs.BACKUP_STREAM_URL }}' \
-H 'referer: https://www.bilibili.com/' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0' --output test/output.mp4
fi
- name: verify shasum
run: |
shasum test/output.mp4
- name: Upload output.mp4
uses: actions/upload-artifact@v4
with:
name: output.mp4
path: test/output.mp4
if-no-files-found: error
retention-days: 1
- name: convert to mp3
run: |
export PATH=/usr/local/bin:$PATH
export PATH=$PWD/ffmpeg:$PATH
echo $PATH
ls -l
ls -l test
ffmpeg -i test/output.mp4 -ar 16000 test/output.mp3
- name: Upload output.mp3
uses: actions/upload-artifact@v4
with:
name: output.mp3
path: test/output.mp3
if-no-files-found: error
retention-days: 1
stt:
runs-on: ubuntu-latest
if: ${{ needs.prepare-video-meta.outputs.exist == 'false' }}
needs:
- fetch-audio
steps:
- name: Download output.mp3
uses: actions/download-artifact@v4
with:
name: output.mp3
path: /tmp
- name: upload to dify
id: difyfile
run: |
curl -X POST 'https://api.dify.ai/v1/files/upload' \
--header 'Authorization: Bearer ${{secrets.DIFY_TOKEN}}' \
--form 'file=@/tmp/output.mp3;type=audio/mp3' \
--form 'user=${{secrets.DIFY_USER}}' | jq -r '.id' | xargs -I {} echo "DIFY_AUDIO_FILE_ID={}" >> "$GITHUB_OUTPUT"
- name: call dify
run: |
echo $DIFY_AUDIO_FILE_ID
curl --max-time 600 -X POST 'https://api.dify.ai/v1/workflows/run' \
--header 'Authorization: Bearer ${{secrets.DIFY_TOKEN}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {
"audio": {
"transfer_method": "local_file",
"upload_file_id": "${{ steps.difyfile.outputs.DIFY_AUDIO_FILE_ID }}",
"type": "audio"
}
},
"response_mode": "blocking",
"user": "${{secrets.DIFY_USER}}"
}' | jq -r '.data.outputs.text' > output.md
- name: show result
run: |
cat output.md
- name: Upload output.md
uses: actions/upload-artifact@v4
with:
name: output.md
path: output.md
if-no-files-found: error
retention-days: 1
create-pr:
if: ${{ needs.prepare-video-meta.outputs.exist == 'false' }}
runs-on: ubuntu-latest
needs: [stt, prepare-video-meta]
steps:
- uses: actions/checkout@v4
- name: mkdir
run: mkdir -p tmp1
- name: Download output.md
uses: actions/download-artifact@v4
with:
name: output.md
path: tmp1
- name: createHead
run: |
echo '---
title: ${{needs.prepare-video-meta.outputs.title }}
description: ${{needs.prepare-video-meta.outputs.description }}
tag: []
date: ${{needs.prepare-video-meta.outputs.date }}
bvid: ${{needs.prepare-video-meta.outputs.bvid }}
---
' >> tmp.md
ls -l tmp1
mkdir -p ${{ needs.prepare-video-meta.outputs.path }}
cat tmp1/output.md >> tmp.md
mv tmp.md ${{ needs.prepare-video-meta.outputs.filepath }}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.PAT }}
commit-message: ":memo: new ${{needs.prepare-video-meta.outputs.category}} ${{ needs.prepare-video-meta.outputs.title }}"
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
delete-branch: true
branch: fetch/${{ needs.prepare-video-meta.outputs.index }}
title: ':memo: new ${{needs.prepare-video-meta.outputs.category}} ${{ needs.prepare-video-meta.outputs.title }}'
add-paths: |
docs/**/*.md
images/**/*.webp
base: master
body: |
new ${{needs.prepare-video-meta.outputs.category}} ${{ needs.prepare-video-meta.outputs.title }}
- Auto-generated by action: [create-pull-request](https://github.com/peter-evans/create-pull-request) with dify
labels: |
${{needs.prepare-video-meta.outputs.category}}
automated pr
draft: false