diff --git a/bin/save_metadata.php b/bin/save_metadata.php index 1be9195..514cc37 100644 --- a/bin/save_metadata.php +++ b/bin/save_metadata.php @@ -35,6 +35,55 @@ */ $metadata = json_decode(file_get_contents($video_dir . 'metadata.json')); +/* + * Identify the committee ID for this video. + */ +if ($metadata->type == 'committee') +{ + + /* + * First, get a list of all committees' names and IDs. + */ + $sql = 'SELECT id, name + FROM committees + WHERE parent_id IS NULL + AND chamber = "' . $metadata->chamber . '"'; + $result = mysql_query($sql); + if (mysql_num_rows($result) > 0) + { + + $committees = array(); + while ($committee = mysql_fetch_array($result)) + { + $committees[] = $committee; + } + + $shortest = -1; + foreach ($committees as $id => $name) + { + + $distance = levenshtein($metadata->committee, $name); + if ($distance === 0) + { + $closest = $id; + $shortest = 0; + break; + } + + elseif ($distance <= $shortest || $shortest < 0) + { + $closest = $id; + $shortest = $distance; + } + + } + + $metadata->committee_id = $closest; + + } + +} + /* * Instantiate the video class */ @@ -71,6 +120,10 @@ $file['type'] = 'video'; $file['title'] = ucfirst($file['chamber']) . ' Video'; $file['capture_directory'] = '/video/' . $metadata->chamber . '/floor/' . $metadata->date .'/'; +if (!empty($metadata->committee_id)) +{ + $file['committee_id'] = $metadata->committee_id; +} /* * Store this record in the database.