Skip to content

Commit c3a42ff

Browse files
author
Martin Panter
committed
Simplify unnecessary URL encoding logic
1 parent 0ba2423 commit c3a42ff

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

iview/hds.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
from shutil import copyfileobj
2525
import urllib.request
2626
from .utils import PersistentConnectionHandler, http_get
27-
from .utils import urlencode_param
2827
from sys import stderr
29-
from urllib.parse import urljoin
28+
from urllib.parse import urljoin, urlencode, quote_plus
3029
import io
3130
from .utils import xml_text_elements
3231
from . import flvlib
@@ -505,9 +504,10 @@ def progress_update(frontend, flv, time, duration):
505504
stderr.flush()
506505

507506
def manifest_url(url, file, hdnea=None):
508-
file += "/manifest.f4m?hdcore="
507+
query = [("hdcore", "")] # Produces 403 Forbidden without this
509508
if hdnea:
510-
file += "&hdnea=" + urlencode_param(hdnea)
509+
query.append(("hdnea", hdnea))
510+
file += "/manifest.f4m?" + urlencode(query)
511511
return urljoin(url, file)
512512

513513
def get_manifest(url, session):
@@ -640,9 +640,11 @@ def player_verification(manifest, player, key):
640640
sig = hmac.new(key, msg.encode("ascii"), sha256)
641641
pvtoken = "{}~hmac={}".format(msg, sig.hexdigest())
642642

643-
# The "hdntl" parameter must be passed either in the URL or as a cookie
644-
return "?pvtoken={}&{}".format(
645-
urlencode_param(pvtoken), urlencode_param(hdntl))
643+
# The "hdntl" parameter must be passed either in the URL or as a cookie;
644+
# however the "pvtoken" parameter only seems to work in the URL
645+
pvtoken = urlencode((("pvtoken", pvtoken),))
646+
hdntl = quote_plus(hdntl, safe="=")
647+
return "?{}&{}".format(pvtoken, hdntl)
646648

647649
def skip_box(stream):
648650
(_, size) = read_box_header(stream)

iview/utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import zlib
22
from io import BufferedIOBase
3-
from urllib.parse import quote_plus
43
from io import SEEK_CUR, SEEK_END
54
import urllib.request
65
import http.client
@@ -47,13 +46,6 @@ def read_strict(stream, size):
4746
raise EOFError()
4847
return data
4948

50-
value_unsafe = '%+&;#'
51-
VALUE_SAFE = ''.join(chr(c) for c in range(33, 127)
52-
if chr(c) not in value_unsafe)
53-
def urlencode_param(value):
54-
"""Minimal URL encoding for query parameter"""
55-
return quote_plus(value, safe=VALUE_SAFE)
56-
5749
class CounterWriter(BufferedIOBase):
5850
def __init__(self, output):
5951
self.length = 0

0 commit comments

Comments
 (0)