From 76f202106b7c9fb9be2994e8715a9f4fb54991b0 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 30 Oct 2015 17:12:13 -0400 Subject: [PATCH 01/15] Defensive coding against Silan bugs and bump to Mutagen 1.31 --- .../airtime_analyzer/cuepoint_analyzer.py | 33 ++++++++++++++++--- .../airtime_analyzer/metadata_analyzer.py | 7 ++-- python_apps/airtime_analyzer/setup.py | 2 +- .../tests/metadata_analyzer_tests.py | 12 +++---- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py index 8a99626c6..bf124ac18 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py @@ -28,12 +28,35 @@ class CuePointAnalyzer(Analyzer): try: results_json = subprocess.check_output(command, stderr=subprocess.STDOUT, close_fds=True) silan_results = json.loads(results_json) - metadata['length_seconds'] = float(silan_results['file duration']) + + # Defensive coding against Silan wildly miscalculating the cue in and out times: + silan_length_seconds = float(silan_results['file duration']) + silan_cuein = format(silan_results['sound'][0][0], 'f') + silan_cueout = format(silan_results['sound'][0][1], 'f') + + # Sanity check the results against any existing metadata passed to us (presumably extracted by Mutagen): + if 'length_seconds' in metadata: + # Silan has a rare bug where it can massively overestimate the length or cue out time sometimes. + if (silan_length_seconds - metadata['length_seconds'] > 3) or (float(silan_cueout) > metadata['length_seconds']): + # Don't trust anything silan says then... + raise Exception("Silan cue out {0} or length {1} differs too much from the mutagen length {2}." + .format(silan_cueout, silan_length_seconds, metadata['length_seconds'])) + # Don't allow silan to trim more than the greater of 3 seconds or 5% off the start of a track + if float(silan_cuein) > max(silan_length_seconds*0.05, 3): + raise Exception("Silan cue in time {0} too big, ignoring.".format(silan_cuein)) + + + ''' XXX: I've commented out the track_length stuff below because Mutagen seems more accurate than silan + as of Mutagen version 1.31. We are always going to use Mutagen's length now because Silan's + length can be off by a few seconds reasonably often. + ''' + # Conver the length into a formatted time string - track_length = datetime.timedelta(seconds=metadata['length_seconds']) - metadata["length"] = str(track_length) - metadata['cuein'] = format(silan_results['sound'][0][0], 'f') - metadata['cueout'] = format(silan_results['sound'][0][1], 'f') + #metadata['length_seconds'] = silan_length_seconds # + #track_length = datetime.timedelta(seconds=metadata['length_seconds']) + #metadata["length"] = str(track_length) + metadata['cuein'] = silan_cuein + metadata['cueout'] = silan_cueout except OSError as e: # silan was not found logging.warn("Failed to run: %s - %s. %s" % (command[0], e.strerror, "Do you have silan installed?")) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/metadata_analyzer.py b/python_apps/airtime_analyzer/airtime_analyzer/metadata_analyzer.py index 58fc1d56e..61a4cbe25 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/metadata_analyzer.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/metadata_analyzer.py @@ -67,8 +67,11 @@ class MetadataAnalyzer(Analyzer): track_length = datetime.timedelta(seconds=info.length) metadata["length"] = str(track_length) #time.strftime("%H:%M:%S.%f", track_length) # Other fields for Airtime - metadata["cueout"] = metadata["length"] - + metadata["cueout"] = metadata["length"] + + # Set a default cue in time in seconds + metadata["cuein"] = 0.0; + if hasattr(info, "bitrate"): metadata["bit_rate"] = info.bitrate diff --git a/python_apps/airtime_analyzer/setup.py b/python_apps/airtime_analyzer/setup.py index 47e231123..b2c643c48 100644 --- a/python_apps/airtime_analyzer/setup.py +++ b/python_apps/airtime_analyzer/setup.py @@ -27,7 +27,7 @@ setup(name='airtime_analyzer', packages=['airtime_analyzer'], scripts=['bin/airtime_analyzer'], install_requires=[ - 'mutagen', + 'mutagen=1.31', # The Mutagen guys change stuff all the time that break our unit tests. Watch out for this. 'pika', 'daemon', 'python-magic', diff --git a/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py b/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py index ee108b362..8a2d59967 100644 --- a/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py +++ b/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py @@ -24,7 +24,7 @@ def test_mp3_mono(): metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.mp3', dict()) check_default_metadata(metadata) assert metadata['channels'] == 1 - assert metadata['bit_rate'] == 64000 + assert metadata['bit_rate'] == 64876 assert abs(metadata['length_seconds'] - 3.9) < 0.1 assert metadata['mime'] == 'audio/mp3' # Not unicode because MIMEs aren't. assert metadata['track_total'] == u'10' # MP3s can have a track_total @@ -34,7 +34,7 @@ def test_mp3_jointstereo(): metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-jointstereo.mp3', dict()) check_default_metadata(metadata) assert metadata['channels'] == 2 - assert metadata['bit_rate'] == 128000 + assert metadata['bit_rate'] == 129757 assert abs(metadata['length_seconds'] - 3.9) < 0.1 assert metadata['mime'] == 'audio/mp3' assert metadata['track_total'] == u'10' # MP3s can have a track_total @@ -43,7 +43,7 @@ def test_mp3_simplestereo(): metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-simplestereo.mp3', dict()) check_default_metadata(metadata) assert metadata['channels'] == 2 - assert metadata['bit_rate'] == 128000 + assert metadata['bit_rate'] == 129757 assert abs(metadata['length_seconds'] - 3.9) < 0.1 assert metadata['mime'] == 'audio/mp3' assert metadata['track_total'] == u'10' # MP3s can have a track_total @@ -52,7 +52,7 @@ def test_mp3_dualmono(): metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-dualmono.mp3', dict()) check_default_metadata(metadata) assert metadata['channels'] == 2 - assert metadata['bit_rate'] == 128000 + assert metadata['bit_rate'] == 129757 assert abs(metadata['length_seconds'] - 3.9) < 0.1 assert metadata['mime'] == 'audio/mp3' assert metadata['track_total'] == u'10' # MP3s can have a track_total @@ -109,7 +109,7 @@ def test_mp3_utf8(): assert metadata['genre'] == u'Я Б Г Д Ж Й' assert metadata['track_number'] == u'1' assert metadata['channels'] == 2 - assert metadata['bit_rate'] == 128000 + assert metadata['bit_rate'] == 129757 assert abs(metadata['length_seconds'] - 3.9) < 0.1 assert metadata['mime'] == 'audio/mp3' assert metadata['track_total'] == u'10' # MP3s can have a track_total @@ -153,7 +153,7 @@ def test_mp3_bad_channels(): metadata = MetadataAnalyzer.analyze(filename, dict()) check_default_metadata(metadata) assert metadata['channels'] == 1 - assert metadata['bit_rate'] == 64000 + assert metadata['bit_rate'] == 64876 assert abs(metadata['length_seconds'] - 3.9) < 0.1 assert metadata['mime'] == 'audio/mp3' # Not unicode because MIMEs aren't. assert metadata['track_total'] == u'10' # MP3s can have a track_total From fc51e6321461d4f2dd06e9ff447e44349c19bbd6 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 30 Oct 2015 17:13:12 -0400 Subject: [PATCH 02/15] Fix typo in airtime_analyzer setup.py --- python_apps/airtime_analyzer/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/airtime_analyzer/setup.py b/python_apps/airtime_analyzer/setup.py index b2c643c48..c9f33f45a 100644 --- a/python_apps/airtime_analyzer/setup.py +++ b/python_apps/airtime_analyzer/setup.py @@ -27,7 +27,7 @@ setup(name='airtime_analyzer', packages=['airtime_analyzer'], scripts=['bin/airtime_analyzer'], install_requires=[ - 'mutagen=1.31', # The Mutagen guys change stuff all the time that break our unit tests. Watch out for this. + 'mutagen==1.31', # The Mutagen guys change stuff all the time that break our unit tests. Watch out for this. 'pika', 'daemon', 'python-magic', From 7be548f30ea39166b827df91c8e69c0c6e2b2a53 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 30 Oct 2015 17:15:33 -0400 Subject: [PATCH 03/15] Fixed the airtime_analyzer unit tests --- .../airtime_analyzer/cuepoint_analyzer.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py index bf124ac18..3c55d75e7 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py @@ -44,6 +44,13 @@ class CuePointAnalyzer(Analyzer): # Don't allow silan to trim more than the greater of 3 seconds or 5% off the start of a track if float(silan_cuein) > max(silan_length_seconds*0.05, 3): raise Exception("Silan cue in time {0} too big, ignoring.".format(silan_cuein)) + else: + # Only use the Silan track length in the worst case, where Mutagen didn't give us one for some reason. + # (This is mostly to make the unit tests still pass.) + # Convert the length into a formatted time string. + metadata['length_seconds'] = silan_length_seconds # + track_length = datetime.timedelta(seconds=metadata['length_seconds']) + metadata["length"] = str(track_length) ''' XXX: I've commented out the track_length stuff below because Mutagen seems more accurate than silan @@ -51,10 +58,6 @@ class CuePointAnalyzer(Analyzer): length can be off by a few seconds reasonably often. ''' - # Conver the length into a formatted time string - #metadata['length_seconds'] = silan_length_seconds # - #track_length = datetime.timedelta(seconds=metadata['length_seconds']) - #metadata["length"] = str(track_length) metadata['cuein'] = silan_cuein metadata['cueout'] = silan_cueout From b49bb2e2624fc0a1019db1fa05ca13f6373a56ab Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 30 Oct 2015 17:54:24 -0400 Subject: [PATCH 04/15] Loosen up Mutagen vs. Silan cue out length threshold a bit --- .../airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py index 3c55d75e7..e51b61ce2 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py @@ -37,7 +37,7 @@ class CuePointAnalyzer(Analyzer): # Sanity check the results against any existing metadata passed to us (presumably extracted by Mutagen): if 'length_seconds' in metadata: # Silan has a rare bug where it can massively overestimate the length or cue out time sometimes. - if (silan_length_seconds - metadata['length_seconds'] > 3) or (float(silan_cueout) > metadata['length_seconds']): + if (silan_length_seconds - metadata['length_seconds'] > 3) or (float(silan_cueout) - metadata['length_seconds'] > 2): # Don't trust anything silan says then... raise Exception("Silan cue out {0} or length {1} differs too much from the mutagen length {2}." .format(silan_cueout, silan_length_seconds, metadata['length_seconds'])) From c85944785bdff3abca8789cfd8a70a0966fab449 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 30 Oct 2015 18:09:56 -0400 Subject: [PATCH 05/15] Comments --- .../airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py index e51b61ce2..47a517b59 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/cuepoint_analyzer.py @@ -39,7 +39,7 @@ class CuePointAnalyzer(Analyzer): # Silan has a rare bug where it can massively overestimate the length or cue out time sometimes. if (silan_length_seconds - metadata['length_seconds'] > 3) or (float(silan_cueout) - metadata['length_seconds'] > 2): # Don't trust anything silan says then... - raise Exception("Silan cue out {0} or length {1} differs too much from the mutagen length {2}." + raise Exception("Silan cue out {0} or length {1} differs too much from the Mutagen length {2}. Ignoring Silan values." .format(silan_cueout, silan_length_seconds, metadata['length_seconds'])) # Don't allow silan to trim more than the greater of 3 seconds or 5% off the start of a track if float(silan_cuein) > max(silan_length_seconds*0.05, 3): From 685134d8bbc14094c2a9e3e6424511059b3e1ffd Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Thu, 5 Nov 2015 12:45:09 -0500 Subject: [PATCH 06/15] Better trial suspension notice --- airtime_mvc/application/common/Billing.php | 3 ++- .../application/controllers/BillingController.php | 6 ++++++ airtime_mvc/application/layouts/scripts/layout.phtml | 6 ++++-- .../views/scripts/partialviews/suspendedtrial.phtml | 9 +++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 airtime_mvc/application/views/scripts/partialviews/suspendedtrial.phtml diff --git a/airtime_mvc/application/common/Billing.php b/airtime_mvc/application/common/Billing.php index 2dbfafa9a..6bbbdcda5 100644 --- a/airtime_mvc/application/common/Billing.php +++ b/airtime_mvc/application/common/Billing.php @@ -126,7 +126,8 @@ class Billing } else { - if ($product["status"] === "Active") { + if ($product["status"] === "Active" || + $product["status"] === "Suspended") { $airtimeProduct = $product; $subdomain = ''; diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index bf508036b..bf4aafb1d 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -21,6 +21,12 @@ class BillingController extends Zend_Controller_Action { public function upgradeAction() { + //If you're not on a trial and you're suspended, we don't let you access the plans page and redirect you to the invoices + //page to force you to pay your bills first. + $isTrial = (Application_Model_Preference::GetPlanLevel() == 'trial'); + if (!$isTrial && (Application_Model_Preference::getProvisioningStatus() == PROVISIONING_STATUS_SUSPENDED)) { + $this->_redirect('billing/invoices'); + } Zend_Layout::getMvcInstance()->assign('parent_page', 'Billing'); diff --git a/airtime_mvc/application/layouts/scripts/layout.phtml b/airtime_mvc/application/layouts/scripts/layout.phtml index ec2c64088..f0916e19a 100644 --- a/airtime_mvc/application/layouts/scripts/layout.phtml +++ b/airtime_mvc/application/layouts/scripts/layout.phtml @@ -22,8 +22,10 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= partial('partialviews/trialBox.phtml', array("is_trial"=>$this->isTrial(), "trial_remain"=> $this->trialRemaining())) ?>
- suspended) : ?> - partial('partialviews/suspended.phtml'); ?> + suspended && $this->isTrial()) : ?> + partial('partialviews/suspendedtrial.phtml'); ?> + suspended && !$this->isTrial()) : ?> + partial('partialviews/trial.phtml'); ?> versionNotify(); diff --git a/airtime_mvc/application/views/scripts/partialviews/suspendedtrial.phtml b/airtime_mvc/application/views/scripts/partialviews/suspendedtrial.phtml new file mode 100644 index 000000000..bafce3743 --- /dev/null +++ b/airtime_mvc/application/views/scripts/partialviews/suspendedtrial.phtml @@ -0,0 +1,9 @@ +
+

