initial bittorrent support
This commit is contained in:
parent
3426d75467
commit
58538a2c64
|
@ -60,6 +60,7 @@ from .utils import (
|
||||||
format_bytes,
|
format_bytes,
|
||||||
formatSeconds,
|
formatSeconds,
|
||||||
GeoRestrictedError,
|
GeoRestrictedError,
|
||||||
|
HaruhiDLError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
ISO3166Utils,
|
ISO3166Utils,
|
||||||
locked_file,
|
locked_file,
|
||||||
|
@ -1903,6 +1904,10 @@ class HaruhiDL(object):
|
||||||
fd.add_progress_hook(ph)
|
fd.add_progress_hook(ph)
|
||||||
if self.params.get('verbose'):
|
if self.params.get('verbose'):
|
||||||
self.to_screen('[debug] Invoking downloader on %r' % info.get('url'))
|
self.to_screen('[debug] Invoking downloader on %r' % info.get('url'))
|
||||||
|
if info.get('protocol') == 'bittorrent' and not self.params.get('allow_p2p'):
|
||||||
|
raise HaruhiDLError('Peer-to-peer format got selected, but peer-to-peer '
|
||||||
|
'downloads are not allowed. '
|
||||||
|
'Choose different format or add --allow-p2p option')
|
||||||
return fd.download(name, info)
|
return fd.download(name, info)
|
||||||
|
|
||||||
if info_dict.get('requested_formats') is not None:
|
if info_dict.get('requested_formats') is not None:
|
||||||
|
|
|
@ -438,6 +438,8 @@ def _real_main(argv=None):
|
||||||
'geo_bypass': opts.geo_bypass,
|
'geo_bypass': opts.geo_bypass,
|
||||||
'geo_bypass_country': opts.geo_bypass_country,
|
'geo_bypass_country': opts.geo_bypass_country,
|
||||||
'geo_bypass_ip_block': opts.geo_bypass_ip_block,
|
'geo_bypass_ip_block': opts.geo_bypass_ip_block,
|
||||||
|
'allow_p2p': opts.allow_p2p if not opts.prefer_p2p else True,
|
||||||
|
'prefer_p2p': opts.prefer_p2p,
|
||||||
# just for deprecation check
|
# just for deprecation check
|
||||||
'autonumber': opts.autonumber if opts.autonumber is True else None,
|
'autonumber': opts.autonumber if opts.autonumber is True else None,
|
||||||
'usetitle': opts.usetitle if opts.usetitle is True else None,
|
'usetitle': opts.usetitle if opts.usetitle is True else None,
|
||||||
|
|
|
@ -10,6 +10,7 @@ from .rtsp import RtspFD
|
||||||
from .ism import IsmFD
|
from .ism import IsmFD
|
||||||
from .external import (
|
from .external import (
|
||||||
get_external_downloader,
|
get_external_downloader,
|
||||||
|
Aria2cFD,
|
||||||
FFmpegFD,
|
FFmpegFD,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ PROTOCOL_MAP = {
|
||||||
'f4m': F4mFD,
|
'f4m': F4mFD,
|
||||||
'http_dash_segments': DashSegmentsFD,
|
'http_dash_segments': DashSegmentsFD,
|
||||||
'ism': IsmFD,
|
'ism': IsmFD,
|
||||||
|
'bittorrent': Aria2cFD,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -182,15 +182,16 @@ class Aria2cFD(ExternalFD):
|
||||||
AVAILABLE_OPT = '-v'
|
AVAILABLE_OPT = '-v'
|
||||||
|
|
||||||
def _make_cmd(self, tmpfilename, info_dict):
|
def _make_cmd(self, tmpfilename, info_dict):
|
||||||
cmd = [self.exe, '-c']
|
cmd = [self.exe or 'aria2c', '-c']
|
||||||
cmd += self._configuration_args([
|
cmd += self._configuration_args([
|
||||||
'--min-split-size', '1M', '--max-connection-per-server', '4'])
|
'--min-split-size', '1M', '--max-connection-per-server', '4'])
|
||||||
dn = os.path.dirname(tmpfilename)
|
dn = os.path.dirname(tmpfilename)
|
||||||
if dn:
|
if dn:
|
||||||
cmd += ['--dir', dn]
|
cmd += ['--dir', dn]
|
||||||
cmd += ['--out', os.path.basename(tmpfilename)]
|
cmd += ['--out', os.path.basename(tmpfilename)]
|
||||||
for key, val in info_dict['http_headers'].items():
|
if info_dict['protocol'] != 'bittorrent':
|
||||||
cmd += ['--header', '%s: %s' % (key, val)]
|
for key, val in info_dict['http_headers'].items():
|
||||||
|
cmd += ['--header', '%s: %s' % (key, val)]
|
||||||
cmd += self._option('--interface', 'source_address')
|
cmd += self._option('--interface', 'source_address')
|
||||||
cmd += self._option('--all-proxy', 'proxy')
|
cmd += self._option('--all-proxy', 'proxy')
|
||||||
cmd += self._bool_option('--check-certificate', 'nocheckcertificate', 'false', 'true', '=')
|
cmd += self._bool_option('--check-certificate', 'nocheckcertificate', 'false', 'true', '=')
|
||||||
|
|
|
@ -1410,7 +1410,19 @@ class InfoExtractor(object):
|
||||||
preference -= 0.5
|
preference -= 0.5
|
||||||
|
|
||||||
protocol = f.get('protocol') or determine_protocol(f)
|
protocol = f.get('protocol') or determine_protocol(f)
|
||||||
proto_preference = 0 if protocol in ['http', 'https'] else (-0.5 if protocol == 'rtsp' else -0.1)
|
if protocol in ['http', 'https']:
|
||||||
|
proto_preference = 0
|
||||||
|
elif protocol == 'rtsp':
|
||||||
|
proto_preference = -0.5
|
||||||
|
elif protocol == 'bittorrent':
|
||||||
|
if self._downloader.params.get('prefer_p2p') is True:
|
||||||
|
proto_preference = 1
|
||||||
|
elif self._downloader.params.get('allow_p2p') is True:
|
||||||
|
proto_preference = -0.1
|
||||||
|
else:
|
||||||
|
proto_preference = -2
|
||||||
|
else:
|
||||||
|
proto_preference = -0.1
|
||||||
|
|
||||||
if f.get('vcodec') == 'none': # audio only
|
if f.get('vcodec') == 'none': # audio only
|
||||||
preference -= 50
|
preference -= 50
|
||||||
|
|
|
@ -533,6 +533,19 @@ def parseOpts(overrideArguments=None):
|
||||||
'--external-downloader-args',
|
'--external-downloader-args',
|
||||||
dest='external_downloader_args', metavar='ARGS',
|
dest='external_downloader_args', metavar='ARGS',
|
||||||
help='Give these arguments to the external downloader')
|
help='Give these arguments to the external downloader')
|
||||||
|
downloader.add_option(
|
||||||
|
'--allow-p2p',
|
||||||
|
dest='allow_p2p', action='store_true', default=None,
|
||||||
|
help='Allow downloading by peer-to-peer protocols (BitTorrent). '
|
||||||
|
'May be a violation of your local laws on file sharing in some cases')
|
||||||
|
downloader.add_option(
|
||||||
|
'--forbid-p2p',
|
||||||
|
dest='allow_p2p', action='store_false', default=None,
|
||||||
|
help='Explicitly forbid downloading by peer-to-peer protocols')
|
||||||
|
downloader.add_option(
|
||||||
|
'--prefer-p2p',
|
||||||
|
dest='prefer_p2p', action='store_true', default=None,
|
||||||
|
help='Prefer peer-to-peer formats (implies --allow-p2p)')
|
||||||
|
|
||||||
workarounds = optparse.OptionGroup(parser, 'Workarounds')
|
workarounds = optparse.OptionGroup(parser, 'Workarounds')
|
||||||
workarounds.add_option(
|
workarounds.add_option(
|
||||||
|
|
Loading…
Reference in a new issue