stat given folder, list only media files

This commit is contained in:
Jonathan Baecker 2020-04-08 17:22:50 +02:00
parent 202019f615
commit d3459f44b0
2 changed files with 25 additions and 2 deletions

View File

@ -72,7 +72,7 @@ class SystemStats:
} }
def disk(self): def disk(self):
root = psutil.disk_usage('/') root = psutil.disk_usage(settings.MEDIA_DISK)
return { return {
'disk_total': [root.total, sizeof_fmt(root.total)], 'disk_total': [root.total, sizeof_fmt(root.total)],
'disk_used': [root.used, sizeof_fmt(root.used)], 'disk_used': [root.used, sizeof_fmt(root.used)],
@ -130,9 +130,28 @@ def get_media_path(dir=None):
return '' return ''
dir = settings.MEDIA_FOLDER dir = settings.MEDIA_FOLDER
else: else:
if '/..' in dir:
dir = '/'.join(dir.split('/')[:-2])
# prevent deeper access
dir = dir.replace('/../', '/')
dir = os.path.join(os.path.dirname(settings.MEDIA_FOLDER), dir) dir = os.path.join(os.path.dirname(settings.MEDIA_FOLDER), dir)
for root, dirs, files in os.walk(dir, topdown=True): for root, dirs, files in os.walk(dir, topdown=True):
return [set_root(root), natsorted(dirs), natsorted(files)] media_files = []
for file in files:
if os.path.splitext(file)[1] in settings.MEDIA_EXTENSIONS:
media_files.append(file)
dirs = natsorted(dirs)
if root != settings.MEDIA_FOLDER:
dirs.insert(0, '..')
if not dirs:
dirs = ['..']
return [set_root(root), dirs, natsorted(media_files)]
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -158,4 +158,8 @@ FFPLAYOUT_CONFIG = '/etc/ffplayout/ffplayout.conf'
# used network interface for statistics: eth0, eno1, etc. # used network interface for statistics: eth0, eno1, etc.
NET_INTERFACE = 'br0' NET_INTERFACE = 'br0'
# Disk for frontpage statistics
MEDIA_DISK = '/mnt/playout'
MEDIA_FOLDER = '/mnt/playout/ADtvMedia' MEDIA_FOLDER = '/mnt/playout/ADtvMedia'
MEDIA_EXTENSIONS = ['.avi', '.mkv', '.m4v', '.mp4', '.webm', '.mov', '.mxf', '.mpg', '.mpeg', '.ts']