Station Suspended

+

+ please upgrade your plan now.', '/billing/upgrade'))); ?> +

+

+ removed within 7 days if you do not upgrade. If you believe this suspension was in error, please contact support.', 'https://sourcefabricberlin.zendesk.com/anonymous_requests/new'))); ?> +

+
\ No newline at end of file From 1efd0b815b1ca6f6c7ac3ffb423349e73d66e4e3 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Thu, 5 Nov 2015 16:47:58 -0500 Subject: [PATCH 07/15] Removed October educational discount banner from billing page --- airtime_mvc/application/views/scripts/billing/upgrade.phtml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airtime_mvc/application/views/scripts/billing/upgrade.phtml b/airtime_mvc/application/views/scripts/billing/upgrade.phtml index fc1799140..83077cb9e 100644 --- a/airtime_mvc/application/views/scripts/billing/upgrade.phtml +++ b/airtime_mvc/application/views/scripts/billing/upgrade.phtml @@ -265,10 +265,12 @@ echo($currentProduct["name"]); //echo Application_Model_Preference::GetPlanLevel(); ?>

+

filterByDbStarts($now, Criteria::GREATER_THAN) + //->filterByDbModifiedInstance(false) + ->orderByDbStarts() + ->find(); + //->find($this->con); + $total = $showInstances->count(); + $progress = 0; + foreach ($showInstances as $instance) { + echo(round(floatval($progress / $total)*100) . "% - " . $instance->getDbId() . "\n
"); + flush(); + ob_flush(); + //while(@ob_end_clean()); + $scheduler->removeGaps2($instance->getDbId()); + $progress += 1; + } + echo("Recalculated $total shows."); } } diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index e5ecd707c..23088c698 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -384,6 +384,24 @@ class Application_Model_Scheduler return $dt; } + private function findTimeDifference2($p_startDT, $p_endDT) { + $startEpoch = $p_startDT->format("U.u"); + $endEpoch = $p_endDT->format("U.u"); + + //add two float numbers to 6 subsecond precision + //DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number. + $newEpoch = bcsub($endEpoch, (string)$startEpoch, 6); + + $dt = DateTime::createFromFormat("U.u", $newEpoch, new DateTimeZone("UTC")); + + if ($dt === false) { + //PHP 5.3.2 problem + $dt = DateTime::createFromFormat("U", intval($newEpoch), new DateTimeZone("UTC")); + } + + return $dt; + } + /* * @param DateTime startDT in UTC * @param string duration @@ -498,12 +516,68 @@ class Application_Model_Scheduler $itemStartDT = $instance->getDbStarts(null); foreach ($schedule as $item) { + + $itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength()); + + $item->setDbStarts($itemStartDT) + ->setDbEnds($itemEndDT); + + $itemStartDT = $itemEndDT; + } + + $schedule->save($this->con); + } + + /** Temporary hack to copy the track cue in, out, and length from the cc_files table to fix + * incorrect track lengths (RKTN-260) + */ + public function removeGaps2($showInstance, $exclude = null) { + Logging::info("removing gaps from show instance #" . $showInstance); + + $instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con); + if (is_null($instance)) { + throw new OutDatedScheduleException(_("The schedule you're viewing is out of date!")); + } + + $itemStartDT = $instance->getDbStarts(null); + + $schedule = CcScheduleQuery::create() + ->filterByDbInstanceId($showInstance) + ->filterByDbId($exclude, Criteria::NOT_IN) + ->orderByDbStarts() + ->find($this->con); + + foreach ($schedule as $item) { + + //START OF TIME RECALC HACK + + //TODO: Copy the cue in, cue out, and track length from the cc_files table + $file = $item->getCcFiles($this->con); + $item->setDbCueIn($file->getDbCueIn()); + $item->setDbCueOut($file->getDbCueOut()); + + $cueOut = new DateTime($file->getDbCueOut()); + $cueIn = new DateTime($file->getDbCueIn()); + $clipLength = $this->findTimeDifference2($cueIn, $cueOut); + + //The clip length is supposed to be cue out - cue in: + //FIXME: How do we correctly do time arithmetic in PHP without losing the millseconds? + $item->setDbClipLength($clipLength->format(DEFAULT_INTERVAL_FORMAT)); + $item->save($this->con); + //Ensure we don't get cached results + CcSchedulePeer::clearInstancePool(); + //END OF TIME RECALC HACK + $itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength()); $item->setDbStarts($itemStartDT) ->setDbEnds($itemEndDT) ->save($this->con); $itemStartDT = $this->findTimeDifference($itemEndDT, $this->crossfadeDuration); } + + $instance->updateDbTimeFilled($this->con); //FIXME: TIME RECALC HACK (Albert) + + $schedule->save($this->con); } /** From 4a86544738241a907c1a8acc1cad0ec54df596a5 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Tue, 3 Nov 2015 14:12:27 -0500 Subject: [PATCH 09/15] Skip non-files for XXXX-260 --- airtime_mvc/application/models/Scheduler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 23088c698..54b492420 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -553,6 +553,9 @@ class Application_Model_Scheduler //TODO: Copy the cue in, cue out, and track length from the cc_files table $file = $item->getCcFiles($this->con); + if (!$file) { + continue; + } $item->setDbCueIn($file->getDbCueIn()); $item->setDbCueOut($file->getDbCueOut()); From 713a158bb36401bafa2db246b7d0fd7d51c48fa0 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Tue, 3 Nov 2015 14:44:31 -0500 Subject: [PATCH 10/15] Disable layout in recalculate-schedule API - XXXX-260 --- airtime_mvc/application/controllers/ApiController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 524365f91..684ccc3c2 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -1523,6 +1523,9 @@ class ApiController extends Zend_Controller_Action echo $m3uFile; public function recalculateScheduleAction() { + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + $scheduler = new Application_Model_Scheduler(); $now = new DateTime("now", new DateTimeZone("UTC")); From e8a0ace0187b02ac0f3198d6f267caa6f97a802f Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 6 Nov 2015 12:57:35 -0500 Subject: [PATCH 11/15] Fixed up syntax error introduced by last commit --- airtime_mvc/application/controllers/ApiController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 684ccc3c2..c702cf7ab 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -1517,10 +1517,12 @@ class ApiController extends Zend_Controller_Action $streamData = Application_Model_StreamSetting::getEnabledStreamData(); foreach ($streamData as $stream) { - $m3uFile .= "#EXTINF,".$stationName." - " . strtoupper($stream['codec']) . "\r\n"; + $m3uFile .= "#EXTINF," . $stationName . " - " . strtoupper($stream['codec']) . "\r\n"; $m3uFile .= $stream['url'] . "\r\n\r\n"; } echo $m3uFile; + } + public function recalculateScheduleAction() { $this->view->layout()->disableLayout(); From 0e6e82a0c62c9ab10b49267715a779ea7b814631 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 6 Nov 2015 13:04:33 -0500 Subject: [PATCH 12/15] Fixed session start issue with new API --- airtime_mvc/application/controllers/ApiController.php | 4 ++++ airtime_mvc/application/models/Scheduler.php | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index c702cf7ab..bb4c9e3f9 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -1528,7 +1528,11 @@ class ApiController extends Zend_Controller_Action $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); + Zend_Session::start(); + $scheduler = new Application_Model_Scheduler(); + session_write_close(); + $now = new DateTime("now", new DateTimeZone("UTC")); $showInstances = CcShowInstancesQuery::create() diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index 54b492420..35d42c0b9 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -532,7 +532,6 @@ class Application_Model_Scheduler * incorrect track lengths (RKTN-260) */ public function removeGaps2($showInstance, $exclude = null) { - Logging::info("removing gaps from show instance #" . $showInstance); $instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con); if (is_null($instance)) { From bb05fa996accd63bb0c4f529f027d514d5e05131 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 9 Nov 2015 19:32:56 -0500 Subject: [PATCH 13/15] SAAS-1132: Improve safety of XML parsing for listener stats --- python_apps/pypo/pypo/listenerstat.py | 6 +++--- python_apps/pypo/setup.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/python_apps/pypo/pypo/listenerstat.py b/python_apps/pypo/pypo/listenerstat.py index fc7adc74a..cd044eac3 100644 --- a/python_apps/pypo/pypo/listenerstat.py +++ b/python_apps/pypo/pypo/listenerstat.py @@ -1,6 +1,6 @@ from threading import Thread import urllib2 -import xml.dom.minidom +import defusedxml.minidom import base64 from datetime import datetime import traceback @@ -64,7 +64,7 @@ class ListenerStat(Thread): else: url = 'http://%(host)s:%(port)s/admin/stats.xml' % ip document = self.get_stream_server_xml(ip, url) - dom = xml.dom.minidom.parseString(document) + dom = defusedxml.minidom.parseString(document) sources = dom.getElementsByTagName("source") mount_stats = None @@ -87,7 +87,7 @@ class ListenerStat(Thread): def get_shoutcast_stats(self, ip): url = 'http://%(host)s:%(port)s/admin.cgi?sid=1&mode=viewxml' % ip document = self.get_stream_server_xml(ip, url, is_shoutcast=True) - dom = xml.dom.minidom.parseString(document) + dom = defusedxml.parseString(document) current_listeners = dom.getElementsByTagName("CURRENTLISTENERS") timestamp = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") diff --git a/python_apps/pypo/setup.py b/python_apps/pypo/setup.py index a5b33b74d..06a25117c 100644 --- a/python_apps/pypo/setup.py +++ b/python_apps/pypo/setup.py @@ -58,7 +58,8 @@ setup(name='airtime-playout', 'pyinotify', 'pytz', 'requests', - 'wsgiref' + 'wsgiref', + 'defusedxml' ], zip_safe=False, data_files=data_files) From 591f7d59f0b0ac390b906a105008beb651764586 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Fri, 13 Nov 2015 10:53:47 -0500 Subject: [PATCH 14/15] Slightly better error handling for uploads --- airtime_mvc/application/models/RabbitMq.php | 2 +- .../modules/rest/controllers/MediaController.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/RabbitMq.php b/airtime_mvc/application/models/RabbitMq.php index 87a89336d..9b399457a 100644 --- a/airtime_mvc/application/models/RabbitMq.php +++ b/airtime_mvc/application/models/RabbitMq.php @@ -141,7 +141,7 @@ class Application_Model_RabbitMq $channel->exchange_declare($exchange, $exchangeType, false, true, $autoDeleteExchange); $msg = new AMQPMessage($jsonData, array('content_type' => 'text/plain')); - + $channel->basic_publish($msg, $exchange); $channel->close(); $conn->close(); diff --git a/airtime_mvc/application/modules/rest/controllers/MediaController.php b/airtime_mvc/application/modules/rest/controllers/MediaController.php index b43bac3c0..8360bfa77 100644 --- a/airtime_mvc/application/modules/rest/controllers/MediaController.php +++ b/airtime_mvc/application/modules/rest/controllers/MediaController.php @@ -122,9 +122,8 @@ class Rest_MediaController extends Zend_Rest_Controller ->appendBody("ERROR: Disk Quota reached."); } catch (Exception $e) { - $this->unknownErrorResponse(); - Logging::error($e->getMessage()); - throw $e; + $this->serviceUnavailableResponse(); + Logging::error($e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -209,5 +208,12 @@ class Rest_MediaController extends Zend_Rest_Controller $resp->setHttpResponseCode(400); $resp->appendBody("An unknown error occurred."); } + + private function serviceUnavailableResponse() + { + $resp = $this->getResponse(); + $resp->setHttpResponseCode(400); + $resp->appendBody("An error occurred while processing your upload. Please try again in a few minutes."); + } } From 1a349c4ea130f2df0b9de877c42e2fd6d4964fdf Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 16 Nov 2015 17:07:38 -0500 Subject: [PATCH 15/15] Fixed non-trial suspension screen --- airtime_mvc/application/layouts/scripts/layout.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/layouts/scripts/layout.phtml b/airtime_mvc/application/layouts/scripts/layout.phtml index f0916e19a..4bcd15b26 100644 --- a/airtime_mvc/application/layouts/scripts/layout.phtml +++ b/airtime_mvc/application/layouts/scripts/layout.phtml @@ -25,7 +25,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= suspended && $this->isTrial()) : ?> partial('partialviews/suspendedtrial.phtml'); ?> suspended && !$this->isTrial()) : ?> - partial('partialviews/trial.phtml'); ?> + partial('partialviews/suspended.phtml'); ?> versionNotify();