2021-06-27 11:19:26 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Core\EpisodeAction;
|
|
|
|
|
2021-08-23 00:45:38 +00:00
|
|
|
class EpisodeActionReader
|
|
|
|
{
|
2021-08-23 11:30:18 +00:00
|
|
|
|
2021-08-23 00:45:38 +00:00
|
|
|
const EPISODEACTION_IDENTIFIER = 'EpisodeAction{';
|
2021-08-23 11:30:18 +00:00
|
|
|
|
2021-08-22 23:11:16 +00:00
|
|
|
/**
|
2021-08-24 11:09:43 +00:00
|
|
|
* @param string $episodeActionsString
|
2021-08-23 11:30:18 +00:00
|
|
|
* @return EpisodeAction[]
|
2021-08-22 23:11:16 +00:00
|
|
|
*/
|
2021-08-23 00:45:38 +00:00
|
|
|
public function fromString(string $episodeActionsString): array
|
|
|
|
{
|
|
|
|
|
2021-08-22 23:11:16 +00:00
|
|
|
|
2021-08-23 00:45:38 +00:00
|
|
|
$patterns = [
|
|
|
|
'/EpisodeAction{(podcast=\')(?<podcast>.*?)(\', episode=\')(?<episode>.*?)(\', guid=\')(?<guid>.*?)(\', action=)(?<action>.*?)(, timestamp=)(?<timestamp>.*?)(, started=)(?<started>.*?)(, position=)(?<position>.*?)(, total=)(?<total>.*?)}]*/',
|
|
|
|
'/EpisodeAction{(podcast=\')(?<podcast>.*?)(\', episode=\')(?<episode>.*?)(\', action=)(?<action>.*?)(, timestamp=)(?<timestamp>.*?)(, started=)(?<started>.*?)(, position=)(?<position>.*?)(, total=)(?<total>.*?)}]*/',
|
|
|
|
];
|
2021-08-22 23:11:16 +00:00
|
|
|
|
2021-08-23 00:45:38 +00:00
|
|
|
$episodeActions = [];
|
|
|
|
|
|
|
|
$episodeActionStrings = explode(self::EPISODEACTION_IDENTIFIER, $episodeActionsString);
|
|
|
|
array_shift($episodeActionStrings);
|
|
|
|
|
|
|
|
foreach ($episodeActionStrings as $episodeActionString) {
|
|
|
|
foreach ($patterns as $pattern) {
|
|
|
|
preg_match(
|
|
|
|
$pattern,
|
|
|
|
self::EPISODEACTION_IDENTIFIER . $episodeActionString,
|
|
|
|
$matches
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($matches["action"] !== null) {
|
|
|
|
$episodeActions[] = new EpisodeAction(
|
|
|
|
$matches["podcast"],
|
|
|
|
$matches["episode"],
|
|
|
|
$matches["action"],
|
|
|
|
$matches["timestamp"],
|
|
|
|
(int)$matches["started"],
|
|
|
|
(int)$matches["position"],
|
|
|
|
(int)$matches["total"],
|
|
|
|
$matches["guid"] ?? null,
|
2021-10-05 18:45:06 +00:00
|
|
|
null,
|
2021-08-23 00:45:38 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-08-22 23:11:16 +00:00
|
|
|
return $episodeActions;
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
}
|