Browse Source

Try to keep YouTube's bot detection happy

main
fluffy 5 months ago
parent
commit
6edcd48256
1 changed files with 6 additions and 1 deletions
  1. +6
    -1
      beatbot.py

+ 6
- 1
beatbot.py View File

@@ -4,10 +4,13 @@ import pickle
import random
import re
import time
import urllib.parse

import mastodon
import requests

USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'

logging.basicConfig(
handlers=[logging.handlers.RotatingFileHandler('beatbot.log', maxBytes=100000, backupCount=10),
logging.StreamHandler()],
@@ -41,8 +44,10 @@ def bot():
seen_vids = set()

for attempt in range(5):
qs = urllib.parse.quote_plus(search_term)
query = requests.get(
f'https://www.youtube.com/results?search_query={search_term}')
f'https://www.youtube.com/results?search_query={qs}',
headers={'User-Agent': USER_AGENT})
video_ids = re.findall(r'watch\?v=([^"]{11})"', query.text)

if video_ids:


Loading…
Cancel
Save