From 2b8e265ce0e41e57eb79e965d2b3db0ab0812dbb Mon Sep 17 00:00:00 2001 From: DariusIII Date: Mon, 21 Aug 2017 10:06:41 +0200 Subject: [PATCH] Add VideoData model and use it ib ReleaseExtra class --- Changelog | 1 + app/Models/VideoData.php | 50 ++++++++++++++++++++++++++++++++++++++++ nntmux/ReleaseExtra.php | 39 ++++++++++++++++++++----------- 3 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 app/Models/VideoData.php diff --git a/Changelog b/Changelog index 062466cd8..4f098be0f 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-08-20 DariusIII + * Chg: Add VideoData model and use it ib ReleaseExtra class * Chg: Add primaryKey property to ReleaseExtraFull model * Chg: Add ReleaseExtraFull model and use it in ReleaseExtra class 2017-08-19 DariusIII diff --git a/app/Models/VideoData.php b/app/Models/VideoData.php new file mode 100644 index 000000000..79bb12294 --- /dev/null +++ b/app/Models/VideoData.php @@ -0,0 +1,50 @@ +pdo->queryOneRow(sprintf('SELECT * FROM video_data WHERE releases_id = %d', $id)); + return VideoData::query()->where('releases_id', $id)->first(); } /** * @param $id * - * @return array|bool + * @return \Illuminate\Database\Eloquent\Model|null|static */ public function getVideo($id) { - return $this->pdo->queryOneRow(sprintf('SELECT * from video_data WHERE releases_id = %d', $id)); + return VideoData::query()->where('releases_id', $id)->first(); } /** @@ -124,13 +125,13 @@ class ReleaseExtra /** * @param $id * - * @return bool|\PDOStatement + * @return mixed */ public function delete($id) { $this->pdo->queryExec(sprintf('DELETE FROM audio_data WHERE releases_id = %d', $id)); $this->pdo->queryExec(sprintf('DELETE FROM release_subtitles WHERE releases_id = %d', $id)); - return $this->pdo->queryExec(sprintf('DELETE FROM video_data WHERE releases_id = %d', $id)); + VideoData::query()->where('releases_id', $id)->delete(); } /** @@ -149,7 +150,7 @@ class ReleaseExtra if (isset($track['@attributes']) && isset($track['@attributes']['type'])) { - if ($track['@attributes']['type'] == 'General') { + if ($track['@attributes']['type'] === 'General') { if (isset($track['Format'])) { $containerformat = $track['Format']; } @@ -162,7 +163,7 @@ class ReleaseExtra $this->addUID($releaseID, $uniqueid); } } - } else if ($track['@attributes']['type'] == 'Video') { + } else if ($track['@attributes']['type'] === 'Video') { $videoduration = $videoformat = $videocodec = $videowidth = $videoheight = $videoaspect = $videoframerate = $videolibrary = ''; if (isset($track['Duration'])) { $videoduration = $track['Duration']; @@ -189,7 +190,7 @@ class ReleaseExtra $videolibrary = $track['Writing_library']; } $this->addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary); - } else if ($track['@attributes']['type'] == 'Audio') { + } else if ($track['@attributes']['type'] === 'Audio') { $audioID = 1; $audioformat = $audiomode = $audiobitratemode = $audiobitrate = $audiochannels = $audiosamplerate = $audiolibrary = $audiolanguage = $audiotitle = ''; if (isset($track['@attributes']['streamid'])) { @@ -251,14 +252,24 @@ class ReleaseExtra * @param $videoaspect * @param $videoframerate * @param $videolibrary - * - * @return bool|\PDOStatement */ public function addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary) { - $ckid = $this->pdo->queryOneRow(sprintf('SELECT releases_id FROM video_data WHERE releases_id = %s', $releaseID)); - if (!isset($ckid['releases_id'])) { - return $this->pdo->queryExec(sprintf('INSERT INTO video_data (releases_id, containerformat, overallbitrate, videoduration, videoformat, videocodec, videowidth, videoheight, videoaspect, videoframerate, videolibrary) VALUES (%d, %s, %s, %s, %s, %s, %d, %d, %s, %d, %s)', $releaseID, $this->pdo->escapeString($containerformat), $this->pdo->escapeString($overallbitrate), $this->pdo->escapeString($videoduration), $this->pdo->escapeString($videoformat), $this->pdo->escapeString($videocodec), $videowidth, $videoheight, $this->pdo->escapeString($videoaspect), $videoframerate, $this->pdo->escapeString(substr($videolibrary, 0, 50)))); + $ckid = VideoData::query()->where('releases_id', $releaseID)->value('releases_id'); + if (!isset($ckid)) { + VideoData::query()->insert(['releases_id' => $releaseID, + 'containerformat' => $containerformat, + 'overallbitrate' => $overallbitrate, + 'videoduration' => $videoduration, + 'videoformat' => $videoformat, + 'videocodec' => $videocodec, + 'videowidth' => $videowidth, + 'videoheight' => $videoheight, + 'videoaspect' => $videoaspect, + 'videoframerate' => $videoframerate, + 'videolibrary' => substr($videolibrary, 0, 50) + ] + ); } }