Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aura-engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Kruse
aura-engine
Commits
de452cc0
Commit
de452cc0
authored
5 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Store fallback playlists.
parent
eb3a90e4
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
libraries/database/broadcasts.py
+17
-9
17 additions, 9 deletions
libraries/database/broadcasts.py
modules/scheduling/calendar.py
+47
-32
47 additions, 32 deletions
modules/scheduling/calendar.py
modules/scheduling/calender_fetcher.py
+199
-71
199 additions, 71 deletions
modules/scheduling/calender_fetcher.py
with
263 additions
and
112 deletions
libraries/database/broadcasts.py
+
17
−
9
View file @
de452cc0
...
...
@@ -189,15 +189,15 @@ class Schedule(DB.Model, AuraDatabaseModel):
is_repetition
=
Column
(
Boolean
())
playlist_id
=
Column
(
Integer
)
#, ForeignKey("playlist.playlist_id"))
timeslot
_fallback_id
=
Column
(
Integer
)
schedule
_fallback_id
=
Column
(
Integer
)
show_fallback_id
=
Column
(
Integer
)
station_fallback_id
=
Column
(
Integer
)
playlist
=
relationship
(
"
Playlist
"
,
primaryjoin
=
"
and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.playlist_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)
"
,
back_populates
=
"
schedule
"
)
timeslot
_fallback
=
relationship
(
"
Playlist
"
,
primaryjoin
=
"
and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.
timeslot
_fallback_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)
"
,
schedule
_fallback
=
relationship
(
"
Playlist
"
,
primaryjoin
=
"
and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.
schedule
_fallback_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)
"
,
back_populates
=
"
schedule
"
)
show_fallback
=
relationship
(
"
Playlist
"
,
primaryjoin
=
"
and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.show_fallback_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)
"
,
...
...
@@ -289,12 +289,20 @@ class Playlist(DB.Model, AuraDatabaseModel):
Raises:
Exception: In case there a inconsistent database state, such es multiple playlists for given date/time.
"""
playlists
=
DB
.
session
.
query
(
Playlist
).
filter
(
Playlist
.
schedule_start
==
datetime
and
Playlist
.
playlist_id
==
playlist_id
).
all
()
if
playlists
and
len
(
playlists
)
>
1
:
raise
Exception
(
"
Inconsistent Database State: Multiple playlists for given schedule
'
%s
'
and playlist id#%d available!
"
%
(
str
(
datetime
),
playlist_id
))
if
not
playlists
:
return
None
return
playlists
[
0
]
playlist
=
None
playlists
=
DB
.
session
.
query
(
Playlist
).
filter
(
Playlist
.
schedule_start
==
datetime
).
all
()
# FIXME There are unknown issues with the native SQL query by ID
# playlists = DB.session.query(Playlist).filter(Playlist.schedule_start == datetime and Playlist.playlist_id == playlist_id).all()
for
p
in
playlists
:
if
p
.
playlist_id
==
playlist_id
:
playlist
=
p
# if playlists and len(playlists) > 1:
# raise Exception("Inconsistent Database State: Multiple playlists for given schedule '%s' and playlist id#%d available!" % (str(datetime), playlist_id))
# if not playlists:
# return None
# return playlists[0]
return
playlist
@staticmethod
...
...
This diff is collapsed.
Click to expand it.
modules/scheduling/calendar.py
+
47
−
32
View file @
de452cc0
...
...
@@ -52,7 +52,8 @@ class AuraCalendarService(threading.Thread):
_stop_event
=
None
logger
=
None
fetched_schedule_data
=
None
url
=
dict
()
# FIXME is it needed?
#url = dict()
data
=
dict
()
calendar_fetcher
=
None
...
...
@@ -75,8 +76,9 @@ class AuraCalendarService(threading.Thread):
self
.
_stop_event
=
threading
.
Event
()
self
.
__set_url__
(
"
calendar
"
)
self
.
__set_url__
(
"
importer
"
)
# FIXME is it needed?
# self.__set_url__("api_calendar_url")
# self.__set_url__("api_playlist_url")
self
.
calendar_fetcher
=
CalendarFetcher
(
config
)
...
...
@@ -141,26 +143,28 @@ class AuraCalendarService(threading.Thread):
self
.
logger
.
debug
(
"
Schedule data:
"
+
str
(
fetched_schedule_data
))
ret_schedule
=
[]
# for schedule in self.fetched_schedule_data:
# if "start" not in schedule:
# self.logger.warning("No start of schedule given. skipping the schedule: "+str(schedule))
# continue
# if "end" not in schedule:
# self.logger.warning("No end of schedule given. skipping the schedule: "+str(schedule))
# continue
for
schedule
in
fetched_schedule_data
:
# Check schedule for validity
if
"
start
"
not
in
schedule
:
self
.
logger
.
warning
(
"
No
'
start
'
of schedule given. Skipping the schedule: %s
"
%
str
(
schedule
))
continue
if
"
end
"
not
in
schedule
:
self
.
logger
.
warning
(
"
No
'
end
'
of schedule given. Skipping the schedule: %s
"
%
str
(
schedule
))
continue
# Store the schedule
schedule_db
=
self
.
store_schedule
(
schedule
)
# Store playlists to play
self
.
logger
.
warning
(
"
--- Storing playlist only ---
"
)
self
.
store_playlist
(
schedule_db
,
schedule_db
.
playlist_id
,
schedule
[
"
playlist
"
])
#FIXME Store fallbacks in DB logic
# self.store_schedule_playlist(schedule_db, schedule, "schedule_fallback", 1)
# self.store_schedule_playlist(schedule_db, schedule, "show_fallback", 2)
# self.store_schedule_playlist(schedule_db, schedule, "station_fallback", 3)
if
schedule_db
.
schedule_fallback_id
:
self
.
store_playlist
(
schedule_db
,
schedule_db
.
schedule_fallback_id
,
schedule
[
"
schedule_fallback
"
],
1
)
if
schedule_db
.
show_fallback_id
:
self
.
store_playlist
(
schedule_db
,
schedule_db
.
show_fallback_id
,
schedule
[
"
show_fallback
"
],
2
)
if
schedule_db
.
station_fallback_id
:
self
.
store_playlist
(
schedule_db
,
schedule_db
.
station_fallback_id
,
schedule
[
"
station_fallback
"
],
3
)
ret_schedule
.
append
(
schedule_db
)
...
...
@@ -215,9 +219,9 @@ class AuraCalendarService(threading.Thread):
schedule_db
.
topic
=
schedule
[
"
show_topics
"
]
schedule_db
.
musicfocus
=
schedule
[
"
show_musicfocus
"
]
if
schedule
[
"
playlist_id
"
]
is
None
:
# FIXME Manually assigned playlist ID.
schedule
[
"
playlist_id
"
]
=
1
#
if schedule["playlist_id"] is None:
#
# FIXME Manually assigned playlist ID.
#
schedule["playlist_id"] = 1
schedule_db
.
playlist_id
=
schedule
[
"
playlist_id
"
]
schedule_db
.
schedule_fallback_id
=
schedule
[
"
schedule_fallback_id
"
]
...
...
@@ -228,7 +232,8 @@ class AuraCalendarService(threading.Thread):
return
schedule_db
# ------------------------------------------------------------------------------------------ #
def
store_playlist
(
self
,
schedule_db
,
playlist_id
,
fetched_playlist
,
fallbackplaylist_type
=
0
):
"""
Stores the Playlist to the database.
...
...
@@ -245,15 +250,20 @@ class AuraCalendarService(threading.Thread):
playlist_db
.
schedule_start
=
schedule_db
.
schedule_start
playlist_db
.
show_name
=
schedule_db
.
show_name
playlist_db
.
fallback_type
=
fallbackplaylist_type
playlist_db
.
entry_count
=
len
(
fetched_playlist
[
"
entries
"
])
if
"
entries
"
in
fetched_playlist
:
playlist_db
.
entry_count
=
len
(
fetched_playlist
[
"
entries
"
])
else
:
playlist_db
.
entry_count
=
0
playlist_db
.
store
(
havetoadd
,
commit
=
True
)
self
.
store_playlist_entries
(
playlist_db
,
fetched_playlist
)
if
playlist_db
.
entry_count
>
0
:
self
.
store_playlist_entries
(
playlist_db
,
fetched_playlist
)
return
playlist_db
def
store_playlist_entries
(
self
,
playlist_db
,
fetched_playlist
):
"""
Stores the playlist entries to the database.
...
...
@@ -285,6 +295,8 @@ class AuraCalendarService(threading.Thread):
entry_num
=
entry_num
+
1
time_marker
+=
duration
def
store_playlist_entry_metadata
(
self
,
playlistentry_db
,
metadata
):
"""
Stores the meta-data for a PlaylistEntry.
...
...
@@ -297,8 +309,8 @@ class AuraCalendarService(threading.Thread):
playlistentrymetadata_db
.
artificial_entry_id
=
playlistentry_db
.
artificial_id
if
"
artist
"
not
in
metadata
:
self
.
logger
.
warning
(
"
Artist not found in metadata for track
'
%s
'
. Setting to
'
N
/a
'"
%
playlistentry_db
.
filename
)
playlistentrymetadata_db
.
artist
=
"
N
/a
"
self
.
logger
.
warning
(
"
Artist not found in metadata for track
'
%s
'
. Setting to
'
n
/a
'"
%
playlistentry_db
.
filename
)
playlistentrymetadata_db
.
artist
=
"
n
/a
"
else
:
playlistentrymetadata_db
.
artist
=
metadata
[
"
artist
"
]
playlistentrymetadata_db
.
title
=
metadata
[
"
title
"
]
...
...
@@ -307,6 +319,7 @@ class AuraCalendarService(threading.Thread):
playlistentrymetadata_db
.
store
(
havetoadd
,
commit
=
True
)
# ------------------------------------------------------------------------------------------ #
# FIXME Needed?
...
...
@@ -380,15 +393,17 @@ class AuraCalendarService(threading.Thread):
return
audio_file
.
info
.
length
# ------------------------------------------------------------------------------------------ #
def
__set_url__
(
self
,
type
):
url
=
self
.
config
.
get
(
type
+
"
url
"
)
pos
=
url
.
find
(
"
?
"
)
# FIXME is it needed?
if
pos
>
0
:
self
.
url
[
type
]
=
url
[
0
:
pos
]
self
.
data
[
type
]
=
url
[
pos
:]
else
:
self
.
url
[
type
]
=
url
# def __set_url__(self, type):
# #url = self.config.get(type+"url")
# pos = url.find("?")
# if pos > 0:
# self.url[type] = url[0:pos]
# self.data[type] = url[pos:]
# else:
# self.url[type] = url
# ------------------------------------------------------------------------------------------ #
def
stop
(
self
):
...
...
This diff is collapsed.
Click to expand it.
modules/scheduling/calender_fetcher.py
+
199
−
71
View file @
de452cc0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment