from emissions.models import Nonstop
from nonstop.models import Track, ScheduledDiffusion, RecurringStreamOccurence, RecurringRandomDirectoryOccurence
+from nonstop.app_settings import app_settings
class Command(BaseCommand):
return playlist
- async def player_process(self, cmd, timeout=None):
- self.player = await asyncio.create_subprocess_shell(
- cmd,
- stdout=asyncio.subprocess.PIPE,
- stderr=asyncio.subprocess.PIPE)
+ async def player_process(self, item, timeout=None):
+ if app_settings.DEBUG_WITH_SLEEPS:
+ if hasattr(item, 'is_stream') and item.is_stream():
+ cmd = 'sleep 86400 # %s' % item.stream.url
+ else:
+ cmd = 'sleep %s # %s' % (item.duration.total_seconds(), item.file_path())
+ else:
+ cmd = [app_settings.PLAYER_COMMAND] + app_settings.PLAYER_ARGS
+ if hasattr(item, 'is_stream') and item.is_stream():
+ cmd.append(item.stream.url)
+ else:
+ cmd.append(item.file_path())
+ print('cmd:', cmd)
+ if isinstance(cmd, str):
+ self.player = await asyncio.create_subprocess_shell(
+ cmd,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE)
+ else:
+ self.player = await asyncio.create_subprocess_exec(
+ *cmd,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE)
if timeout is None:
await self.player.communicate()
else:
self.current_track_start_datetime = now
print(now, track.title, track.duration,
'- future tracks:', [x.title for x in self.playlist[self.playhead + 1:self.playhead + 3]])
- cmd = 'sleep %s # %s' % (track.duration.seconds, track.title)
- await self.player_process(cmd)
+ await self.player_process(track)
# TODO: detect "soft spot", to switch to another nonstop
# tranche
self.playhead += 1
elif slot.is_stream():
print(now, 'playing stream', slot.stream)
- if slot.get_jingle_filepath():
- cmd = 'sleep 15 # jingle %s' % slot.get_jingle_filepath()
- await self.player_process(cmd, timeout=60)
- cmd = 'sleep 86400 # stream' # will never stop by itself
+ if slot.jingle_id:
+ await self.player_process(slot.jingle, timeout=60)
print('timeout at', (slot.end_datetime - now).total_seconds())
- await self.player_process(cmd, timeout=(slot.end_datetime - now).total_seconds())
+ await self.player_process(slot, timeout=(slot.end_datetime - now).total_seconds())
else:
if hasattr(slot, 'episode'):
print(now, 'playing sound', slot.episode)
else:
print(now, 'playing random')
- if slot.get_jingle_filepath():
- cmd = 'sleep 15 # jingle %s' % slot.get_jingle_filepath()
- await self.player_process(cmd, timeout=60)
- filepath = slot.get_sound_filepath()
- if hasattr(slot, 'soundfile'):
- cmd = 'sleep %s # %s' % (slot.soundfile.duration, filepath)
- else:
- cmd = 'sleep %s # %s' % (45 * 60, filepath)
- await self.player_process(cmd)
+ if slot.jingle_id:
+ await self.player_process(slot.jingle, timeout=60)
+ await self.player_process(slot)
def recompute_playlist(self):
current_track = self.playlist[self.playhead]