stt #8
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 22 * * *' | |
jobs: | |
# fetch audio by input & auto schedule | |
prepare-video-meta: | |
runs-on: ubuntu-latest | |
strategy: | |
# - os: linux arch: arm64 | |
matrix: | |
include: | |
- os: linux | |
arch: amd64 | |
outputs: | |
exist: ${{ steps.get-video.outputs.exist }} | |
filepath: ${{ steps.get-video.outputs.filepath }} | |
index: ${{ steps.get-video.outputs.index }} | |
date: ${{ steps.get-video.outputs.date }} | |
bvid: ${{ steps.get-video.outputs.bvid }} | |
title: ${{ steps.get-video.outputs.title }} | |
description: ${{ steps.get-video.outputs.tidescriptiontle }} | |
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 detail | |
id: get-video-info | |
run: | | |
curl https://api.bilibili.com/x/web-interface/view?bvid=${{ steps.get-video.outputs.bvid }} | jq -r '.data.cid' | xargs -I {} echo "CID={}" >> "$GITHUB_OUTPUT" | |
- name: get stream | |
id: get-stream | |
run: | | |
echo 'cid:${{ steps.get-video-info.outputs.CID }}' | |
curl 'https://api.bilibili.com/x/player/wbi/playurl?bvid=${{ github.event.inputs.bvid }}&cid=${{ steps.get-video-info.outputs.CID }}' \ | |
-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' | jq -r '.data.durl[0].url' | xargs -I {} echo "STREAM_URL={}" >> "$GITHUB_OUTPUT" | |
- name: get video | |
run: | | |
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 | |
- 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 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: | |
- 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 | |
cat /tmp1/output.md >> tmp.md | |
mv tmp.md ${{ needs.prepare-video-meta.outputs.filepath }} | |
- name: Upload res.md | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tmp.md | |
path: tmp.md | |
if-no-files-found: error | |
retention-days: 1 | |
- 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 <noreply@github.com> | |
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 |