diff options
author | Antti Ajanki <antti.ajanki@iki.fi> | 2015-01-05 20:12:29 +0200 |
---|---|---|
committer | Antti Ajanki <antti.ajanki@iki.fi> | 2015-01-05 21:07:13 +0200 |
commit | 3b8f3a1504b46ff6085617ea22e027668d45a503 (patch) | |
tree | a169d7e05b515d006a5e99371fd9a23f59dfe2b6 /youtube_dl | |
parent | f4bca0b348fe1f4f65c939b496973062180e0c4f (diff) |
[downloader/f4m] <metadata> is optional according to the F4M specs
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/downloader/f4m.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/youtube_dl/downloader/f4m.py b/youtube_dl/downloader/f4m.py index f9f6f3e73..87d3150c7 100644 --- a/youtube_dl/downloader/f4m.py +++ b/youtube_dl/downloader/f4m.py @@ -187,24 +187,27 @@ def build_fragments_list(boot_info): return res -def write_flv_header(stream, metadata): - """Writes the FLV header and the metadata to stream""" +def write_flv_header(stream): + """Writes the FLV header to stream""" # FLV header stream.write(b'FLV\x01') stream.write(b'\x05') stream.write(b'\x00\x00\x00\x09') - # FLV File body stream.write(b'\x00\x00\x00\x00') - # FLVTAG - # Script data - stream.write(b'\x12') - # Size of the metadata with 3 bytes - stream.write(struct_pack('!L', len(metadata))[1:]) - stream.write(b'\x00\x00\x00\x00\x00\x00\x00') - stream.write(metadata) - # Magic numbers extracted from the output files produced by AdobeHDS.php - # (https://github.com/K-S-V/Scripts) - stream.write(b'\x00\x00\x01\x73') + + +def write_metadata_tag(stream, metadata): + """Writes optional metadata tag to stream""" + if metadata: + # Script data + stream.write(b'\x12') + # Size of the metadata with 3 bytes + stream.write(struct_pack('!L', len(metadata))[1:]) + stream.write(b'\x00\x00\x00\x00\x00\x00\x00') + stream.write(metadata) + # Magic numbers extracted from the output files produced by AdobeHDS.php + # (https://github.com/K-S-V/Scripts) + stream.write(b'\x00\x00\x01\x73') def _add_ns(prop): @@ -256,7 +259,11 @@ class F4mFD(FileDownloader): bootstrap = self.ydl.urlopen(bootstrap_url).read() else: bootstrap = base64.b64decode(bootstrap_node.text) - metadata = base64.b64decode(media.find(_add_ns('metadata')).text) + metadata_node = media.find(_add_ns('metadata')) + if metadata_node is not None: + metadata = base64.b64decode(metadata_node.text) + else: + metadata = None boot_info = read_bootstrap_info(bootstrap) fragments_list = build_fragments_list(boot_info) @@ -269,7 +276,8 @@ class F4mFD(FileDownloader): tmpfilename = self.temp_name(filename) (dest_stream, tmpfilename) = sanitize_open(tmpfilename, 'wb') - write_flv_header(dest_stream, metadata) + write_flv_header(dest_stream) + write_metadata_tag(dest_stream, metadata) # This dict stores the download progress, it's updated by the progress # hook |