liveleak mime parser
This commit is contained in:
@@ -221,6 +221,36 @@ class VidmeMIMEParser(BaseMIMEParser):
|
||||
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 = [
|
||||
StreamableMIMEParser,
|
||||
@@ -231,5 +261,6 @@ parsers = [
|
||||
ImgurMIMEParser,
|
||||
RedditUploadsMIMEParser,
|
||||
YoutubeMIMEParser,
|
||||
LiveleakMIMEParser,
|
||||
GifvMIMEParser,
|
||||
BaseMIMEParser]
|
||||
|
||||
@@ -69,6 +69,10 @@ URLS = OrderedDict([
|
||||
'https://vid.me/rHlb',
|
||||
re.compile('https://(.*)\.cloudfront\.net/videos/15694926/52450725.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')),
|
||||
])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user