Skip to content

Commit

Permalink
^q^
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtBestor committed Feb 27, 2024
1 parent edb9a6b commit d914a9a
Show file tree
Hide file tree
Showing 71 changed files with 1,206 additions and 884 deletions.
7 changes: 3 additions & 4 deletions src/extractor/_4chan_downloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import downloader
from utils import Downloader, File, clean_title, urljoin, get_ext
from ratelimit import limits, sleep_and_retry
from utils import Downloader, File, clean_title, urljoin, get_ext, limits
import utils


Expand All @@ -9,8 +8,7 @@ class File_4chan(File):
type = '4chan'
format = 'page:04;'

@sleep_and_retry
@limits(2, 1)
@limits(.5)
def get(self):
return {}

Expand All @@ -21,6 +19,7 @@ class Downloader_4chan(Downloader):
URLS = [r'regex:boards.(4chan|4channel).org']
MAX_CORE = 4
display_name = '4chan'
ACCEPT_COOKIES = [r'(.*\.)?(4chan|4channel)\.org']

@classmethod
def fix_url(cls, url):
Expand Down
119 changes: 96 additions & 23 deletions src/extractor/afreeca_downloader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import downloader
from utils import Soup, Downloader, Session, try_n, format_filename, cut_pair, File, get_print
from utils import Soup, Downloader, Session, try_n, format_filename, cut_pair, File, get_print, print_error, json
import ree as re
from io import BytesIO
from m3u8_tools import playlist2stream, M3u8_stream
import errors
import json
import utils
import os


class LoginRequired(errors.LoginRequired):
Expand All @@ -18,6 +19,7 @@ class Downloader_afreeca(Downloader):
URLS = ['afreecatv.com']
single = True
display_name = 'AfreecaTV'
ACCEPT_COOKIES = [r'(.*\.)?afreecatv\.com']

def init(self):
self.session = Session()
Expand All @@ -35,27 +37,40 @@ def read(self):
downloader.download(video['url_thumb'], buffer=thumb)
self.setIcon(thumb)

self.title = video['title']
self.title = os.path.splitext(video['name'])[0].replace(':', ':')
self.artist = video['artist']

if video['live']:
d = {}
d['url'] = self.url
d['title'] = self.artist
d['thumb'] = thumb.getvalue()
utils.update_live(d, self.cw)


@try_n(4)
def _get_stream(url_m3u8):
print('_get_stream', url_m3u8)
def _get_stream(url_m3u8, session, referer, cw=None):
print_ = get_print(cw)
print_(f'_get_stream: {url_m3u8}')
try:
stream = playlist2stream(url_m3u8)
stream = playlist2stream(url_m3u8, referer=referer, session=session)
except Exception as e:
print(e)
stream = M3u8_stream(url_m3u8)
print_(print_error(e))
stream = M3u8_stream(url_m3u8, referer=referer, session=session)
return stream



class Video(File):
type = 'afreeca'
_live_info = None

def get(self):
print_ = get_print(self.cw)
url, session = self['referer'], self.session
if session is None:
session = Session()
session.purge('afreeca')

html = downloader.read_html(url, session=session)
if "document.location.href='https://login." in html:
Expand All @@ -69,8 +84,34 @@ def get(self):
url_thumb = soup.find('meta', {'property': 'og:image'}).attrs['content']
print_('url_thumb: {}'.format(url_thumb))

vid = re.find('/player/([0-9]+)', url, err='no vid')
if f'{vid}/catch' in url: #6215
vid = re.find('/player/([0-9]+)', url)
if vid is None: # live
bid = re.find('afreecatv.com/([^/]+)', url, err='no bid')

url_api = f'https://st.afreecatv.com/api/get_station_status.php?szBjId={bid}'
r = session.post(url_api, headers={'Referer': url})
d = json.loads(r.text)
artist = d['DATA']['user_nick']
if self._live_info is not None:
self._live_info['title'] = artist

url_api = f'https://live.afreecatv.com/afreeca/player_live_api.php?bjid={bid}'
#bno = re.find('afreecatv.com/[^/]+/([0-9]+)', url, err='no bno')
bno = re.find(r'nBroadNo\s=\s([0-9]+)', html, err='no bno') #6915
r = session.post(url_api, data={'bid': bid, 'bno': bno, 'type': 'aid', 'pwd': '', 'player_type': 'html5', 'stream_type': 'common', 'quality': 'master', 'mode': 'landing', 'from_api': '0'}, headers={'Referer': url})
d = json.loads(r.text)
res = d['CHANNEL'].get('RESULT')
print_(f'result: {res}')
if res == -6:
raise LoginRequired()
aid = d['CHANNEL']['AID']

data = {}
data['title'] = soup.find('meta', {'property': 'og:title'})['content'].strip()
data['files'] = [{'file': f'https://pc-web.stream.afreecatv.com/live-stm-16/auth_master_playlist.m3u8?aid={aid}'}]
data['writer_nick'] = artist
data['live'] = True
elif f'{vid}/catch' in url: #6215
url_api = 'https://api.m.afreecatv.com/station/video/a/catchview'
r = session.post(url_api, data={'nPageNo': '1', 'nLimit': '10', 'nTitleNo': vid}, headers={'Referer': url})
try:
Expand All @@ -92,6 +133,7 @@ def get(self):
data = d['data']

