Skip to content

Commit

Permalink
Extract _read_atoms generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 5, 2013
1 parent 5a8c96d commit 8b17644
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions qtfaststart/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,24 @@ def get_index(datastream):
The tuple elements will be in the order that they appear in the file.
"""
index = []

log.debug("Getting index of top level atoms...")

# Read atoms until we catch an error
index = list(_read_atoms(datastream))

# Make sure the atoms we need exist
top_level_atoms = set([item[0] for item in index])
for key in ["moov", "mdat"]:
if key not in top_level_atoms:
log.error("%s atom not found, is this a valid MOV/MP4 file?" % key)
raise FastStartException()

return index


def _read_atoms(datastream):
"""
Read atoms until an error occurs
"""
while(datastream):
try:
skip = 8
Expand All @@ -60,7 +73,7 @@ def get_index(datastream):
except:
break

index.append((atom_type, datastream.tell() - skip, atom_size))
yield (atom_type, datastream.tell() - skip, atom_size)

if atom_size == 0:
if atom_type == "mdat":
Expand All @@ -74,15 +87,6 @@ def get_index(datastream):

datastream.seek(atom_size - skip, os.SEEK_CUR)

# Make sure the atoms we need exist
top_level_atoms = set([item[0] for item in index])
for key in ["moov", "mdat"]:
if key not in top_level_atoms:
log.error("%s atom not found, is this a valid MOV/MP4 file?" % key)
raise FastStartException()

return index


def find_atoms(size, datastream):
"""
Expand Down

0 comments on commit 8b17644

Please sign in to comment.