Add workflow to update the user agents once a month
This commit is contained in:
parent
351ac7b50c
commit
e939585c17
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'
|
||||
@ -1,15 +1,4 @@
|
||||
const useragents: string[] = [
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (X11; Linux i686; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36 Edg/97.0.1072.69",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36 Vivaldi/4.3"
|
||||
];
|
||||
import useragents from './useragents.json';
|
||||
|
||||
export function setUserAgent(array: string[]): void {
|
||||
useragents.push(...array);
|
||||
|
||||
12
play-dl/Request/useragents.json
Normal file
12
play-dl/Request/useragents.json
Normal file
@ -0,0 +1,12 @@
|
||||
[
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (X11; Linux i686; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0",
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36 Edg/97.0.1072.69",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.81 Safari/537.36 Vivaldi/4.3"
|
||||
]
|
||||
Loading…
x
Reference in New Issue
Block a user