forked from rc/aircox
		
	remove Station model (to much trouble for few advantages); start new player; rename Post.detail_url to Post.url, same for ListItem; move Article into website app; add website.Sound post; work on lists;...
This commit is contained in:
		@ -3,6 +3,6 @@ import aircox.liquidsoap.models as models
 | 
			
		||||
 | 
			
		||||
@admin.register(models.Output)
 | 
			
		||||
class OutputAdmin (admin.ModelAdmin):
 | 
			
		||||
    list_display = ('id', 'type', 'station')
 | 
			
		||||
    list_display = ('id', 'type')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -96,7 +96,7 @@ class Monitor:
 | 
			
		||||
        # - preload next diffusion's tracks
 | 
			
		||||
        args = {'start__gt': prev_diff.start } if prev_diff else {}
 | 
			
		||||
        next_diff = programs.Diffusion \
 | 
			
		||||
                        .get(controller.station, now, now = True,
 | 
			
		||||
                        .get(now, now = True,
 | 
			
		||||
                             type = programs.Diffusion.Type.normal,
 | 
			
		||||
                             sounds__isnull = False,
 | 
			
		||||
                             **args) \
 | 
			
		||||
@ -194,30 +194,19 @@ class Command (BaseCommand):
 | 
			
		||||
            help='write configuration and playlist'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        group = parser.add_argument_group('selector')
 | 
			
		||||
        group.add_argument(
 | 
			
		||||
            '-s', '--station', type=int, action='append',
 | 
			
		||||
            help='select station(s) with this id'
 | 
			
		||||
        )
 | 
			
		||||
        group.add_argument(
 | 
			
		||||
            '-a', '--all', action='store_true',
 | 
			
		||||
            help='select all stations'
 | 
			
		||||
            '-s', '--station', type=str,
 | 
			
		||||
            default = 'aircox',
 | 
			
		||||
            help='use this name as station name (default is "aircox")'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def handle (self, *args, **options):
 | 
			
		||||
        # selector
 | 
			
		||||
        stations = []
 | 
			
		||||
        if options.get('all'):
 | 
			
		||||
            stations = programs.Station.objects.filter(active = True)
 | 
			
		||||
        elif options.get('station'):
 | 
			
		||||
            stations = programs.Station.objects.filter(
 | 
			
		||||
                id__in = options.get('station')
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        run = options.get('run')
 | 
			
		||||
        monitor = options.get('on_air') or options.get('monitor')
 | 
			
		||||
        self.controllers = [ utils.Controller(station, connector = monitor)
 | 
			
		||||
                                for station in stations ]
 | 
			
		||||
        self.controller = utils.Controller(
 | 
			
		||||
            station = options.get('station'),
 | 
			
		||||
            connector = monitor
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # actions
 | 
			
		||||
        if options.get('write') or run:
 | 
			
		||||
 | 
			
		||||
@ -1,24 +1,19 @@
 | 
			
		||||
from enum import Enum, IntEnum
 | 
			
		||||
 | 
			
		||||
from django.db import models
 | 
			
		||||
from django.utils.translation import ugettext as _, ugettext_lazy
 | 
			
		||||
 | 
			
		||||
import aircox.programs.models as programs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Output (models.Model):
 | 
			
		||||
    # Note: we don't translate the names since it is project names.
 | 
			
		||||
    Type = {
 | 
			
		||||
        'jack': 0x00,
 | 
			
		||||
        'alsa': 0x01,
 | 
			
		||||
        'icecast': 0x02,
 | 
			
		||||
    }
 | 
			
		||||
    class Type(IntEnum):
 | 
			
		||||
        jack = 0x00
 | 
			
		||||
        alsa = 0x01
 | 
			
		||||
        icecast = 0x02
 | 
			
		||||
 | 
			
		||||
    station = models.ForeignKey(
 | 
			
		||||
        programs.Station,
 | 
			
		||||
        verbose_name = _('station'),
 | 
			
		||||
    )
 | 
			
		||||
    type = models.SmallIntegerField(
 | 
			
		||||
        _('output type'),
 | 
			
		||||
        choices = [ (y, x) for x,y in Type.items() ],
 | 
			
		||||
        choices = [ (int(y), _(x)) for x,y in Type.__members__.items() ],
 | 
			
		||||
        blank = True, null = True
 | 
			
		||||
    )
 | 
			
		||||
    settings = models.TextField(
 | 
			
		||||
 | 
			
		||||
@ -295,12 +295,11 @@ class Controller:
 | 
			
		||||
        files dir.
 | 
			
		||||
        """
 | 
			
		||||
        self.id = station.slug
 | 
			
		||||
        self.name = station.name
 | 
			
		||||
        self.path = os.path.join(settings.AIRCOX_LIQUIDSOAP_MEDIA, station.slug)
 | 
			
		||||
        self.name = station
 | 
			
		||||
        self.path = os.path.join(settings.AIRCOX_LIQUIDSOAP_MEDIA,
 | 
			
		||||
                                 slugify(station))
 | 
			
		||||
 | 
			
		||||
        self.station = station
 | 
			
		||||
        self.station.controller = self
 | 
			
		||||
        self.outputs = models.Output.objects.filter(station = station)
 | 
			
		||||
        self.outputs = models.Output.objects.all()
 | 
			
		||||
 | 
			
		||||
        self.connector = connector and Connector(self.socket_path)
 | 
			
		||||
 | 
			
		||||
@ -310,8 +309,7 @@ class Controller:
 | 
			
		||||
            source.id : source
 | 
			
		||||
            for source in [
 | 
			
		||||
                Source(self, program)
 | 
			
		||||
                for program in programs.Program.objects.filter(station = station,
 | 
			
		||||
                                                             active = True)
 | 
			
		||||
                for program in programs.Program.objects.filter(active = True)
 | 
			
		||||
                if program.stream_set.count()
 | 
			
		||||
            ]
 | 
			
		||||
        }
 | 
			
		||||
@ -370,23 +368,3 @@ class Controller:
 | 
			
		||||
            file.write(data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Monitor:
 | 
			
		||||
    """
 | 
			
		||||
    Monitor multiple controllers.
 | 
			
		||||
    """
 | 
			
		||||
    controllers = None
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        self.controllers = {
 | 
			
		||||
            controller.id : controller
 | 
			
		||||
            for controller in [
 | 
			
		||||
                Controller(station, True)
 | 
			
		||||
                for station in programs.Station.objects.filter(active = True)
 | 
			
		||||
            ]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    def update(self):
 | 
			
		||||
        for controller in self.controllers.values():
 | 
			
		||||
            controller.update()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user