projects
/
smooth-dl.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9bae220
)
Differentiate better between url, manifest_url and base_url
author
Antonio Ospite <ao2@ao2.it>
Tue, 4 Mar 2014 11:26:47 +0000
(12:26 +0100)
committer
Antonio Ospite <ao2@ao2.it>
Thu, 14 Jan 2016 15:31:58 +0000
(16:31 +0100)
smooth-dl.py
patch
|
blob
|
history
diff --git
a/smooth-dl.py
b/smooth-dl.py
index
29115b3
..
3297102
100755
(executable)
--- a/
smooth-dl.py
+++ b/
smooth-dl.py
@@
-36,12
+36,14
@@
__version = "0.x"
__author_info = "Written by Antonio Ospite http://ao2.it"
import os
__author_info = "Written by Antonio Ospite http://ao2.it"
import os
+import re
import sys
import xml.etree.ElementTree as etree
import urllib2
import struct
import tempfile
from optparse import OptionParser
import sys
import xml.etree.ElementTree as etree
import urllib2
import struct
import tempfile
from optparse import OptionParser
+from urlparse import urlparse, urlunparse
def get_chunk_data(data):
def get_chunk_data(data):
@@
-92,29
+94,32
@@
def write_wav_header(out_file, fmt, codec_private_data, data_len):
out_file.write(struct.pack('<L', data_len))
out_file.write(struct.pack('<L', data_len))
-def get_manifest(
base_
url, dest_dir=tempfile.gettempdir()):
+def get_manifest(url, dest_dir=tempfile.gettempdir()):
"""Returns the manifest and the new URL if this is changed"""
if os.path.exists(dest_dir) == False:
os.mkdir(dest_dir, 0755)
"""Returns the manifest and the new URL if this is changed"""
if os.path.exists(dest_dir) == False:
os.mkdir(dest_dir, 0755)
- if base_url.startswith('http://'):
+ # Remove the querystring if present
+ manifest_url = urlunparse(urlparse(url)._replace(query=''))
- manifest_url = base_url
- if not manifest_url.lower().endswith(('/manifest', '.ismc', '.csm')):
- manifest_url += '/Manifest'
+ if not manifest_url.lower().endswith(('/manifest', '.ismc', '.csm')):
+ manifest_url += '/Manifest'
+
+ if manifest_url.startswith('http://'):
response = urllib2.urlopen(manifest_url)
data = response.read()
response = urllib2.urlopen(manifest_url)
data = response.read()
- manifest_path = os.path.join(dest_dir, 'Manifest')
- f = open(manifest_path, "w")
+ local_manifest_path = os.path.join(dest_dir, 'Manifest')
+
+ f = open(local_manifest_path, "w")
f.write(data)
f.close()
else:
f.write(data)
f.close()
else:
-
manifest_path = base_
url
+
local_manifest_path =
url
- manifest = etree.parse(manifest_path)
+ manifest = etree.parse(
local_
manifest_path)
version = manifest.getroot().attrib['MajorVersion']
if version != "2":
version = manifest.getroot().attrib['MajorVersion']
if version != "2":
@@
-123,11
+128,13
@@
def get_manifest(base_url, dest_dir=tempfile.gettempdir()):
try:
# if some intermediate client Manifest is used, like in Rai Replay
clip = manifest.find("Clip")
try:
# if some intermediate client Manifest is used, like in Rai Replay
clip = manifest.find("Clip")
- actual_manifest_url = clip.attrib["Url"]
- base_url = actual_manifest_url.lower().replace("/manifest", "")
+ manifest_url = clip.attrib["Url"]
except:
pass
except:
pass
+ manifest_pattern = re.compile("/manifest$", re.IGNORECASE)
+ base_url = manifest_pattern.sub("", manifest_url)
+
return (manifest, base_url)
return (manifest, base_url)