Skip to content

Commit 7974819

Browse files
authored
Merge pull request #571 from tcely/patch-3
Handle STR0NNN in a generic way
2 parents 6b7197c + fb663d5 commit 7974819

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tubesync/sync/utils.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,31 @@ def seconds_to_timestr(seconds):
134134
return '{:02d}:{:02d}:{:02d}'.format(hour, minutes, seconds)
135135

136136

137+
def normalize_codec(codec_str):
138+
result = str(codec_str).upper()
139+
parts = result.split('.')
140+
if len(parts) > 0:
141+
result = parts[0].strip()
142+
else:
143+
return None
144+
if 'NONE' == result:
145+
return None
146+
if str(0) in result:
147+
prefix = result.rstrip('0123456789')
148+
result = prefix + str(int(result[len(prefix):]))
149+
return result
150+
151+
137152
def parse_media_format(format_dict):
138153
'''
139154
This parser primarily adapts the format dict returned by youtube-dl into a
140155
standard form used by the matchers in matching.py. If youtube-dl changes
141156
any internals, update it here.
142157
'''
143158
vcodec_full = format_dict.get('vcodec', '')
144-
vcodec_parts = vcodec_full.split('.')
145-
if len(vcodec_parts) > 0:
146-
vcodec = vcodec_parts[0].strip().upper()
147-
else:
148-
vcodec = None
149-
if vcodec == 'NONE':
150-
vcodec = None
159+
vcodec = normalize_codec(vcodec_full)
151160
acodec_full = format_dict.get('acodec', '')
152-
acodec_parts = acodec_full.split('.')
153-
if len(acodec_parts) > 0:
154-
acodec = acodec_parts[0].strip().upper()
155-
else:
156-
acodec = None
157-
if acodec == 'NONE':
158-
acodec = None
161+
acodec = normalize_codec(acodec_full)
159162
try:
160163
fps = int(format_dict.get('fps', 0))
161164
except (ValueError, TypeError):

0 commit comments

Comments
 (0)