1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-22 16:44:32 +01:00

[putio] Added PutIo extractor

This commit is contained in:
Sumit Basak 2019-08-27 16:54:27 -04:00
parent 393cc31d5e
commit 16bdaf52c1
No known key found for this signature in database
GPG Key ID: F1621EB29A7CA4FF
2 changed files with 70 additions and 0 deletions

View File

@ -894,6 +894,7 @@ from .presstv import PressTVIE
from .promptfile import PromptFileIE from .promptfile import PromptFileIE
from .prosiebensat1 import ProSiebenSat1IE from .prosiebensat1 import ProSiebenSat1IE
from .puls4 import Puls4IE from .puls4 import Puls4IE
from .putio import PutIoIE
from .pyvideo import PyvideoIE from .pyvideo import PyvideoIE
from .qqmusic import ( from .qqmusic import (
QQMusicIE, QQMusicIE,

View File

@ -0,0 +1,69 @@
# coding: utf-8
from __future__ import unicode_literals
import re
from youtube_dl.utils import HEADRequest, UnsupportedError, unified_strdate
from .common import InfoExtractor
from ..compat import (
compat_str,
)
class PutIoIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?api\.put\.io/v[0-9]+/files/(?P<id>[0-9]+)'
_TESTS = [{
'url': 'https://app.put.io/files/638463831',
'only_matching': True,
}, {
'url': 'https://api.put.io/v2/files/638474942/download',
'only_matching': True,
}, {
'url': 'https://api.put.io/v2/files/638441619/stream',
'only_matching': True,
}]
def _real_extract(self, url):
video_id = self._match_id(url)
self.to_screen('%s: Getting info for file' % video_id)
head_req = HEADRequest(url)
head_response = self._request_webpage(head_req, video_id, fatal=True)
resolved_url = compat_str(head_response.geturl())
if url == resolved_url:
# we expect a redirect, so if there is none, this URL is invalid
raise UnsupportedError(url)
disposition = head_response.headers.get('Content-Disposition')
mobj = re.match(r'.*?filename="(?P<title>[^"]+)".*?', disposition)
title = mobj.group('title') or video_id
info_dict = {
'id': video_id,
'title': title,
'upload_date': unified_strdate(head_response.headers.get('Last-Modified'))
}
# match supported types only, since a URL can point to any type of file
content_type = head_response.headers.get('Content-Type', '').lower()
m = re.match(
r'^(?P<type>audio|video|application(?=/(?:ogg$|(?:vnd\.apple\.|x-)?mpegurl)))/(?P<format_id>[^;\s]+)',
content_type)
if m:
format_id = compat_str(m.group('format_id'))
if format_id.endswith('mpegurl'):
formats = self._extract_m3u8_formats(resolved_url, video_id, 'mp4')
elif format_id == 'f4m':
formats = self._extract_f4m_formats(resolved_url, video_id)
else:
formats = [{
'format_id': format_id,
'url': resolved_url,
'vcodec': 'none' if m.group('type') == 'audio' else None
}]
info_dict['direct'] = True
self._sort_formats(formats)
info_dict['formats'] = formats
return info_dict
raise UnsupportedError(url)