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
c3f21f38
Commit
c3f21f38
authored
Jul 02, 2020
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stamina: record played tracks
parent
b7771b86
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
nonstop/app_settings.py
nonstop/app_settings.py
+4
-0
nonstop/management/commands/stamina.py
nonstop/management/commands/stamina.py
+35
-1
No files found.
nonstop/app_settings.py
View file @
c3f21f38
...
...
@@ -30,5 +30,9 @@ class AppSettings:
def
PLAYER_ARGS
(
self
):
return
self
.
get_setting
(
'PLAYER_ARGS'
,
[])
@
property
def
ON_AIR_SWITCH_URL
(
self
):
return
self
.
get_setting
(
'ON_AIR_SWITCH_URL'
,
None
)
app_settings
=
AppSettings
()
nonstop/management/commands/stamina.py
View file @
c3f21f38
...
...
@@ -3,10 +3,12 @@ import datetime
import
random
import
signal
import
requests
from
django.core.management.base
import
BaseCommand
from
emissions.models
import
Nonstop
from
nonstop.models
import
Track
,
ScheduledDiffusion
,
RecurringStreamOccurence
,
RecurringRandomDirectoryOccurence
from
nonstop.models
import
Track
,
SomaLogLine
,
ScheduledDiffusion
,
RecurringStreamOccurence
,
RecurringRandomDirectoryOccurence
from
nonstop.app_settings
import
app_settings
...
...
@@ -94,6 +96,33 @@ class Command(BaseCommand):
return
playlist
def
is_nonstop_on_air
(
self
):
# check if nonstop system is currently on air
if
app_settings
.
ON_AIR_SWITCH_URL
is
None
:
return
None
switch_response
=
requests
.
get
(
app_settings
.
ON_AIR_SWITCH_URL
,
timeout
=
5
)
if
not
switch_response
.
ok
:
return
None
try
:
status
=
switch_response
.
json
()
except
ValueError
:
return
None
if
status
.
get
(
'active'
)
==
0
:
return
True
elif
status
.
get
(
'active'
)
==
1
and
status
.
get
(
'nonstop-via-stud1'
)
==
0
:
return
True
elif
status
.
get
(
'active'
)
==
2
and
status
.
get
(
'nonstop-via-stud2'
)
==
1
:
return
True
return
False
async
def
record_nonstop_line
(
self
,
track
,
now
):
log_line
=
SomaLogLine
()
log_line
.
play_timestamp
=
now
log_line
.
track
=
track
log_line
.
filepath
=
track
.
nonstopfile_set
.
first
()
log_line
.
on_air
=
self
.
is_nonstop_on_air
()
log_line
.
save
()
async
def
player_process
(
self
,
item
,
timeout
=
None
):
if
app_settings
.
DEBUG_WITH_SLEEPS
:
if
hasattr
(
item
,
'is_stream'
)
and
item
.
is_stream
():
...
...
@@ -141,7 +170,12 @@ 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
]])
record_task
=
None
if
isinstance
(
track
,
Track
):
# not jingles
record_task
=
asyncio
.
create_task
(
self
.
record_nonstop_line
(
track
,
datetime
.
datetime
.
now
()))
await
self
.
player_process
(
track
)
if
record_task
:
await
record_task
if
self
.
softstop
:
# track was left to finish, but now the playlist should stop.
break
...
...
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