fix some issues, make the liquidsoap monitor working
This commit is contained in:
@ -53,6 +53,7 @@ class SoundAdmin (NameableAdmin):
|
||||
(None, { 'fields': ['embed', 'duration', 'mtime'] }),
|
||||
(None, { 'fields': ['removed', 'good_quality', 'public' ] } )
|
||||
]
|
||||
readonly_fields = ('path', 'duration',)
|
||||
|
||||
|
||||
@admin.register(Stream)
|
||||
@ -82,7 +83,7 @@ class ProgramAdmin (NameableAdmin):
|
||||
@admin.register(Diffusion)
|
||||
class DiffusionAdmin (admin.ModelAdmin):
|
||||
def archives (self, obj):
|
||||
sounds = obj.get_archives()
|
||||
sounds = [ str(s) for s in obj.get_archives()]
|
||||
return ', '.join(sounds) if sounds else ''
|
||||
|
||||
list_display = ('id', 'type', 'date', 'archives', 'program', 'initial')
|
||||
|
@ -18,10 +18,12 @@ Where:
|
||||
|
||||
|
||||
To check quality of files, call the command sound_quality_check using the
|
||||
parameters given by the setting AIRCOX_SOUND_QUALITY.
|
||||
parameters given by the setting AIRCOX_SOUND_QUALITY. This script requires
|
||||
Sox (and soxi).
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
@ -53,13 +55,19 @@ class Command (BaseCommand):
|
||||
' matching episode on sounds that have not been yet assigned'
|
||||
)
|
||||
|
||||
|
||||
def handle (self, *args, **options):
|
||||
if options.get('scan'):
|
||||
self.scan()
|
||||
if options.get('quality_check'):
|
||||
self.check_quality(check = (not options.get('scan')) )
|
||||
|
||||
def _get_duration (self, path):
|
||||
p = subprocess.Popen(['soxi', '-D', path], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
out, err = p.communicate()
|
||||
if not err:
|
||||
return utils.seconds_to_time(int(float(out)))
|
||||
|
||||
def get_sound_info (self, program, path):
|
||||
"""
|
||||
Parse file name to get info on the assumption it has the correct
|
||||
@ -82,6 +90,7 @@ class Command (BaseCommand):
|
||||
else:
|
||||
r = r.groupdict()
|
||||
|
||||
r['duration'] = self._get_duration(path)
|
||||
r['name'] = r['name'].replace('_', ' ').capitalize()
|
||||
r['path'] = path
|
||||
return r
|
||||
@ -109,12 +118,18 @@ class Command (BaseCommand):
|
||||
|
||||
@staticmethod
|
||||
def check_sounds (qs):
|
||||
"""
|
||||
Only check for the sound existence or update
|
||||
"""
|
||||
# check files
|
||||
for sound in qs:
|
||||
if sound.check_on_file():
|
||||
sound.save(check = False)
|
||||
|
||||
def scan (self):
|
||||
"""
|
||||
For all programs, scan dirs
|
||||
"""
|
||||
print('scan files for all programs...')
|
||||
programs = Program.objects.filter()
|
||||
|
||||
@ -149,7 +164,8 @@ class Command (BaseCommand):
|
||||
sound_info = self.get_sound_info(program, path)
|
||||
sound = Sound.objects.get_or_create(
|
||||
path = path,
|
||||
defaults = { 'name': sound_info['name'] }
|
||||
defaults = { 'name': sound_info['name'],
|
||||
'duration': sound_info['duration'] or None }
|
||||
)[0]
|
||||
sound.__dict__.update(sound_kwargs)
|
||||
sound.save(check = False)
|
||||
|
@ -49,9 +49,8 @@ class Stats:
|
||||
|
||||
args.append('stats')
|
||||
|
||||
p = subprocess.Popen(args,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr = subprocess.PIPE)
|
||||
p = subprocess.Popen(args, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
# sox outputs to stderr (my god WHYYYY)
|
||||
out_, out = p.communicate()
|
||||
self.parse(str(out, encoding='utf-8'))
|
||||
|
@ -564,16 +564,17 @@ class Diffusion (models.Model):
|
||||
Get total duration of the archives. May differ from the schedule
|
||||
duration.
|
||||
"""
|
||||
return sum([ sound.duration for sound in self.sounds
|
||||
if sound.type == Sound.Type['archive']])
|
||||
r = [ sound.duration
|
||||
for sound in self.sounds.filter(type = Sound.Type['archive'])
|
||||
if sound.duration ]
|
||||
return sum(r) or self.duration
|
||||
|
||||
def get_archives (self):
|
||||
"""
|
||||
Return an ordered list of archives sounds for the given episode.
|
||||
"""
|
||||
r = [ sound for sound in self.sounds.all()
|
||||
r = [ sound for sound in self.sounds.all().order_by('path')
|
||||
if sound.type == Sound.Type['archive'] ]
|
||||
r.sort(key = 'path')
|
||||
return r
|
||||
|
||||
@classmethod
|
||||
|
@ -8,7 +8,7 @@ def to_timedelta (time):
|
||||
return datetime.timedelta(
|
||||
hours = time.hour,
|
||||
minutes = time.minute,
|
||||
seconds = time.seconds
|
||||
seconds = time.second
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user