mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-30 12:22:48 +00:00
Add workflow to update the user agents once a month
This commit is contained in:
19
.github/updateUserAgents.js
vendored
Normal file
19
.github/updateUserAgents.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
const { writeFileSync } = require('fs');
|
||||
const UserAgent = require('user-agents');
|
||||
|
||||
const generator = new UserAgent({ deviceCategory: 'desktop' });
|
||||
const userAgents = [];
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
let userAgent = generator.random();
|
||||
|
||||
// only use Windows and Linux user agents and exclude Internet Explorer ones
|
||||
while (!(userAgent.data.platform.startsWith('Win') || userAgent.data.platform.startsWith('Linux'))
|
||||
|| userAgent.data.userAgent.includes('; MSIE') || userAgent.data.userAgent.includes('Trident/')) {
|
||||
userAgent = generator.random();
|
||||
}
|
||||
|
||||
userAgents.push(userAgent.toString());
|
||||
}
|
||||
|
||||
writeFileSync('play-dl/Request/useragents.json', JSON.stringify(userAgents, null, 4));
|
||||
48
.github/workflows/update-user-agents.yml
vendored
Normal file
48
.github/workflows/update-user-agents.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
name: 'Update user agents'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 1 * *'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: Update user agents
|
||||
steps:
|
||||
- name: Clone repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Create and checkout automated/update-user-agents branch
|
||||
run: |
|
||||
git branch 'automated/update-user-agents' main
|
||||
git checkout 'automated/update-user-agents'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install user-agents
|
||||
|
||||
- name: Run update script
|
||||
run: node .github/updateUserAgents.js
|
||||
|
||||
- name: Commit changes
|
||||
run: |
|
||||
git config user.name 'github-actions[bot]'
|
||||
git config user.email 'github-actions[bot]@users.noreply.github.com'
|
||||
|
||||
git add play-dl/Request/useragents.json
|
||||
git commit --message '[Automated] Update user agents'
|
||||
|
||||
- name: Push and create pull request
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git push --set-upstream origin automated/update-user-agents
|
||||
useragents=$(cat play-dl/Request/useragents.json | jq -r '"New user agents:\n- " + join("\n- ")')
|
||||
gh pr create --title '[Automated] Update user agents' --body "$useragents" --head 'automated/update-user-agents'
|
||||
Reference in New Issue
Block a user