deuteronomy-works / pyffmpeg

FFmpeg wrapper for python
Apache License 2.0
62 stars 11 forks source link

Update FFProbe tag retrieval #659

Closed Pharbi closed 1 year ago

Pharbi commented 1 year ago

Overview

This code change involves a restructure related to how FFprobe parses metadata into tags. This is related to issue 658, where given a video that does not comply fully with the parser it fails to add values to an empty key '' in the dictionary. This also condenses duplicate code previously in _parse_input_meta and _parse_meta.

Expected behavior

Return a FFprobe object when instantiated

from pyffmpeg import FFprobe
fp = FFprobe('video.mp4')

Actual behavior

    178 # this might be a continuation
    179 if key == '':
--> 180     tags[prev_key] += "\\r\\n" + data[1].strip()
    181 else:
    182     tags[key] = value

KeyError: ''

Reproducing Issue

Steps to reproduce original issue is an extension of #658 where if you add print statements inside of the for loop of _parse_meta there exist keys that are empty strings due to an attempt of formatting/decoration of the YouTube short link. With the usage of a base dictionary this causes a KeyError in the attempt to merge the list with a nonexistent one.

Tests

test_misc.py::test_fix_splashes[case0-exp0] PASSED                                                                                                                                                                                                                     [  5%]
test_misc.py::test_fix_splashes[case1-exp1] PASSED                                                                                                                                                                                                                     [ 11%]
test_misc.py::test_fix_splashes[case2-exp2] PASSED                                                                                                                                                                                                                     [ 17%]
test_pseudo_ffprobe.py::test_probe[countdown.mp4-00:00:04.37] PASSED                                                                                                                                                                                                   [ 23%]
test_pseudo_ffprobe.py::test_probe["Ea-sy_Lemon_30_Second_-_Kevin_MacLeod.mp3"-00:00:31.29] PASSED                                                                                                                                                                     [ 29%]
test_pseudo_ffprobe.py::test_probe["Ecossaise in E-flat - Kevin MacLeod.mp3"-00:00:30.96] PASSED                                                                                                                                                                       [ 35%]
test_pseudo_ffprobe.py::test_album_art PASSED                                                                                                                                                                                                                          [ 41%]
test_pseudo_ffprobe.py::test_generate_tags[countdown.mp4] PASSED                                                                                                                                                                                                       [ 47%]
test_pyffmpeg.py::test_save_directory PASSED                                                                                                                                                                                                                           [ 52%]
test_pyffmpeg.py::test_convert[https://raw.githubusercontent.com/deuteronomy-works/pyffmpeg/master/tests/countdown.mp4-countdown.wav] PASSED                                                                                                                           [ 58%]
test_pyffmpeg.py::test_convert[https://raw.githubusercontent.com/deuteronomy-works/pyffmpeg/master/tests/sample_960x400_ocean_with_audio.flv-flv.mp4] PASSED                                                                                                           [ 64%]
test_pyffmpeg.py::test_convert[https://raw.githubusercontent.com/deuteronomy-works/pyffmpeg/master/tests/sample_960x400_ocean_with_audio.flv-flv.mp3] PASSED                                                                                                           [ 70%]
test_pyffmpeg.py::test_convert[https://raw.githubusercontent.com/deuteronomy-works/pyffmpeg/master/tests/sample_960x400_ocean_with_audio.flv-flv.wav] PASSED                                                                                                           [ 76%]
test_pyffmpeg.py::test_convert[https://raw.githubusercontent.com/deuteronomy-works/pyffmpeg/master/tests/sample_960x400_ocean_with_audio.flv-outs/flv.mp3] PASSED                                                                                                      [ 82%]
test_pyffmpeg.py::test_get_ffmpeg_bin PASSED                                                                                                                                                                                                                           [ 88%]
test_pyffmpeg.py::test_loglevel PASSED                                                                                                                                                                                                                                 [ 94%]
test_pyffmpeg.py::test_options PASSED