stt #95
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |