juanmcasillas / gopro2gpx

Parse the gpmd stream for GOPRO moov track (MP4) and extract the GPS info into a GPX (and kml) file.
GNU General Public License v3.0
197 stars 50 forks source link

Refactor ffmpegtools to reduce dependency linkage #34

Closed stakita closed 2 years ago

stakita commented 2 years ago

This PR refactors some of the classes to reduce direct dependencies between them. I'll summarize the changes below. Note, these changes are structural and should be largely invisible. The only exception to this is the information string (previously stream) when using getMetadataTrack with json.

config.py

Relocate ffmpeg version logic from config.py to ffmpegtools.py. This file just queries the config file if it exists and stores the ffprobe and ffmpeg paths if available. This removes ffmpeg specific operations from the concerns of config.py.

ffmpegtools.py

Remove the dependency and internal knowledge of the Config class from the FFMpegTools class. This class now conditionally overrides the ffprobe and ffmpeg paths if provided, otherwise with initialize itself with sensible defaults (based on the plaform). Additionally, this allows for the determination of whether to use the ffprobe json interface to be internal to the FFMpegTools class. This allows for the getMetadataTrackFromJSON and getMetadataTrack methods to be removed and combined into a single method getMetadataTrack which uses the json interface as needed. This simplifies the use of the class in the gpmf.py classes.

gopro2gpx.py

The FFMpegTools class is instantiated at the top-level main() function so that it can be injected into the Parser class rather than have it be instantiated inline. This should make the Parser class easier to test as we can mock the FFMpegTools class.

gpmf.py

This now takes the injected FFMpegTools dependency. There is now only a unified method getMetadataTrack to call so the conditional has been removed.