liveleak mime parser

This commit is contained in:
woorst
2017-07-05 23:56:16 -05:00
parent 659807d890
commit 2a7c35da21
2 changed files with 35 additions and 0 deletions

View File

@@ -221,6 +221,36 @@ class VidmeMIMEParser(BaseMIMEParser):
return url, None return url, None
class LiveleakMIMEParser(BaseMIMEParser):
"""
https://www.liveleak.com/view?i=12c_3456789
<video>
<source src="https://cdn.liveleak.com/..mp4" res="HD" type="video/mp4">
<source src="https://cdn.liveleak.com/..mp4" res="SD" type="video/mp4">
</video>
Sometimes only one video source is available
"""
pattern = re.compile(r'https?://((www|m)\.)?liveleak\.com/view\?i\=\w+$')
@staticmethod
def get_mimetype(url):
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
urls = []
videos = soup.find_all('video')
for vid in videos:
source = vid.find('source', attr={'res': 'HD'}) \
or vid.find('source')
if source:
urls.append((source.get('src'), source.get('type')))
# TODO: Handle pages with multiple videos
# TODO: Handle pages with youtube embeds
if urls:
return urls[0]
else:
return url, None
# Parsers should be listed in the order they will be checked # Parsers should be listed in the order they will be checked
parsers = [ parsers = [
StreamableMIMEParser, StreamableMIMEParser,
@@ -231,5 +261,6 @@ parsers = [
ImgurMIMEParser, ImgurMIMEParser,
RedditUploadsMIMEParser, RedditUploadsMIMEParser,
YoutubeMIMEParser, YoutubeMIMEParser,
LiveleakMIMEParser,
GifvMIMEParser, GifvMIMEParser,
BaseMIMEParser] BaseMIMEParser]

View File

@@ -69,6 +69,10 @@ URLS = OrderedDict([
'https://vid.me/rHlb', 'https://vid.me/rHlb',
re.compile('https://(.*)\.cloudfront\.net/videos/15694926/52450725.mp4(.*)'), re.compile('https://(.*)\.cloudfront\.net/videos/15694926/52450725.mp4(.*)'),
'video/mp4')), 'video/mp4')),
('liveleak_video', (
'https://www.liveleak.com/view?i=08b_1499296574',
re.compile('https://cdn.liveleak.com/80281E/ll_a_s/2017/Jul/5/LiveLeak-dot-com-08b_1499296574-NMHH8690_1499296571.mov.h264_720p.mp4(.*)'),
'video/mp4')),
]) ])