Last active
June 23, 2023 08:22
-
-
Save bkbilly/be8802f6eaf82d196aa053c114f7e7ae to your computer and use it in GitHub Desktop.
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
from m3u8downloader.main import M3u8Downloader | |
from bs4 import BeautifulSoup | |
import requests | |
import re | |
import os | |
file_location = 'Η Γη της Ελιάς' | |
vgm_url = 'https://www.megatv.com/episodes/?id=s242&type=tvshows' | |
os.makedirs(file_location, exist_ok=True) | |
html_text = requests.get(vgm_url).text | |
soup = BeautifulSoup(html_text, 'html.parser') | |
mydivs = soup.find_all("a", class_="relative-post") | |
title_text = soup.find("h1", {"class": "show-name"}).text | |
title = re.search(r"(.+)?(?=\|)", title_text).group(1).strip() | |
for mydiv in mydivs: | |
print("--------") | |
season_text = mydiv.find("span", {"class": "season-t"}).text | |
season_gr = re.search(r"(\w)' ΚΥΚΛΟΣ", season_text).group(1) | |
gr_dict = {'Α': 1, 'Β': 2, 'Γ': 3, 'Δ': 4} | |
season = gr_dict[season_gr] | |
episode = re.search(r".*epeisodio-(\d+)", mydiv['href']).group(1) | |
filename = f"{title} - {season}x{episode}.mp4" | |
if not os.path.exists(f"{file_location}/{filename}"): | |
print(filename) | |
html_text = requests.get(mydiv['href']).text | |
soup2 = BeautifulSoup(html_text, 'html.parser') | |
m3u8_url = soup2.find('div', {'id': 'player_div_id'})['data-kwik_source'] | |
print(m3u8_url) | |
downloader = M3u8Downloader(m3u8_url, f"{file_location}/{filename}") | |
downloader.start() | |
else: | |
print(f"Episode already exists: {filename}") | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment