Skip to content
Snippets Groups Projects
Commit fa418651 authored by David Trattnig's avatar David Trattnig
Browse files

More fixes for playlist response handling.

parent 8d04a182
No related branches found
No related tags found
No related merge requests found
...@@ -161,16 +161,6 @@ class CalendarFetcher: ...@@ -161,16 +161,6 @@ class CalendarFetcher:
def __fetch_schedule_playlist__(self, schedule, id_name, fetched_schedule_entries): def __fetch_schedule_playlist__(self, schedule, id_name, fetched_schedule_entries):
servicetype = "importer" servicetype = "importer"
# set playlist_id (in testenvironment always null => no idea)
if id_name not in schedule or schedule[id_name] is None:
playlist_id = 1
else:
playlist_id = schedule[id_name]
# set url
#url = self.url["importer"] + schedule["show_name"] + "/playlists/" + str(playlist_id)
#url = self.url["importer"] + "public" + "/playlists/" + str(playlist_id)
# fetch playlists from TANK # fetch playlists from TANK
if not "show_slug" in schedule: if not "show_slug" in schedule:
raise ValueError("Missing 'show_slug' for schedule", schedule) raise ValueError("Missing 'show_slug' for schedule", schedule)
...@@ -178,25 +168,22 @@ class CalendarFetcher: ...@@ -178,25 +168,22 @@ class CalendarFetcher:
slug = str(schedule["show_slug"]) slug = str(schedule["show_slug"])
json_response = self.__fetch_data__(servicetype, "${SLUG}", slug) json_response = self.__fetch_data__(servicetype, "${SLUG}", slug)
# use testdata if wanted
if not json_response and self.config.get("use_test_data"):
self.logger.warn("Using test-data for fetch-schedule-playlist")
use_testdata = True
# if a playlist is already fetched, do not fetch it again # if a playlist is already fetched, do not fetch it again
for entry in fetched_schedule_entries: for entry in fetched_schedule_entries:
if entry["playlist_id"] == schedule[id_name]: if entry["playlist_id"] == schedule[id_name]:
self.logger.debug("playlist #" + str(schedule[id_name]) + " already fetched") self.logger.debug("playlist #" + str(schedule[id_name]) + " already fetched")
return entry return entry
if use_testdata: if self.config.get("use_test_data"):
# FIXME move hardcoded test-data to separate testing logic. # FIXME move hardcoded test-data to separate testing logic.
self.logger.warn("Using test-data for fetch-schedule-playlist")
json_response = self.create_test_data(id_name, schedule) json_response = self.create_test_data(id_name, schedule)
# convert to list # convert to list
schedule_entries = simplejson.loads(json_response) schedule_entries = simplejson.loads(json_response)
if "results" in schedule_entries:
schedule_entries = schedule_entries["results"][0]
if "entries" in schedule_entries:
for entry in schedule_entries["entries"]: for entry in schedule_entries["entries"]:
if entry["uri"].startswith("file"): if entry["uri"].startswith("file"):
entry["filename"] = self.convert_to_filename(entry["uri"]) entry["filename"] = self.convert_to_filename(entry["uri"])
...@@ -209,7 +196,7 @@ class CalendarFetcher: ...@@ -209,7 +196,7 @@ class CalendarFetcher:
# convert to normal filename # convert to normal filename
e = self.config.get("audiofolder") + "/" + uri[7:] + ".flac" e = self.config.get("audiofolder") + "/" + uri[7:] + ".flac"
if not os.path.isfile(e): if not os.path.isfile(e):
self.logger.warning("File", e, "does not exist!") self.logger.warning("File %s does not exist!" % e)
return e return e
# ------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------ #
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment