Skip to content

Instantly share code, notes, and snippets.

@bkbilly
Last active June 23, 2023 08:22
Show Gist options
  • Save bkbilly/be8802f6eaf82d196aa053c114f7e7ae to your computer and use it in GitHub Desktop.
Save bkbilly/be8802f6eaf82d196aa053c114f7e7ae to your computer and use it in GitHub Desktop.
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