check read access
the bot crash if a file don't have read access
This commit is contained in:
parent
558d1e5bd3
commit
bd532e5c22
@ -282,7 +282,7 @@ class MumbleBot:
|
|||||||
else:
|
else:
|
||||||
ffmpeg_debug = "warning"
|
ffmpeg_debug = "warning"
|
||||||
|
|
||||||
command = ["/usr/bin/ffmpeg", '-v', ffmpeg_debug, '-nostdin', '-i', path, '-ac', '1', '-f', 's16le', '-ar', '48000', '-']
|
command = ["ffmpeg", '-v', ffmpeg_debug, '-nostdin', '-i', path, '-ac', '1', '-f', 's16le', '-ar', '48000', '-']
|
||||||
self.thread = sp.Popen(command, stdout=sp.PIPE, bufsize=480)
|
self.thread = sp.Popen(command, stdout=sp.PIPE, bufsize=480)
|
||||||
var.current_music[2] = title
|
var.current_music[2] = title
|
||||||
var.current_music[3] = path
|
var.current_music[3] = path
|
||||||
|
13
util.py
13
util.py
@ -6,6 +6,7 @@ import os
|
|||||||
import variables as var
|
import variables as var
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
|
||||||
def get_recursive_filelist_sorted(path):
|
def get_recursive_filelist_sorted(path):
|
||||||
filelist = []
|
filelist = []
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
@ -19,6 +20,10 @@ def get_recursive_filelist_sorted(path):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
fullpath = os.path.join(path, relroot, file)
|
fullpath = os.path.join(path, relroot, file)
|
||||||
|
if not os.access(fullpath, os.R_OK):
|
||||||
|
print("coucou")
|
||||||
|
continue
|
||||||
|
|
||||||
mime = magic.from_file(fullpath, mime=True)
|
mime = magic.from_file(fullpath, mime=True)
|
||||||
if 'audio' in mime or 'audio' in magic.from_file(fullpath).lower() or 'video' in mime:
|
if 'audio' in mime or 'audio' in magic.from_file(fullpath).lower() or 'video' in mime:
|
||||||
filelist.append(relroot + file)
|
filelist.append(relroot + file)
|
||||||
@ -26,6 +31,7 @@ def get_recursive_filelist_sorted(path):
|
|||||||
filelist.sort()
|
filelist.sort()
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
|
|
||||||
# - zips all files of the given zippath (must be a directory)
|
# - zips all files of the given zippath (must be a directory)
|
||||||
# - returns the absolute path of the created zip file
|
# - returns the absolute path of the created zip file
|
||||||
# - zip file will be in the applications tmp folder (according to configuration)
|
# - zip file will be in the applications tmp folder (according to configuration)
|
||||||
@ -56,6 +62,7 @@ def zipdir(zippath, zipname_prefix=None):
|
|||||||
zipf.close()
|
zipf.close()
|
||||||
return zipname
|
return zipname
|
||||||
|
|
||||||
|
|
||||||
class Dir(object):
|
class Dir(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.name = os.path.basename(path.strip('/'))
|
self.name = os.path.basename(path.strip('/'))
|
||||||
@ -103,7 +110,7 @@ class Dir(object):
|
|||||||
subdirs = list(self.subdirs.keys())
|
subdirs = list(self.subdirs.keys())
|
||||||
|
|
||||||
for key, val in self.subdirs.items():
|
for key, val in self.subdirs.items():
|
||||||
subdirs.extend(map(lambda subdir: key + '/' + subdir,val.get_subdirs_recursively()))
|
subdirs.extend(map(lambda subdir: key + '/' + subdir, val.get_subdirs_recursively()))
|
||||||
|
|
||||||
subdirs.sort()
|
subdirs.sort()
|
||||||
return subdirs
|
return subdirs
|
||||||
@ -131,13 +138,13 @@ class Dir(object):
|
|||||||
files = self.files
|
files = self.files
|
||||||
|
|
||||||
for key, val in self.subdirs.items():
|
for key, val in self.subdirs.items():
|
||||||
files.extend(map(lambda file: key + '/' + file,val.get_files_recursively()))
|
files.extend(map(lambda file: key + '/' + file, val.get_files_recursively()))
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def render_text(self, ident=0):
|
def render_text(self, ident=0):
|
||||||
print('{}{}/'.format(' ' * (ident * 4), self.name))
|
print('{}{}/'.format(' ' * (ident * 4), self.name))
|
||||||
for key, val in self.subdirs.items():
|
for key, val in self.subdirs.items():
|
||||||
val.render_text(ident+1)
|
val.render_text(ident + 1)
|
||||||
for file in self.files:
|
for file in self.files:
|
||||||
print('{}{}'.format(' ' * ((ident + 1)) * 4, file))
|
print('{}{}'.format(' ' * ((ident + 1)) * 4, file))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user