[downloader/f4m] Minor cleanup

This commit is contained in:
Antti Ajanki 2015-01-05 20:30:40 +02:00
parent 2c322cc5d6
commit f14f2a6d79

View File

@ -191,6 +191,10 @@ def write_unsigned_int(stream, val):
stream.write(struct_pack('!I', val)) stream.write(struct_pack('!I', val))
def write_unsigned_int_24(stream, val):
stream.write(struct_pack('!I', val)[1:])
def write_flv_header(stream): def write_flv_header(stream):
"""Writes the FLV header to stream""" """Writes the FLV header to stream"""
# FLV header # FLV header
@ -202,13 +206,12 @@ def write_flv_header(stream):
def write_metadata_tag(stream, metadata): def write_metadata_tag(stream, metadata):
"""Writes optional metadata tag to stream""" """Writes optional metadata tag to stream"""
SCRIPT_TAG = b'\x12'
FLV_TAG_HEADER_LEN = 11 FLV_TAG_HEADER_LEN = 11
if metadata: if metadata:
# Script data stream.write(SCRIPT_TAG)
stream.write(b'\x12') write_unsigned_int_24(stream, len(metadata))
# 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(b'\x00\x00\x00\x00\x00\x00\x00')
stream.write(metadata) stream.write(metadata)
write_unsigned_int(stream, FLV_TAG_HEADER_LEN + len(metadata)) write_unsigned_int(stream, FLV_TAG_HEADER_LEN + len(metadata))