diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 9b7c39f..158e90e 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -21,6 +21,7 @@ class Note // Maybe these doesn't make sense to keep but leaving it here just in // case for handiness' sake private array $fields = []; + private ?array $mediaInfo = null; private array $cardIds; const HIGHLIGHT_PATTERN = '/]*)>(.*?)<\/span>/i'; @@ -55,8 +56,16 @@ class Note 'cards' => $note->cardIds, ] = $noteInfo; + // the fields array key value comes with an order fields that is + // already maintained by PHP since arrays are ordered dictionaries. + // So we can safely just drop it. + // + // REVIEW: Having said that, maybe ordering the array before throwing + // the order would be advisable. $note->fields = array_map(fn($x) => $x['value'], $noteInfo['fields']); + $note->mediaInfo = $note->parseMediaInfo($note->fields['Notes']); + // Set VocabKanji field //$vocabKanji = explode('|', $note->fields['VocabKanji']); $note->terms = self::parseVocabDef($note->fields['VocabDef']); @@ -136,6 +145,49 @@ class Note return $terms; } + public function parseMediaInfo(string $notes): ?array + { + $matches = null; + + // Parse the notes fields. It can be in the form of + // series-name_S01 EP07 (11h22m33s44ms) + // or + // movie-name EP (11h22m33s44ms) + if (1 !== preg_match( + '/(?[a-z\-_]+)(_S)?(?\d*) EP(?\d*) \((?