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
e5d72e6b
Commit
e5d72e6b
authored
Jun 14, 2020
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle mix deliveries
parent
df8a87f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
8 deletions
+57
-8
nonstop/management/commands/stamina.py
nonstop/management/commands/stamina.py
+28
-6
nonstop/models.py
nonstop/models.py
+29
-2
No files found.
nonstop/management/commands/stamina.py
View file @
e5d72e6b
...
...
@@ -6,7 +6,7 @@ import signal
from
django.core.management.base
import
BaseCommand
from
emissions.models
import
Nonstop
from
nonstop.models
import
Track
,
ScheduledDiffusion
,
RecurringStreamOccurence
from
nonstop.models
import
Track
,
ScheduledDiffusion
,
RecurringStreamOccurence
,
RecurringRandomDirectoryOccurence
class
Command
(
BaseCommand
):
...
...
@@ -117,14 +117,25 @@ class Command(BaseCommand):
self
.
playhead
+=
1
elif
slot
.
is_stream
():
print
(
now
,
'playing stream'
,
slot
.
stream
)
# TODO: jingle
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
print
(
'timeout at'
,
(
slot
.
end_datetime
-
now
).
total_seconds
())
await
self
.
player_process
(
cmd
,
timeout
=
(
slot
.
end_datetime
-
now
).
total_seconds
())
else
:
print
(
now
,
'playing sound'
,
slot
.
episode
)
# TODO: jingle
cmd
=
'sleep %s # %s'
%
(
slot
.
soundfile
.
duration
,
slot
.
episode
)
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
)
def
recompute_playlist
(
self
):
...
...
@@ -143,12 +154,17 @@ class Command(BaseCommand):
occurence
=
RecurringStreamOccurence
.
objects
.
filter
(
datetime__gt
=
now
-
datetime
.
timedelta
(
days
=
1
),
datetime__lt
=
now
).
order_by
(
'datetime'
).
last
()
# note it shouldn't be possible to have both diffusion and occurence
directory_occurence
=
RecurringRandomDirectoryOccurence
.
objects
.
filter
(
datetime__gt
=
now
-
datetime
.
timedelta
(
days
=
1
),
datetime__lt
=
now
).
order_by
(
'datetime'
).
last
()
# note it shouldn't be possible to have both diffusion and occurences
# running at the moment.
if
occurence
and
occurence
.
end_datetime
>
now
:
return
occurence
if
diffusion
and
diffusion
.
end_datetime
>
now
:
return
diffusion
if
directory_occurence
and
directory_occurence
.
end_datetime
>
now
:
return
directory_occurence
return
None
def
get_next_diffusion
(
self
,
before_datetime
):
...
...
@@ -161,12 +177,18 @@ class Command(BaseCommand):
datetime__gt
=
now
,
datetime__lt
=
before_datetime
,
).
order_by
(
'datetime'
).
first
()
directory_occurence
=
RecurringRandomDirectoryOccurence
.
objects
.
filter
(
datetime__gt
=
now
,
datetime__lt
=
before_datetime
,
).
order_by
(
'datetime'
).
first
()
if
diffusion
and
occurence
:
return
diffusion
if
diffusion
.
diffusion__datetime
<
occurence
.
datetime
else
occurence
if
diffusion
:
return
diffusion
if
occurence
:
return
occurence
if
directory_occurence
:
return
directory_occurence
return
None
def
recompute_slots
(
self
):
...
...
nonstop/models.py
View file @
e5d72e6b
import
datetime
import
os
import
mutagen
import
random
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
...
...
@@ -276,6 +275,13 @@ class ScheduledDiffusion(models.Model):
def
is_stream
(
self
):
return
bool
(
self
.
stream_id
)
def
get_jingle_filepath
(
self
):
return
self
.
jingle
.
get_local_filepath
()
if
self
.
jingle_id
else
None
def
get_sound_filepath
(
self
):
# TODO, copy and stuff
return
self
.
soundfile
.
file
.
path
class
NonstopZoneSettings
(
models
.
Model
):
nonstop
=
models
.
ForeignKey
(
'emissions.Nonstop'
,
on_delete
=
models
.
CASCADE
)
...
...
@@ -315,6 +321,9 @@ class RecurringStreamOccurence(models.Model):
def
is_stream
(
self
):
return
True
def
get_jingle_filepath
(
self
):
return
self
.
diffusion
.
jingle
.
get_local_filepath
()
if
self
.
diffusion
.
jingle_id
else
None
class
RecurringRandomDirectoryDiffusion
(
models
.
Model
):
# between soundfiles and nonstop zones, this is used for the "mix
...
...
@@ -332,6 +341,24 @@ class RecurringRandomDirectoryOccurence(models.Model):
diffusion
=
models
.
ForeignKey
(
RecurringRandomDirectoryDiffusion
,
on_delete
=
models
.
CASCADE
)
datetime
=
models
.
DateTimeField
(
_
(
'Date/time'
),
db_index
=
True
)
@
property
def
duration
(
self
):
return
self
.
diffusion
.
schedule
.
get_duration
()
*
60
@
property
def
end_datetime
(
self
):
return
self
.
datetime
+
datetime
.
timedelta
(
minutes
=
self
.
diffusion
.
schedule
.
get_duration
())
def
is_stream
(
self
):
return
False
def
get_jingle_filepath
(
self
):
return
self
.
diffusion
.
jingle
.
get_local_filepath
()
if
self
.
diffusion
.
jingle_id
else
None
def
get_sound_filepath
(
self
):
directory
=
self
.
diffusion
.
directory
return
os
.
path
.
join
(
directory
,
random
.
choice
(
os
.
listdir
(
directory
)))
@
receiver
(
post_delete
)
def
remove_soundfile
(
sender
,
instance
=
None
,
**
kwargs
):
...
...
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