Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
radiopanik
django-panik-nonstop
Commits
20fc4ca6
Commit
20fc4ca6
authored
Jun 14, 2020
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stamina: play for real
parent
e5d72e6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
23 deletions
+45
-23
nonstop/app_settings.py
nonstop/app_settings.py
+12
-0
nonstop/management/commands/stamina.py
nonstop/management/commands/stamina.py
+31
-21
nonstop/models.py
nonstop/models.py
+2
-2
No files found.
nonstop/app_settings.py
View file @
20fc4ca6
...
...
@@ -18,5 +18,17 @@ class AppSettings:
# relative to ..._BASE_PATH
return
self
.
get_setting
(
'JINGLES_PREFIX'
,
'SPOTS'
)
@
property
def
DEBUG_WITH_SLEEPS
(
self
):
return
self
.
get_setting
(
'DEBUG_WITH_SLEEPS'
,
False
)
@
property
def
PLAYER_COMMAND
(
self
):
return
self
.
get_setting
(
'PLAYER_COMMAND'
,
'mpv'
)
@
property
def
PLAYER_ARGS
(
self
):
return
self
.
get_setting
(
'PLAYER_ARGS'
,
[])
app_settings
=
AppSettings
()
nonstop/management/commands/stamina.py
View file @
20fc4ca6
...
...
@@ -7,6 +7,7 @@ from django.core.management.base import BaseCommand
from
emissions.models
import
Nonstop
from
nonstop.models
import
Track
,
ScheduledDiffusion
,
RecurringStreamOccurence
,
RecurringRandomDirectoryOccurence
from
nonstop.app_settings
import
app_settings
class
Command
(
BaseCommand
):
...
...
@@ -82,11 +83,29 @@ 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
:
...
...
@@ -110,33 +129,24 @@ class Command(BaseCommand):
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
]
...
...
nonstop/models.py
View file @
20fc4ca6
...
...
@@ -278,7 +278,7 @@ class ScheduledDiffusion(models.Model):
def
get_jingle_filepath
(
self
):
return
self
.
jingle
.
get_local_filepath
()
if
self
.
jingle_id
else
None
def
get_sound_
filepath
(
self
):
def
file
_
path
(
self
):
# TODO, copy and stuff
return
self
.
soundfile
.
file
.
path
...
...
@@ -355,7 +355,7 @@ class RecurringRandomDirectoryOccurence(models.Model):
def
get_jingle_filepath
(
self
):
return
self
.
diffusion
.
jingle
.
get_local_filepath
()
if
self
.
diffusion
.
jingle_id
else
None
def
get_sound_
filepath
(
self
):
def
file
_
path
(
self
):
directory
=
self
.
diffusion
.
directory
return
os
.
path
.
join
(
directory
,
random
.
choice
(
os
.
listdir
(
directory
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment