Skip to content

Commit

Permalink
Merge pull request #537 from deuteronomy-works/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
amoh-godwin authored Oct 17, 2022
2 parents f81becd + 8f66f6f commit 93f71ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyffmpeg/extract_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# video functions

def _codec_name(line):
logger.info('Inside _codec_name')
if 'Video:' in line:
cod = re.findall(r'Video: .*? ', line)[0]
if cod.endswith(', '):
Expand All @@ -24,6 +25,7 @@ def _codec_name(line):


def _data_rate(line):
logger.info('Inside _data_rate')
dr = re.findall(r', \d+ [a-zA-Z]+/s', line)
if dr:
dr = dr[0].split(', ')[1]
Expand All @@ -35,6 +37,7 @@ def _data_rate(line):


def _dimensions(line):
logger.info("Inside _dimensions")
dim = re.findall(r', \d+x\d+ ', line)
if dim:
dim = dim[0].split(', ')[1].strip()
Expand All @@ -54,6 +57,7 @@ def _dimensions(line):


def _fps(line):
logger.info('Inside _fps')
if 'fps' in line:
fps = re.findall(r'\d+.?\d* fps', line)[0].split(' fps')[0]
fps_str = 'fps: '+fps
Expand All @@ -64,6 +68,7 @@ def _fps(line):


def _tbc(line):
logger.info("Inside _tbc")
if 'tbc' in line:
tbc = re.findall(r'\d+.?\d* tbc', line)[0].split(' tbc')[0]
tbc_str = 'tbc: ' + tbc
Expand All @@ -74,6 +79,7 @@ def _tbc(line):


def _tbn(line):
logger.info('Inside _tbn')
if 'tbn' in line:
tbn = re.findall(r'\d+.?\d* tbn', line)[0].split(' tbn')[0]
tbn_str = 'tbn: ' + tbn
Expand All @@ -84,6 +90,7 @@ def _tbn(line):


def _tbr(line):
logger.info("Inside _tbr")
if 'tbr' in line:
tbr = re.findall(r'\d+.?\d* tbr', line)[0].split(' tbr')[0]
tbr_str = 'tbr: ' + tbr
Expand All @@ -96,6 +103,7 @@ def _tbr(line):
# audio functions

def _audio_codec_name(line):
logger.info('Inside _audio_codec_name')
if 'Audio:' in line:
cod = re.findall(r'Audio: .*? ', line)[0]
if cod.endswith(', '):
Expand All @@ -109,6 +117,7 @@ def _audio_codec_name(line):


def _bit_rate(line):
logger.info('Inside _bit_rate')
bt = re.findall(r', \d+ [a-zA-Z]+/s', line)
if bt:
bt = bt[0].split(', ')[1]
Expand All @@ -120,6 +129,7 @@ def _bit_rate(line):


def _channels(line):
logger.info("Inside _channels")
ch_string = 'channels: '
if 'stereo' in line:
ch_string += 'stereo'
Expand All @@ -130,6 +140,7 @@ def _channels(line):


def _sample_rate(line):
logger.info("Inside _sample_rate")
sr = re.findall(r', \d+ Hz', line)
if sr:
sr = sr[0].split(', ')[1]
Expand Down
5 changes: 5 additions & 0 deletions pyffmpeg/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


OS_NAME = system().lower()
logger.info(f"OS: {OS_NAME}")

if OS_NAME == 'linux':
SHELL = False
Expand Down Expand Up @@ -45,9 +46,11 @@ def __init__(self):
if self.os_name != 'windows':
os.system(f'chmod +rw {self.home_path}')
os.system(f'chmod +rw {self.bin_path}')
self.logger.info(f'bin folder: {self.bin_path}')
self.ffmpeg_file = ''

def load_ffmpeg_bin(self):
self.logger.info('Inside load_ffmpeg_bin')

# Load OS specific ffmpeg executable

Expand Down Expand Up @@ -81,6 +84,7 @@ def load_ffmpeg_bin(self):

@staticmethod
def convert_to_py(fn: str, target: str):
logger.info('Inside convert_to_py')

