From d22ab329d874c5b95b40a13ee0268dc039966df0 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 4 Mar 2011 12:07:22 -0500 Subject: [PATCH] -CC-1944 --- application/controllers/ApiController.php | 5 ++-- .../controllers/PreferenceController.php | 1 + application/forms/Preferences.php | 10 +++++++ application/models/Preference.php | 11 +++++++ application/models/Schedule.php | 29 ++++++++++++++----- pypo/pypofetch.py | 2 +- pypo/pypopush.py | 6 ++-- 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/application/controllers/ApiController.php b/application/controllers/ApiController.php index e6e8d1932..2a3fe6117 100644 --- a/application/controllers/ApiController.php +++ b/application/controllers/ApiController.php @@ -128,9 +128,8 @@ class ApiController extends Zend_Controller_Action if (Schedule::ValidPypoTimeFormat($from) && Schedule::ValidPypoTimeFormat($to)) { $result = Schedule::ExportRangeAsJson($from, $to); $result['stream_metadata'] = array(); - $result['stream_metadata']['format'] = "2"; - $result['stream_metadata']['station_name'] = "z103"; - $result['stream_metadata']['show_name'] = "dj danny D"; + $result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat(); + $result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName(); echo json_encode($result); } } diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index b6a6f5bea..1b8eb9e0c 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -29,6 +29,7 @@ class PreferenceController extends Zend_Controller_Action $values = $form->getValues(); Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); Application_Model_Preference::SetDefaultFade($values["stationDefaultFade"]); + Application_Model_Preference::SetStreamLabelFormat($values["streamFormat"]); $this->view->statusMsg = "Preferences Updated."; } diff --git a/application/forms/Preferences.php b/application/forms/Preferences.php index 8ecda7187..b776b8096 100644 --- a/application/forms/Preferences.php +++ b/application/forms/Preferences.php @@ -34,10 +34,20 @@ class Application_Form_Preferences extends Zend_Form 'value' => $defaultFade )); + $stream_format = new Zend_Form_Element_Radio('streamFormat'); + $stream_format->setLabel('Stream Label:'); + $stream_format->setMultiOptions(array("Artist - Title", + "Show - Artist - Title", + "Show", + "Station name - Show name")); + $stream_format->setValue(Application_Model_Preference::GetStreamLabelFormat()); + $this->addElement($stream_format); + $this->addElement('submit', 'submit', array( 'class' => 'ui-button ui-state-default', 'ignore' => true, 'label' => 'Submit', )); + } } diff --git a/application/models/Preference.php b/application/models/Preference.php index 8a75d9365..5b2f80cfa 100644 --- a/application/models/Preference.php +++ b/application/models/Preference.php @@ -86,5 +86,16 @@ class Application_Model_Preference return Application_Model_Preference::GetValue("default_fade"); } + public static function SetStreamLabelFormat($type){ + Application_Model_Preference::SetValue("stream_label_format", $type); + } + + public static function GetStreamLabelFormat(){ + return Application_Model_Preference::getValue("stream_label_format"); + } + + public static function GetStationName(){ + return Application_Model_Preference::getValue("station_name"); + } } diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 34063770d..672954123 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -396,14 +396,26 @@ class Schedule { $row["id"] = $row["group_id"]; } } else { - $sql = "SELECT MIN(name) AS name, MIN(creator) AS creator, group_id, " - ." SUM(clip_length) AS clip_length," - ." MIN(file_id) AS file_id, COUNT(*) as count," - ." MIN(playlist_id) AS playlist_id, MIN(starts) AS starts, MAX(ends) AS ends" - ." FROM $CC_CONFIG[scheduleTable]" - ." LEFT JOIN $CC_CONFIG[playListTable] ON playlist_id = $CC_CONFIG[playListTable].id" - ." WHERE (starts >= TIMESTAMP '$p_fromDateTime') AND (ends <= TIMESTAMP '$p_toDateTime')" - ." GROUP BY group_id" + $sql = "SELECT MIN(st.name) AS name," + ." MIN(pt.creator) AS creator," + ." st.group_id, " + ." SUM(st.clip_length) AS clip_length," + ." MIN(st.file_id) AS file_id," + ." COUNT(*) as count," + ." MIN(st.playlist_id) AS playlist_id," + ." MIN(st.starts) AS starts," + ." MAX(st.ends) AS ends," + ." MIN(sh.name) AS show_name" + ." FROM $CC_CONFIG[scheduleTable] as st" + ." LEFT JOIN $CC_CONFIG[playListTable] as pt" + ." ON st.playlist_id = pt.id" + ." LEFT JOIN $CC_CONFIG[showInstances] as si" + ." ON st.instance_id = si.id" + ." LEFT JOIN $CC_CONFIG[showTable] as sh" + ." ON si.show_id = sh.id" + ." WHERE (st.starts >= TIMESTAMP '$p_fromDateTime')" + ." AND (st.ends <= TIMESTAMP '$p_toDateTime')" + ." GROUP BY st.group_id" ." ORDER BY starts"; $rows = $CC_DBC->GetAll($sql); @@ -645,6 +657,7 @@ class Schedule { $playlists[$pkey]['duration'] = $dx['clip_length']; $playlists[$pkey]['played'] = '0'; $playlists[$pkey]['schedule_id'] = $dx['group_id']; + $playlists[$pkey]['show_name'] = $dx['show_name']; $playlists[$pkey]['user_id'] = 0; $playlists[$pkey]['id'] = $dx["playlist_id"]; $playlists[$pkey]['start'] = Schedule::CcTimeToPypoTime($dx["start"]); diff --git a/pypo/pypofetch.py b/pypo/pypofetch.py index 0134fd6a4..d1665ae3e 100644 --- a/pypo/pypofetch.py +++ b/pypo/pypofetch.py @@ -93,7 +93,6 @@ class PypoFetch: #encode in latin-1 due to this bug: http://bugs.python.org/issue1772794 tn.write(('vars.stream_metadata_type %s\n' % stream_metadata['format']).encode('latin-1')) - tn.write(('vars.show_name %s\n' % stream_metadata['show_name']).encode('latin-1')) tn.write(('vars.station_name %s\n' % stream_metadata['station_name']).encode('latin-1')) tn.write('exit\n') logger.debug(tn.read_all()) @@ -236,6 +235,7 @@ class PypoFetch: entry = dict() entry['type'] = 'file' entry['annotate'] = pl_entry + entry['show_name'] = playlist['show_name'] ls_playlist.append(entry) logger.debug("everything ok, adding %s to playlist", pl_entry) diff --git a/pypo/pypopush.py b/pypo/pypopush.py index 782853060..6da24da72 100644 --- a/pypo/pypopush.py +++ b/pypo/pypopush.py @@ -141,13 +141,13 @@ class PypoPush: #Sending schedule table row id string. logger.debug("vars.pypo_data %s\n"%(str(liquidsoap_data["schedule_id"]))) - tn.write("vars.pypo_data %s\n"%(str(liquidsoap_data["schedule_id"]))) + tn.write(("vars.pypo_data %s\n"%str(liquidsoap_data["schedule_id"])).encode('latin-1')) for item in playlist: annotate = str(item['annotate']) logger.debug(annotate) - tn.write('queue.push %s' % (annotate)) - tn.write("\n") + tn.write(('queue.push %s\n' % annotate).encode('latin-1')) + tn.write(('vars.show_name %s\n' % item['show_name']).encode('latin-1')) tn.write("exit\n") logger.debug(tn.read_all())