changes
This commit is contained in:
@ -14,10 +14,10 @@ planified before the (given) month.
|
||||
- "check" will remove all diffusions that are unconfirmed and have been planified
|
||||
from the (given) month and later.
|
||||
"""
|
||||
from argparse import RawTextHelpFormatter
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils import timezone as tz
|
||||
from aircox_programs.models import *
|
||||
from argparse import RawTextHelpFormatter
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils import timezone as tz
|
||||
from aircox_programs.models import *
|
||||
|
||||
|
||||
class Actions:
|
||||
@ -52,7 +52,7 @@ class Actions:
|
||||
if schedule.match(diffusion.date):
|
||||
break
|
||||
else:
|
||||
print('> #{}: {}'.format(diffusion.date, str(diffusion)))
|
||||
print('> #{}: {}'.format(diffusion.pk, str(diffusion)))
|
||||
items.append(diffusion.id)
|
||||
|
||||
print('{} diffusions will be removed'.format(len(items)))
|
||||
|
@ -42,22 +42,22 @@ class Command (BaseCommand):
|
||||
|
||||
def add_arguments (self, parser):
|
||||
parser.formatter_class=RawTextHelpFormatter
|
||||
parser.add_argument(
|
||||
'-q', '--quality_check', action='store_true',
|
||||
help='Enable quality check using sound_quality_check on all ' \
|
||||
'sounds marqued as not good'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-s', '--scan', action='store_true',
|
||||
help='Scan programs directories for changes'
|
||||
)
|
||||
|
||||
|
||||
def handle (self, *args, **options):
|
||||
programs = Program.objects.filter()
|
||||
|
||||
for program in programs:
|
||||
path = lambda x: os.path.join(program.path, x)
|
||||
self.check_files(
|
||||
program, path(settings.AIRCOX_SOUND_ARCHIVES_SUBDIR),
|
||||
archive = True,
|
||||
)
|
||||
self.check_files(
|
||||
program, path(settings.AIRCOX_SOUND_EXCERPTS_SUBDIR),
|
||||
excerpt = True,
|
||||
)
|
||||
|
||||
self.check_quality()
|
||||
if options.get('scan'):
|
||||
self.scan()
|
||||
if options.get('quality_check'):
|
||||
self.check_quality()
|
||||
|
||||
def get_sound_info (self, path):
|
||||
"""
|
||||
@ -111,12 +111,28 @@ class Command (BaseCommand):
|
||||
diffusion = diffusion[0]
|
||||
return diffusion.episode or None
|
||||
|
||||
def scan (self):
|
||||
print('scan files for all programs...')
|
||||
programs = Program.objects.filter()
|
||||
|
||||
def check_files (self, program, dir_path, **sound_kwargs):
|
||||
for program in programs:
|
||||
print('- program ', program.name)
|
||||
path = lambda x: os.path.join(program.path, x)
|
||||
self.scan_for_program(
|
||||
program, path(settings.AIRCOX_SOUND_ARCHIVES_SUBDIR),
|
||||
type = Sound.Type['archive'],
|
||||
)
|
||||
self.scan_for_program(
|
||||
program, path(settings.AIRCOX_SOUND_EXCERPTS_SUBDIR),
|
||||
type = Sound.Type['excerpt'],
|
||||
)
|
||||
|
||||
def scan_for_program (self, program, dir_path, **sound_kwargs):
|
||||
"""
|
||||
Scan a given directory that is associated to the given program, and
|
||||
update sounds information.
|
||||
"""
|
||||
print(' - scan files in', dir_path)
|
||||
if not os.path.exists(dir_path):
|
||||
return
|
||||
|
||||
@ -154,5 +170,29 @@ class Command (BaseCommand):
|
||||
"""
|
||||
Check all files where quality has been set to bad
|
||||
"""
|
||||
import sound_quality_check as quality_check
|
||||
|
||||
print('start quality check...')
|
||||
files = [ sound.path
|
||||
for sound in Sound.objects.filter(good_quality = False) ]
|
||||
cmd = quality_check.Command()
|
||||
cmd.handle( files = files,
|
||||
**settings.AIRCOX_SOUND_QUALITY )
|
||||
|
||||
print('- update sounds in database')
|
||||
def update_stats(sound_info, sound):
|
||||
stats = sound_info.get_file_stats()
|
||||
if stats:
|
||||
sound.duration = int(stats.get('length'))
|
||||
|
||||
for sound_info in cmd.good:
|
||||
sound = Sound.objects.get(path = sound_info.path)
|
||||
sound.good_quality = True
|
||||
update_stats(sound_info, sound)
|
||||
sound.save(check = False)
|
||||
|
||||
for sound_info in cmd.bad:
|
||||
sound = Sound.objects.get(path = sound_info.path)
|
||||
update_stats(sound_info, sound)
|
||||
sound.save(check = False)
|
||||
|
||||
|
@ -66,10 +66,14 @@ class Sound:
|
||||
|
||||
def __init__ (self, path, sample_length = None):
|
||||
self.path = path
|
||||
self.sample_length = sample_length or self.sample_length
|
||||
self.sample_length = sample_length if sample_length is not None \
|
||||
else self.sample_length
|
||||
|
||||
def get_file_stats (self):
|
||||
return self.stats and self.stats[0]
|
||||
|
||||
def analyse (self):
|
||||
print('- Complete file analysis')
|
||||
print('- complete file analysis')
|
||||
self.stats = [ Stats(self.path) ]
|
||||
position = 0
|
||||
length = self.stats[0].get('length')
|
||||
@ -77,7 +81,7 @@ class Sound:
|
||||
if not self.sample_length:
|
||||
return
|
||||
|
||||
print('- Samples analysis: ', end=' ')
|
||||
print('- samples analysis: ', end=' ')
|
||||
while position < length:
|
||||
print(len(self.stats), end=' ')
|
||||
stats = Stats(self.path, at = position, length = self.sample_length)
|
||||
@ -85,18 +89,6 @@ class Sound:
|
||||
position += self.sample_length
|
||||
print()
|
||||
|
||||
def resume (self):
|
||||
view = lambda array: [
|
||||
'file' if index is 0 else
|
||||
'sample {} (at {} seconds)'.format(index, (index-1) * self.sample_length)
|
||||
for index in self.good
|
||||
]
|
||||
|
||||
if self.good:
|
||||
print('- Good:\033[92m', ', '.join( view(self.good) ), '\033[0m')
|
||||
if self.bad:
|
||||
print('- Bad:\033[91m', ', '.join( view(self.bad) ), '\033[0m')
|
||||
|
||||
def check (self, name, min_val, max_val):
|
||||
self.good = [ index for index, stats in enumerate(self.stats)
|
||||
if min_val <= stats.get(name) <= max_val ]
|
||||
@ -104,6 +96,17 @@ class Sound:
|
||||
if index not in self.good ]
|
||||
self.resume()
|
||||
|
||||
def resume (self):
|
||||
view = lambda array: [
|
||||
'file' if index is 0 else
|
||||
'sample {} (at {} seconds)'.format(index, (index-1) * self.sample_length)
|
||||
for index in array
|
||||
]
|
||||
|
||||
if self.good:
|
||||
print('- good:\033[92m', ', '.join( view(self.good) ), '\033[0m')
|
||||
if self.bad:
|
||||
print('- bad:\033[91m', ', '.join( view(self.bad) ), '\033[0m')
|
||||
|
||||
class Command (BaseCommand):
|
||||
help = __doc__
|
||||
@ -117,7 +120,7 @@ class Command (BaseCommand):
|
||||
help='file(s) to analyse'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-s', '--sample_length', type=int,
|
||||
'-s', '--sample_length', type=int, default=120,
|
||||
help='size of sample to analyse in seconds. If not set (or 0), does'
|
||||
' not analyse by sample',
|
||||
)
|
||||
@ -163,11 +166,11 @@ class Command (BaseCommand):
|
||||
|
||||
# resume
|
||||
if options.get('resume'):
|
||||
if good:
|
||||
print('Files that did not failed the test:\033[92m\n ',
|
||||
'\n '.join(good), '\033[0m')
|
||||
if bad:
|
||||
if self.good:
|
||||
print('files that did not failed the test:\033[92m\n ',
|
||||
'\n '.join([sound.path for sound in self.good]), '\033[0m')
|
||||
if self.bad:
|
||||
# bad at the end for ergonomy
|
||||
print('Files that failed the test:\033[91m\n ',
|
||||
'\n '.join(bad),'\033[0m')
|
||||
print('files that failed the test:\033[91m\n ',
|
||||
'\n '.join([sound.path for sound in self.bad]),'\033[0m')
|
||||
|
||||
|
Reference in New Issue
Block a user