with open(fn, 'rb') as f_file:
raw = f_file.read()
Expand All @@ -97,6 +101,7 @@ def fix_splashes(options):
"""
Make splashes synanymous irrespective of the OS
"""
logger.info('Inside fix_splashes')
if system().lower() == 'windows':
new_opts = []
for entry in options:
Expand Down
16 changes: 16 additions & 0 deletions pyffmpeg/pseudo_ffprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ class FFprobe():

def __init__(self, file_name=None):

self.logger = logging.getLogger('pyffmpeg.pseudo_ffprobe.FFprobe')
self.logger.info('FFprobe initialised')
self.misc = Paths()
self._ffmpeg = self.misc.load_ffmpeg_bin()
self.logger.info(f'ffmpeg bin: {self._ffmpeg}')
self.file_name = file_name
self.overwrite = True
if self.overwrite:
Expand Down Expand Up @@ -61,6 +64,7 @@ def __init__(self, file_name=None):

def _expose(self):
# Expose public functions
self.logger.info('Inside expose')
if 'Duration' in self.metadata[-1]:
self.duration = self.metadata[-1]['Duration']

Expand All @@ -74,15 +78,18 @@ def _expose(self):
self.fps = self.metadata[0][1]['fps']

def _extract(self):
self.logger.info('Inside extract')
for stream in self.raw_streams:
self._extract_all(stream)

def _extract_fps(self, stream):
self.logger.info('Inside _extract_fps')
# Extract fps data from the stream
fps_str = re.findall(r'\d+.?\d* fps', stream)[0].split(' fps')[0]
self.fps = float(fps_str)

def _extract_all(self, stdout):
self.logger.info('Inside _extract_all')
# pick only streams, all of them

if 'misdetection possible' in stdout:
Expand All @@ -109,6 +116,7 @@ def _extract_all(self, stdout):
self._parse_stream_meta(self.stream_heads)

def get_album_art(self, out_file=None):
self.logger.info('Inside get_album_art')
user_file = True
if not out_file:
# randomize the filename to avoid overwrite prompt
Expand Down Expand Up @@ -137,6 +145,7 @@ def get_album_art(self, out_file=None):
return data

def _parse_meta(self, stream):
self.logger.info('Inside _parse_meta')
tags = {}
metadata = self._strip_meta(stream)
# Previous key will be overriden
Expand All @@ -157,6 +166,7 @@ def _parse_meta(self, stream):
return tags

def _parse_header(self, line):
self.logger.info('Inside _parse_header')
parsed = []

if 'Video' in line:
Expand All @@ -172,6 +182,7 @@ def _parse_header(self, line):
return parsed

def _parse_input_meta(self, stream):
self.logger.info('Inside _parse_input_meta')
tags = {}
metadata = self._strip_input_meta(stream)

Expand All @@ -192,6 +203,7 @@ def _parse_input_meta(self, stream):
return tags

def _parse_other_meta(self):
self.logger.info('Inside _parse_other_meta')
for stream in self._other_metadata:
items = stream.split(',')
for each in items:
Expand All @@ -215,6 +227,7 @@ def _parse_other_meta(self):
self.bitrate = self.other_metadata['bitrate']

def _parse_stream_meta(self, stream):
self.logger.info('Inside _parse_stream_meta')
for stream in stream:
infos = stream.split(': ')[-1]
data = infos.split(', ')
Expand All @@ -229,6 +242,7 @@ def _parse_stream_meta(self, stream):
self.type = each

def probe(self):
self.logger.info('Inside _probe')

# randomize the filename to avoid overwrite prompt

Expand Down Expand Up @@ -256,6 +270,7 @@ def probe(self):
self._expose()

def _strip_meta(self, stdout):
self.logger.info('Inside _strip_meta')
std = stdout.splitlines()

# store in stream header
Expand All @@ -271,6 +286,7 @@ def _strip_meta(self, stdout):
return header + meta

def _strip_input_meta(self, stdout):
self.logger.info('Inside _strip_input_meta')
# replace commas with '\r\n'
stdout = stdout.replace(', ', '\r\n')
std = stdout.splitlines()
Expand Down

0 comments on commit 93f71ac

Please sign in to comment.