Skip to content

Commit

Permalink
Move all the HTTP options into the library.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrippa committed Apr 16, 2014
1 parent 664ab49 commit c6e54fd
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 41 deletions.
25 changes: 0 additions & 25 deletions docs/api.rst
Expand Up @@ -73,31 +73,6 @@ Session
:members:


Session options
---------------

**rtmpdump**
The path to RTMPDump executable, default: ``"rtmpdump"``

**rtmpdump-proxy**
RTMPDump SOCKS proxy, default: ``None``

**errorlog**
Log errors from subprocesses to a file, default: ``False``

**hds-live-edge**
Specify the time live HDS streams will start from the
edge of stream, default: ``10.0``

**hds-fragment-buffer**
Specify the maximum amount of fragments to buffer,
this controls the maximum size of the ringbuffer,
default: ``10``

**ringbuffer-size**
The size of the internal ring buffer used for some stream types, default: ``16777216``


Plugins
-------
.. module:: livestreamer.plugin
Expand Down
93 changes: 91 additions & 2 deletions src/livestreamer/session.py
@@ -1,5 +1,6 @@
import imp
import pkgutil
import re
import sys
import traceback

Expand Down Expand Up @@ -56,9 +57,97 @@ def set_option(self, key, value):
:param key: key of the option
:param value: value to set the option to
"""
self.options.set(key, value)
**Available options**:
======================= =========================================
errorlog (bool) Log errors from subprocesses to
a file located in the temp directory
hds-fragment-buffer (int) Specify the maximum amount of
fragments to buffer, this controls the
maximum size of the ringbuffer,
default: ``10``
hds-live-edge (float) Specify the time live HDS
streams will start from the edge of
stream, default: ``10.0``
http-proxy (str) Specify a HTTP proxy to use for
all HTTP requests
https-proxy (str) Specify a HTTPS proxy to use for
all HTTPS requests
http-cookies (dict or str) A dict or a semi-colon (;)
delimited str of cookies to add to each
HTTP request, e.g. ``foo=bar;baz=qux``
http-headers (dict or str) A dict or semi-colon (;)
delimited str of headers to add to each
HTTP request, e.g. ``foo=bar;baz=qux``
http-query-params (dict or str) A dict or a ampersand (&)
delimited string of query parameters to
add to each HTTP request,
e.g. ``foo=bar&baz=qux``
http-trust-env (bool) Trust HTTP settings set in the
environment, such as environment
variables (HTTP_PROXY, etc) and
~/.netrc authentication
http-ssl-verify (bool) Verify SSL certificates,
default: ``True``
http-ssl-cert (str or tuple) SSL certificate to use,
can be either a .pem file (str) or a
.crt/.key pair (tuple)
ringbuffer-size (int) The size of the internal ring
buffer used by most stream types,
default: ``16777216`` (16MB)
rtmpdump (str) Specify the location of the
rtmpdump executable, e.g.
``/usr/local/bin/rtmpdump``
rtmpdump-proxy (str) Specify a proxy (SOCKS) that
rtmpdump will use
======================= =========================================
"""
if key == "http-proxy":
if not re.match("^http(s)?://", value):
value = "http://" + value
self.http.proxies["http"] = value
elif key == "https-proxy":
if not re.match("^http(s)?://", value):
value = "https://" + value
self.http.proxies["https"] = value
elif key == "http-cookies":
if isinstance(value, dict):
self.http.cookies.update(value)
else:
self.http.parse_cookies(value)
elif key == "http-headers":
if isinstance(value, dict):
self.http.headers.update(value)
else:
self.http.parse_headers(value)
elif key == "http-query-params":
if isinstance(value, dict):
self.http.params.update(value)
else:
self.http.parse_query_params(value)
elif key == "http-trust-env":
self.http.trust_env = value
elif key == "http-ssl-verify":
self.http.verify = value
elif key == "http-ssl-cert":
self.http.cert = value
else:
self.options.set(key, value)

def get_option(self, key):
"""Returns current value of specified option.
Expand Down
23 changes: 9 additions & 14 deletions src/livestreamer_cli/main.py
@@ -1,6 +1,5 @@
import errno
import os
import re
import requests
import sys
import signal
Expand Down Expand Up @@ -580,35 +579,31 @@ def setup_console():
def setup_http_session():
"""Sets the global HTTP settings, such as proxy and headers."""
if args.http_proxy:
if not re.match("^http(s)?://", args.http_proxy):
args.http_proxy = "http://" + args.http_proxy
livestreamer.http.proxies["http"] = args.http_proxy
livestreamer.set_option("http-proxy", args.http_proxy)

if args.https_proxy:
if not re.match("^http(s)?://", args.https_proxy):
args.https_proxy = "https://" + args.https_proxy
livestreamer.http.proxies["https"] = args.https_proxy
livestreamer.set_option("https-proxy", args.https_proxy)

if args.http_cookies:
livestreamer.http.parse_cookies(args.http_cookies)
livestreamer.set_option("http-cookies", args.http_cookies)

if args.http_headers:
livestreamer.http.parse_headers(args.http_headers)
livestreamer.set_option("http-headers", args.http_headers)

if args.http_query_params:
livestreamer.http.parse_query_params(args.http_query_params)
livestreamer.set_option("http-query-params", args.http_query_params)

if args.http_ignore_env:
livestreamer.http.trust_env = False
livestreamer.set_option("http-trust-env", False)

if args.http_no_ssl_verify:
livestreamer.http.verify = False
livestreamer.set_option("http-ssl-verify", False)

if args.http_ssl_cert:
livestreamer.http.cert = args.http_ssl_cert
livestreamer.set_option("http-ssl-cert", args.http_ssl_cert)

if args.http_ssl_cert_crt_key:
livestreamer.http.cert = tuple(args.http_ssl_cert_crt_key)
livestreamer.set_option("http-ssl-cert", tuple(args.http_ssl_cert_crt_key))


def setup_plugins():
Expand Down

0 comments on commit c6e54fd

Please sign in to comment.