Skip to content

Instantly share code, notes, and snippets.

@PRO-2684
Created January 4, 2023 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PRO-2684/5d73aa01526fe1e5e994d1459349c436 to your computer and use it in GitHub Desktop.
Save PRO-2684/5d73aa01526fe1e5e994d1459349c436 to your computer and use it in GitHub Desktop.
Bulk download teleplays at meijuwo.
from requests import Session
from re import match, search
from bs4 import BeautifulSoup as bs
from os import system, chdir
class Teleplay:
def __init__(self, url: str) -> None:
'''Initialize a teleplay. `url` be like: `https://www.meijuwo.net/play/5940-1-1/`.'''
m = match(r'(https://www.meijuwo.net/play/\d+-\d+-)\d+', url)
if m:
self.base = m.groups()[0]
else:
raise RuntimeError('Invalid url!')
self.x = Session()
self.x.headers.update({
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54',
'referer': 'https://www.meijuwo.net/'
})
soup = bs(self.x.get(url).text, features="html.parser")
playlist = soup.find('ul', {'id': 'playlist'})
self.count = len(playlist.find_all('li'))
def fetch(self, volumn: int) -> str:
'''Fetch m3u8 url for given volumn.'''
assert (1 <= volumn <= self.count), f"Invalid volumn {volumn}, expected integer between 1 and {self.count}."
url = self.base + str(volumn)
r = self.x.get(url)
m = search(r'"url":"(.+)","url_next":"', r.text)
if m:
api_id = m.groups()[0]
else:
raise RuntimeError('Argument `api_id` not found!')
r = self.x.get('https://api.apiimg.com/dplay/super.php?id=' + api_id)
m = search(r'"url": "(.+)",', r.text)
if m:
m3u8 = m.groups()[0]
else:
raise RuntimeError('Argument `m3u8` not found!')
return m3u8
if __name__ == '__main__':
chdir(r'D:\Download')
t = Teleplay('https://www.meijuwo.net/play/5940-1-1/')
for i in range(1, t.count + 1):
m3u8 = t.fetch(i)
cmd = f'.\\N_m3u8DL-RE.exe "{m3u8}" --save-name {i:0>2}'
print(f"[{i}]>", cmd)
system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment