Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lars Kruse
aura-engine
Commits
0ad560a2
Commit
0ad560a2
authored
Aug 28, 2020
by
David Trattnig
Browse files
PUT clock info to engine api. #28
parent
b397c751
Changes
1
Hide whitespace changes
Inline
Side-by-side
modules/plugins/trackservice.py
View file @
0ad560a2
...
...
@@ -27,12 +27,12 @@ from modules.base.utils import SimpleUtil as SU
class
TrackserviceHandler
():
"""
Sends the trackservice entry to the `engine-api` REST endpoint.
Sends the trackservice entry
and studio clock information
to the `engine-api` REST endpoint.
"""
logger
=
None
config
=
None
soundsystem
=
None
last_
schedule
=
None
last_
playlist
=
None
def
__init__
(
self
,
config
,
soundsystem
):
...
...
@@ -49,7 +49,7 @@ class TrackserviceHandler():
Some track started playing.
"""
self
.
store_trackservice
(
entry
)
self
.
store_
show
_info
(
entry
)
self
.
store_
clock
_info
(
entry
)
def
store_trackservice
(
self
,
entry
):
...
...
@@ -57,33 +57,88 @@ class TrackserviceHandler():
Posts the given `PlaylistEntry` to the Engine API Playlog.
"""
data
=
dict
()
data
[
"track_start"
]
=
entry
.
entry_start
diff
=
(
entry
.
entry_start_actual
-
entry
.
entry_start
).
total_seconds
()
self
.
logger
.
info
(
"There's a difference of %s seconds between planned and actual start of the entry"
%
diff
)
data
[
"track_start"
]
=
entry
.
entry_start_actual
data
[
"track_artist"
]
=
entry
.
meta_data
.
artist
data
[
"track_album"
]
=
entry
.
meta_data
.
album
data
[
"track_title"
]
=
entry
.
meta_data
.
title
data
[
"track_duration"
]
=
entry
.
duration
data
[
"track_type"
]
=
entry
.
get_type
().
numeric
data
[
"
timeslot
_id"
]
=
entry
.
playlist
.
schedule
.
schedule_id
data
[
"
schedule
_id"
]
=
entry
.
playlist
.
schedule
.
schedule_id
data
[
"show_name"
]
=
entry
.
playlist
.
schedule
.
show_name
data
[
"log_source"
]
=
self
.
config
.
get
(
"api_engine_number"
)
data
=
SU
.
clean_dictionary
(
data
)
self
.
logger
.
info
(
"Posting schedule update to Engine API..."
)
url
=
self
.
config
.
get
(
"api_engine_playlog
_url
"
)
url
=
self
.
config
.
get
(
"api_engine_
store_
playlog"
)
headers
=
{
'content-type'
:
'application/json'
}
body
=
json
.
dumps
(
data
,
indent
=
4
,
sort_keys
=
True
,
default
=
str
)
response
=
requests
.
post
(
url
,
data
=
body
,
headers
=
headers
)
self
.
logger
.
info
(
"Engine API response: %s"
%
response
.
status_code
)
def
store_show_info
(
self
,
entry
):
def
store_clock_info
(
self
,
entry
):
"""
Posts the current and next show information to the Engine API.
"""
current_
schedule
=
entry
.
playlist
.
schedule
if
current_
schedule
==
self
.
last_
schedule
:
self
.
logger
.
info
(
"
Schedule
didn't change since last update."
)
current_
playlist
=
entry
.
playlist
if
current_
playlist
==
self
.
last_
playlist
:
self
.
logger
.
info
(
"
Playlist
didn't change since last update."
)
else
:
self
.
logger
.
info
(
"Posting schedule update to Engine API..."
)
# TODO Implement
\ No newline at end of file
self
.
last_playlist
=
current_playlist
current_schedule
=
current_playlist
.
schedule
next_schedule
=
self
.
soundsystem
.
scheduler
.
get_next_schedules
(
1
)
if
next_schedule
:
next_schedule
=
next_schedule
[
0
]
data
=
dict
()
data
[
"engine_source"
]
=
self
.
config
.
get
(
"api_engine_number"
)
if
current_playlist
:
data
[
"current_playlist"
]
=
dict
()
data
[
"current_playlist"
][
"playlist_id"
]
=
current_playlist
.
playlist_id
data
[
"current_playlist"
][
"entries"
]
=
[]
for
e
in
current_playlist
.
entries
:
entry
=
dict
()
entry
[
"track_start"
]
=
e
.
entry_start
entry
[
"track_artist"
]
=
e
.
meta_data
.
artist
entry
[
"track_album"
]
=
e
.
meta_data
.
album
entry
[
"track_title"
]
=
e
.
meta_data
.
title
entry
[
"track_duration"
]
=
e
.
duration
entry
[
"track_type"
]
=
e
.
get_type
().
numeric
entry
=
SU
.
clean_dictionary
(
entry
)
data
[
"current_playlist"
][
"entries"
].
append
(
entry
)
if
current_schedule
:
cs
=
dict
()
cs
[
"schedule_id"
]
=
current_schedule
.
schedule_id
cs
[
"schedule_start"
]
=
current_schedule
.
schedule_start
cs
[
"schedule_end"
]
=
current_schedule
.
schedule_end
cs
[
"show_id"
]
=
current_schedule
.
show_id
cs
[
"show_name"
]
=
current_schedule
.
show_name
cs
[
"playlist_id"
]
=
current_schedule
.
playlist_id
cs
[
"fallback_type"
]
=
current_schedule
.
fallback_state
.
id
cs
=
SU
.
clean_dictionary
(
cs
)
data
[
"current_schedule"
]
=
cs
if
next_schedule
:
ns
=
dict
()
ns
[
"schedule_id"
]
=
next_schedule
.
schedule_id
ns
[
"schedule_start"
]
=
next_schedule
.
schedule_start
ns
[
"schedule_end"
]
=
next_schedule
.
schedule_end
ns
[
"show_id"
]
=
next_schedule
.
show_id
ns
[
"show_name"
]
=
next_schedule
.
show_name
ns
[
"playlist_id"
]
=
next_schedule
.
playlist_id
ns
[
"fallback_type"
]
=
next_schedule
.
fallback_state
.
id
ns
=
SU
.
clean_dictionary
(
ns
)
data
[
"next_schedule"
]
=
ns
data
=
SU
.
clean_dictionary
(
data
)
self
.
logger
.
info
(
"Posting clock info update to Engine API..."
)
url
=
self
.
config
.
get
(
"api_engine_store_clock"
)
headers
=
{
'content-type'
:
'application/json'
}
body
=
json
.
dumps
(
data
,
indent
=
4
,
sort_keys
=
True
,
default
=
str
)
response
=
requests
.
put
(
url
,
data
=
body
,
headers
=
headers
)
self
.
logger
.
info
(
"Engine API response: %s"
%
response
.
status_code
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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