import os
import requests
from bs4 import BeautifulSoup
def download_webms(url):
if "4chan.org" not in url:
print("Please provide a valid 4chan thread URL.")
return
try:
response = requests.get(url)
response.raise_for_status() # Raise an error on bad status
except requests.RequestException as e:
print(f"Error accessing {url}: {e}")
return
soup = BeautifulSoup(response.text, 'html.parser')
webms = [a['href'] for a in soup.find_all('a', href=True) if a['href'].endswith('.webm')]
if not webms:
print("No .webm files found in the thread.")
return
# Create a directory for downloads if it doesn't exist
os.makedirs('4chanwebms', exist_ok=True)
# Download each .webm file found
for webm_url in webms:
try:
webm_response = requests.get(f'https:{webm_url}', stream=True)
webm_response.raise_for_status()
webm_filename = webm_url.split('/')[-1]
with open(os.path.join('downloads', webm_filename), 'wb') as f:
for chunk in webm_response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Downloaded {webm_filename} successfully.")
except requests.RequestException as e:
print(f"Failed to download {webm_url}: {e}")
if __name__ == '__main__':
thread_url = input("Enter a 4chan thread URL: ")
download_webms(thread_url)
i made a program to help download all webms in certain thread. How do i make an extension out of it?