Skip to content

Commit

Permalink
Implement Edl reader
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed Jun 2, 2024
1 parent 521c7d5 commit af3819a
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Front/Library/Utility/Arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,60 @@ export default class Arrays {
/**
* Array Filter
*
* @param array
* @param key
* @param keyValue
* @return any
*/
public static filterByKey = (array:Array<any> = [], key:string, keyValue:string|Array<any>|null|Object) => array.filter(
(aEl) => aEl[key] == keyValue
);

/**
* Array Filter Multi Dimensional
*
* @param array
* @param key
* @param keyValue
* @return any
*/
public static filterByKeyMD = (
array: Array<any> = [],
key: string,
keyValue: string | Array<any> | null | Object
) => array.filter(
(aEl) => this.getNestedValue(aEl, key.split('.')) == keyValue
);

/**
* Remove Objects By Key Value
*
* Removes all objects from the array where the specified parameter is equal to the given value.
*
* @param array The array of objects.
* @param key The key to check in each object, supports nested keys with "." separator.
* @param value The value to match for removal.
* @return A new array with the objects removed.
*/
public static removeObjectsByKeyValue = (array: Array<any>, key: string, value: string):Array<any> => {
return array.filter(obj => this.getNestedValue(obj, key.split('.')) !== value);
}

/** Private static methods
******************************************************
*/

/**
* Get Nested Values
*
* Helper function to get nested value from an object
*
* @param obj The object to traverse
* @param keys Array of keys representing the path to the nested value
* @return The nested value or undefined if any key is not found
*/
private static getNestedValue = (obj: any, keys: string[]): any => {
return keys.reduce((acc, key) => acc && acc[key], obj);
};

}
153 changes: 153 additions & 0 deletions src/Library/File/Edl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php declare(strict_types=1);
/**
* File
*
* Classe for manipulate specific files
*
* PHP version 8.1.2
*
* @package kzarshenas/crazyphp
* @author kekefreedog <[email protected]>
* @copyright 2022-2022 Kévin Zarshenas
*/
namespace CrazyPHP\Library\File;

/**
* Dependances
*/
use CrazyPHP\Library\File\File;

/**
* Edl
*
* Methods for interacting with EDL file
*
* @package kzarshenas/crazyphp
* @author kekefreedog <[email protected]>
* @copyright 2022-2022 Kévin Zarshenas
*/
class Edl {

/** Public static method
******************************************************
*/

/**
* Open
*
* Open EDL file content
*
* @param string $input Parameter to read
* @return mixed
*/
public static function open(string $path = ""):mixed {

# Set result
$result = null;

# Check if file exists
if(!$path || !File::exists($path))

# Return result
return $result;

# Set path
$path = File::path($path);

# Set EDL content
$edl = [];

# Set current envent
$currentEvent = null;

# Open file
$file = fopen($path, 'r');

# Iteration lines of file
while (($line = fgets($file)) !== false) {

# Remove any extra whitespace
$line = trim($line);

# Skip empty lines
if(empty($line))

# Continue
continue;

# Parse title and frame count mode
if(preg_match('/^TITLE:\s*(.*)$/', $line, $matches)){

# File title
$edl['title'] = $matches[1];

}else
# Frame settings
if(preg_match('/^FCM:\s*(.*)$/', $line, $matches)){

# Set fcm
$edl['fcm'] = $matches[1];

}else
# Cut content
if(preg_match('/^(\d+)\s+(\w+)\s+(\w+)\s+(\w)\s+(\d{2}:\d{2}:\d{2}:\d{2})\s+(\d{2}:\d{2}:\d{2}:\d{2})\s+(\d{2}:\d{2}:\d{2}:\d{2})\s+(\d{2}:\d{2}:\d{2}:\d{2})$/', $line, $matches)){

# Parse edit decision
$currentEvent = [
'eventNumber' => (int)$matches[1],
'reel' => $matches[2],
'track' => $matches[3],
'editType' => $matches[4],
'sourceIn' => $matches[5],
'sourceOut' => $matches[6],
'recordIn' => $matches[7],
'recordOut' => $matches[8],
'comments' => [],
'details' => []
];

# Push in events
$edl['events'][] = $currentEvent;

}else
# Set details
if(preg_match('/^DLEDL:\s*(.*)$/', $line, $matches) && $currentEvent !== null){

# Parse DLEDL lines
$currentEvent['details'][] = $matches[1];

# Push in events
$edl['events'][count($edl['events']) - 1] = $currentEvent;

}else
# From Clip Name
if(preg_match('/^FROM CLIP NAME:\s*(.*)$/', $line, $matches) && $currentEvent !== null){

# Parse FROM CLIP NAME lines
$currentEvent['fromClipName'] = $matches[1];

# Push in events
$edl['events'][count($edl['events']) - 1] = $currentEvent;

}else
# Set misc data
if(preg_match('/^\*\s*(.*)$/', $line, $matches) && $currentEvent !== null){

# Parse comment lines
$currentEvent['comments'][] = $matches[1];

# Push in events
$edl['events'][count($edl['events']) - 1] = $currentEvent;

}
}

# Close file
fclose($file);

# Return edl
return $edl;

}

}
2 changes: 2 additions & 0 deletions src/Library/File/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public static function open(string $filename = "", bool $arrayFormat = true):arr

# Check filename
if(!$filename)

# Return result
return $result;

# Check tokken in filename
Expand Down
Binary file added tests/Library/File/EdlTest.php
Binary file not shown.

0 comments on commit af3819a

Please sign in to comment.