Created
September 1, 2023 12:13
-
-
Save OkoyaUsman/924d4d9af63440af4a9932b43ffac70f to your computer and use it in GitHub Desktop.
A python script to auto download a series with all seasons and episodes from netnaija.com, saves the headache of popup ads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import os | |
from bs4 import BeautifulSoup | |
SERIES_URL = "https://www.thenetnaija.net/videos/series/10134-bob-hearts-abishola" #stick the series url here and run | |
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', 'Referer': 'https://www.thenetnaija.net/'} | |
def createFolder(folder_name): | |
if not os.path.exists(folder_name): | |
os.makedirs(folder_name) | |
print(f"The folder '{folder_name}' has been created.") | |
else: | |
print(f"The folder '{folder_name}' already exists.") | |
seriesfolder = SERIES_URL.split("/")[5] | |
createFolder(seriesfolder) | |
serieshtml = requests.get(SERIES_URL).text | |
soup1 = BeautifulSoup(serieshtml, 'html.parser') | |
seasons = soup1.findAll('div', {'class': 'vs-one'}) | |
sc = 0 | |
for season in seasons: | |
sc += 1 | |
seasonfolder = seriesfolder+"/season"+str(sc) | |
createFolder(seasonfolder) | |
SEASON_URL = SERIES_URL+"/season-"+str(sc) | |
seasonhtml = requests.get(SEASON_URL).text | |
soup2 = BeautifulSoup(seasonhtml, 'html.parser') | |
episodes = soup2.findAll('article', {'class': 'file-one'}) | |
ec = 0 | |
for episode in episodes: | |
ec += 1 | |
EPISODE_URL = SEASON_URL+"/episode-"+str(ec) | |
response1 = requests.get(EPISODE_URL+"/download", headers=headers) | |
item1 = str(response1.url).split("/")[4].split("-")[0] | |
data1 = requests.get("https://api.sabishare.com/token/download/"+item1).json() | |
videourl = data1["data"]["url"] | |
r1 = requests.get(videourl, allow_redirects=True, stream=True) | |
file1 = seasonfolder+"/episode"+str(ec)+".mp4" | |
with open(file1, "wb") as vid1: | |
for chunk1 in r1.iter_content(chunk_size=1024): | |
if chunk1: | |
vid1.write(chunk1) | |
vid1.flush() | |
print("downloaded video") | |
response2 = requests.get(EPISODE_URL+"/download-sub", headers=headers) | |
item2 = str(response2.url).split("/")[4].split("-")[0] | |
data2 = requests.get("https://api.sabishare.com/token/download/"+item2).json() | |
suburl = data2["data"]["url"] | |
r2 = requests.get(suburl, allow_redirects=True, stream=True) | |
file2 = seasonfolder+"/episode"+str(ec)+".srt" | |
with open(file2, "wb") as vid2: | |
for chunk2 in r2.iter_content(chunk_size=1024): | |
if chunk2: | |
vid2.write(chunk2) | |
vid2.flush() | |
print("downloaded sub") | |
print(f"Completed Season {str(sc)}. Episode {str(ec)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment