-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see #1: add support for Face Detection
- Loading branch information
Showing
5 changed files
with
164 additions
and
85 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/includes/class-helixware-mico-face-detection-service.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/** | ||
* Manage Face Detection fragments. | ||
* @since 1.2.1 | ||
*/ | ||
class HelixWare_Mico_Face_Detection_Service extends HelixWare_Mico_Fragment_Service { | ||
|
||
const FRAGMENTS = 'faceFragments'; | ||
|
||
/** | ||
* Create an instance of the MICO Fragment service. | ||
* | ||
* @since 1.2.1 | ||
* | ||
* @param \HelixWare_HAL_Client $hal_client A HAL client. | ||
* @param string $server_url The server URL. | ||
* @param \HelixWare_Asset_Service $asset_service The Asset service. | ||
*/ | ||
public function __construct( $hal_client, $server_url, $asset_service ) { | ||
|
||
parent::__construct( self::FRAGMENTS, $hal_client, $server_url, $asset_service ); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/** | ||
* This class manages Fragments for assets. | ||
* | ||
* @since 1.0.0 | ||
* @package Helixware_Mico | ||
* @subpackage Helixware_Mico/includes | ||
* @author David Riccitelli <[email protected]> | ||
*/ | ||
class Helixware_Mico_Sequence_Service extends Helixware_Mico_Fragment_Service { | ||
|
||
const FRAGMENTS = "sequenceFragments"; | ||
|
||
/** | ||
* Create an instance of the MICO Fragment service. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param \HelixWare_HAL_Client $hal_client A HAL client. | ||
* @param string $server_url The server URL. | ||
* @param \HelixWare_Asset_Service $asset_service The Asset service. | ||
*/ | ||
public function __construct( $hal_client, $server_url, $asset_service ) { | ||
|
||
parent::__construct( self::FRAGMENTS, $hal_client, $server_url, $asset_service ); | ||
|
||
} | ||
|
||
/** | ||
* Get the VTT chapters URL. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @param int $id The post ID. | ||
* | ||
* @return string The local URL to the VTT chapters URL. | ||
*/ | ||
public function get_vtt_chapters_url( $id ) { | ||
|
||
return admin_url( "admin-ajax.php?action=hw_vtt_chapters&id=$id" ); | ||
} | ||
|
||
/** | ||
* Echo a jwplayer:track line linking to the chapters file. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @param WP_Post $post A post instance. | ||
*/ | ||
public function playlist_rss_jwplayer_header( $post ) { | ||
|
||
echo( '<jwplayer:track file="' . htmlentities( $this->get_vtt_chapters_url( $post->ID ) ) . '" kind="chapters" />' . "\n" ); | ||
|
||
} | ||
|
||
/** | ||
* Outputs a VTT file defining the chapters for the attachment with the provided id. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
public function ajax_vtt_chapters() { | ||
|
||
// Check that a post ID has been provided. | ||
if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { | ||
wp_die( 'A numeric id is required.' ); | ||
} | ||
|
||
echo( "WEBVTT\n\n" ); | ||
|
||
$chapter_no = 0; | ||
$fragments = $this->get_fragments_by_id( $_GET['id'] ); | ||
array_walk( $fragments, function ( $fragment ) use ( &$chapter_no ) { | ||
|
||
echo( 'chapter_' . ( ++ $chapter_no ) . "\n" ); | ||
echo( HelixWare_Helper::milliseconds_to_timecode( $fragment->start ) . " --> " . HelixWare_Helper::milliseconds_to_timecode( $fragment->end ) . "\n" ); | ||
echo( 'Chapter ' . $chapter_no . "\n" ); | ||
echo( "\n" ); | ||
|
||
} ); | ||
|
||
wp_die(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,18 @@ | |
* @subpackage HelixWare/includes | ||
* @author David Riccitelli <[email protected]> | ||
*/ | ||
class HelixWare_Mico_Fragments_Shortcode { | ||
class HelixWare_Mico_Face_Detection_Shortcode { | ||
|
||
const HANDLE_NAME = 'hw_fragments'; | ||
const HANDLE_NAME = 'hw_face_detection'; | ||
|
||
/** | ||
* The Fragments service. | ||
* The MICO Face Detection service. | ||
* | ||
* @since 1.2.0 | ||
* @since 1.2.1 | ||
* @access private | ||
* @var \Helixware_Mico_Fragment_Service $fragments_service The Fragments service. | ||
* @var \HelixWare_Mico_Face_Detection_Service $face_detection_service The MICO Face Detection service. | ||
*/ | ||
private $fragments_service; | ||
private $face_detection_service; | ||
|
||
/** | ||
* The Asset service. | ||
|
@@ -43,15 +43,15 @@ class HelixWare_Mico_Fragments_Shortcode { | |
* | ||
* @since 1.1.0 | ||
* | ||
* @param \Helixware_Mico_Fragment_Service $fragments_service The Fragments service. | ||
* @param \Helixware_Mico_Face_Detection_Service $face_detection_service The MICO Face Detection service. | ||
* @param \HelixWare_Asset_Service $asset_service The Asset service. | ||
* @param \HelixWare_Asset_Image_Service $asset_image_service The Asset Image service. | ||
*/ | ||
public function __construct( $fragments_service, $asset_service, $asset_image_service ) { | ||
public function __construct( $face_detection_service, $asset_service, $asset_image_service ) { | ||
|
||
$this->fragments_service = $fragments_service; | ||
$this->asset_service = $asset_service; | ||
$this->asset_image_service = $asset_image_service; | ||
$this->face_detection_service = $face_detection_service; | ||
$this->asset_service = $asset_service; | ||
$this->asset_image_service = $asset_image_service; | ||
|
||
// Register itself as handler for the hw_fragments shortcode. | ||
add_shortcode( self::HANDLE_NAME, array( $this, 'render' ) ); | ||
|
@@ -78,8 +78,8 @@ public function render( $atts ) { | |
$id = $atts['id']; | ||
|
||
$html = "<ul>"; | ||
foreach ( $this->fragments_service->get_fragments_by_id( $id ) as $fragment ) { | ||
$html .= '<li style="float:left;"><img width="200" src="' . $this->asset_image_service->get_local_image_url_by_id( $id, $fragment->start / 1000 ) . '" />' . $fragment->start . '</li>'; | ||
foreach ( $this->face_detection_service->get_fragments_by_id( $id ) as $fragment ) { | ||
$html .= '<li style="float:left;"><img width="200" src="' . $this->asset_image_service->get_local_image_url_by_id( $id, $fragment->start / 1000, $fragment->x, $fragment->y, $fragment->width, $fragment->height ) . '" />' . $fragment->start . "($fragment->x, $fragment->y, $fragment->width, $fragment->height)" . '</li>'; | ||
} | ||
$html .= "</ul>"; | ||
|
||
|