aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-11-25 03:12:26 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-11-25 03:13:22 +0100
commit02dbf93f0e98a56ed04b4a9e6a6d62efd6d801f9 (patch)
tree0d630a6816c117b144ef158390476470a649bd4a /youtube_dl/utils.py
parent1fb2bcbbf748e07d05f98110cc27d440506a9b77 (diff)
[zdf/common] Use API in ZDF extractor.
This also comes with a lot of extra format fields Fixes #1518
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 34b3d19e0..ad0a06287 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -8,6 +8,7 @@ import gzip
import io
import json
import locale
+import math
import os
import pipes
import platform
@@ -16,6 +17,7 @@ import ssl
import socket
import sys
import traceback
+import xml.etree.ElementTree
import zlib
try:
@@ -1006,3 +1008,22 @@ def unsmuggle_url(smug_url):
jsond = compat_parse_qs(sdata)[u'__youtubedl_smuggle'][0]
data = json.loads(jsond)
return url, data
+
+
+def parse_xml_doc(s):
+ assert isinstance(s, type(u''))
+ return xml.etree.ElementTree.fromstring(s.encode('utf-8'))
+
+
+def format_bytes(bytes):
+ if bytes is None:
+ return u'N/A'
+ if type(bytes) is str:
+ bytes = float(bytes)
+ if bytes == 0.0:
+ exponent = 0
+ else:
+ exponent = int(math.log(bytes, 1024.0))
+ suffix = [u'B', u'KiB', u'MiB', u'GiB', u'TiB', u'PiB', u'EiB', u'ZiB', u'YiB'][exponent]
+ converted = float(bytes) / float(1024 ** exponent)
+ return u'%.2f%s' % (converted, suffix)