title = data.get('full_title') or data['title']
artist = data.get('copyright_nickname') or data.get('original_user_nick') or data['writer_nick']

if data.get('adult_status') == 'notLogin':
raise LoginRequired(title)
Expand All @@ -105,16 +147,47 @@ def get(self):
urls_m3u8.append(file)
print_(f'urls_m3u8: {len(urls_m3u8)}')

streams = []
for url_m3u8 in urls_m3u8:
try:
stream = _get_stream(url_m3u8)
except Exception as e:
print(e)
continue #2193
streams.append(stream)
for stream in streams[1:]:
streams[0] += stream
stream = streams[0]

return {'url': stream, 'title': title, 'name': format_filename(title, vid, '.mp4'), 'url_thumb': url_thumb}
if data.get('live'):
hdr = session.headers.copy()
hdr['Referer'] = url
stream = utils.LiveStream(urls_m3u8[0], headers=hdr, cw=self.cw)
else:
streams = []
for url_m3u8 in urls_m3u8:
try:
stream = _get_stream(url_m3u8, session, url, cw=self.cw)
except Exception as e:
print_(print_error(e))
continue #2193
streams.append(stream)
for stream in streams[1:]:
streams[0] += stream
stream = streams[0]

live = data.get('live') or False
return {'url': stream, 'title': title, 'name': format_filename(title, vid, '.mp4', artist=artist, live=live), 'url_thumb': url_thumb, 'artist': artist, 'live': live}



class Live_afreeca(utils.Live):
type = 'afreeca'

@classmethod
def is_live(cls, url):
return bool(re.match(r'https?://(play|bj).afreecatv.com/([^/?#]+)', url))

@classmethod
def fix_url(cls, url):
bj = re.find(r'https?://(play|bj).afreecatv.com/([^/?#]+)', url)[1]
return f'https://play.afreecatv.com/{bj}'

@classmethod
def check_live(cls, url, info=None):
try:
video = Video({'referer': url})
video._live_info = info
video.ready(None)
return True
except Exception as e:
print(e)
return False
7 changes: 3 additions & 4 deletions src/extractor/asmhentai_downloader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#coding: utf8
import downloader
import ree as re
from utils import Soup, urljoin, Downloader, join, Session, File, clean_title
from utils import Soup, urljoin, Downloader, join, Session, File, clean_title, limits
import os
from ratelimit import limits, sleep_and_retry
import utils


Expand All @@ -19,8 +18,7 @@ class File_asmhentai(File):
type = 'asmhentai'
format = 'name'

@sleep_and_retry
@limits(4, 1)
@limits(.25)
def get(self):
soup = downloader.read_soup(self['referer'], self['rereferer'], session=self.session)
img = soup.find('img', id='fimg')
Expand All @@ -38,6 +36,7 @@ class Downloader_asmhentai(Downloader):
URLS = ['asmhentai.com']
MAX_CORE = 8
display_name = 'AsmHentai'
ACCEPT_COOKIES = [r'(.*\.)?asmhentai\.com']

def init(self):
self.session = Session()
Expand Down
4 changes: 2 additions & 2 deletions src/extractor/avgle_downloader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#coding: utf8
import downloader
from m3u8_tools import M3u8_stream
from utils import Soup, Downloader, LazyUrl, get_print, try_n, check_alive, format_filename
from utils import Soup, Downloader, LazyUrl, get_print, try_n, check_alive, format_filename, json
from io import BytesIO
import base64
import json
import webbrowser
import errors

Expand All @@ -14,6 +13,7 @@ class Downloader_avgle(Downloader):
type = 'avgle'
single = True
URLS = ['avgle.com']
ACCEPT_COOKIES = [r'(.*\.)?avgle\.com']

def init(self):
if not self.cw.data_:
Expand Down
4 changes: 2 additions & 2 deletions src/extractor/bcy_downloader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#coding:utf8
import downloader
from utils import Soup, cut_pair, LazyUrl, Downloader, get_print, get_max_range, try_n, clean_title, check_alive
import json
from utils import Soup, cut_pair, LazyUrl, Downloader, get_print, get_max_range, try_n, clean_title, check_alive, json
import os
from translator import tr_

Expand All @@ -12,6 +11,7 @@ class Downloader_bcy(Downloader):
URLS = ['bcy.net/item/detail/', 'bcy.net/u/']
MAX_CORE = 8
display_name = '半次元'
ACCEPT_COOKIES = [r'(.*\.)?bcy\.net']

def init(self):
self.html = downloader.read_html(self.url)
Expand Down
1 change: 1 addition & 0 deletions src/extractor/bdsmlr_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Downloader_bdsmlr(Downloader):
type = 'bdsmlr'
URLS = ['bdsmlr.com']
display_name = 'BDSMlr'
ACCEPT_COOKIES = [r'(.*\.)?bdsmlr\.com']

def init(self):
if 'bdsmlr.com/post/' in self.url:
Expand Down
Loading

0 comments on commit d914a9a

Please sign in to comment.