<jupyter_start><jupyter_text>Video e Slide Downloader<jupyter_code>from bs4 import BeautifulSoup as bs
import re
import requests
import os
link = input("Inserisci link della sezione del sito ariel da cui vuoi scaricare video e slide")
arielauth = input("Inserisci il tuo cookie arielauth. Se non sai come recuperarlo leggi sul readme. Assicurati di aver fatto l'accesso di recente")
cookies = {"arielauth": f"{arielauth}"}
r = requests.post(link, allow_redirects=True, cookies=cookies)
soup = bs(r.text)
videos = [ div.find("video").find("source")["src"] for div in soup.find_all("div", class_="embed-responsive embed-responsive-16by9")]
videos
materials_nonflat  = [ div.find_all("a") for div in soup.find_all("div", class_="arielMessageBody")]
materials = [item["href"] for sublist in materials_nonflat for item in sublist]
attacched_materials_non_flat =  [ div.find_all("a") for div in soup.find_all("div", class_="arielAttachmentBox")]
sitoAriel=""
if len(attacched_materials_non_flat)!=0:
    sitoAriel = re.search("(https://[\w]+.ariel.ctu.unimi.it/[\w]+)", link).group(1)
attached_materials = [{"url":sitoAriel + re.search( '(/.+)', item["href"]).group(1), "name":item.getText() }for sublist in attacched_materials_non_flat for item in sublist]
for materiale in materials:
    print(f"Sto scaricando {materiale}")
    m = re.search('.+/(.+)', materiale).group(1).strip('/')
    r = requests.get(materiale, allow_redirects=True)
    os.makedirs(os.path.dirname("Result/"), exist_ok=True)
    with open('Result/' + m , 'wb+') as f:
       f.write(r.content)
for materiale in attached_materials:
    print(f"Sto scaricando {materiale['name']}")
    r = requests.post(materiale["url"], allow_redirects=True, cookies=cookies)
    os.makedirs(os.path.dirname("Result/"), exist_ok=True)
    with open('Result/' + materiale["name"] , 'wb+') as f:
        f.write(r.content)
print("Ho finito di scaricare slide e altri materiali.")
i=1
for video in videos:
    m = re.search('.+/mp4:(.+)(.mp4|.MP4)/.+', video).group(1).replace("%20", " ")
    print(f'Sto scaricando {m}. Progresso: {i}/{len(videos)}')
    os.makedirs(os.path.dirname("Result/videos/"), exist_ok=True)
    command = f'ffmpeg -i "{video}" -y -c copy "Result/videos/{m}.mp4"'
    if os.system(command):
        raise RuntimeError(f'program {command} failed!')
    print(f'Ho finito di scaricare {m}')
    i=i+1
print("Finito!")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1706611570247934, 'fraction_numerical': 0.0070247933884297524, 'mean_word_length': 5.113636363636363, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '195251', 'license': 'Apache-2.0', 'n_tokens_mistral': 897, 'n_tokens_neox': 873, 'n_words': 198, 'path': 'downloader.ipynb', 'repo_name': 'mark99-19/little-mermaid-downloader', 'size': '2420'}