]> git.localhorst.tv Git - alttp.git/commitdiff
fix zsr sync
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 May 2024 09:18:38 +0000 (11:18 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 May 2024 09:18:38 +0000 (11:18 +0200)
app/Console/Commands/SyncZSR.php

index 1d9211025020e204b7f5dd5a725c800d1f0e578b..65b21c187dbfaa4982bcce5105dec419939fb761 100644 (file)
@@ -88,17 +88,6 @@ class SyncZSR extends Command {
                } else {
                        $episode->title = $entry['summary'];
                }
-               if (preg_match('/Restream: https?:\/\/(www\.)?twitch\.tv\/(\w+)/u', $entry['description'], $matches)) {
-                       $channel = $this->syncChannel($episode, $matches[2]);
-                       if ($channel) {
-                               $episode->channels()->syncWithoutDetaching([$channel->id]);
-                       }
-               }
-               if (preg_match('/^(.*) - (.*?) vs (.*?)$/u', $episode->title, $matches)) {
-                       $episode->title = $matches[1];
-                       $this->syncPlayer($episode, $matches[2]);
-                       $this->syncPlayer($episode, $matches[3]);
-               }
                $start = Carbon::parse($entry['start']['dateTime'])->setTimezone('UTC');
                if (!$episode->start || $start->ne($episode->start)) {
                        $episode->start = $start;
@@ -106,7 +95,20 @@ class SyncZSR extends Command {
                $end = Carbon::parse($entry['end']['dateTime'])->setTimezone('UTC');
                $episode->estimate = $start->diffInSeconds($end);
                $episode->confirmed = true;
-               $episode->save();
+               if (preg_match('/^(.*) - (.*?) vs\.? (.*?)$/u', $episode->title, $matches)) {
+                       $episode->title = $matches[1];
+                       $episode->save();
+                       $this->syncPlayer($episode, $matches[2]);
+                       $this->syncPlayer($episode, $matches[3]);
+               } else {
+                       $episode->save();
+               }
+               if (preg_match('/Restream: https?:\/\/(www\.)?twitch\.tv\/(\w+)/u', $entry['description'], $matches)) {
+                       $channel = $this->syncChannel($episode, $matches[2]);
+                       if ($channel) {
+                               $episode->channels()->syncWithoutDetaching([$channel->id]);
+                       }
+               }
        }
 
        private function syncChannel(Episode $episode, $zsrChannel) {