We use cookies (just for analytics) on this website. If you continue we will assume you are happy with it. ok

BeBanjo

Back to index

Segment

The segment resource represents a portion of an asset.

In Movida land, a segment looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<segment>
  <id type="integer">245</id>
  <external-id>AB123</external-id>
  <type>Segment type</type>
  <position>2</position>
  <start>00:00:10.234</start>
  <end>00:01:20.333</end>
  <link rel="self" href="https://movida.bebanjo.net/api/segments/245"/>
  <link rel="asset" href="https://movida.bebanjo.net/api/assets/123"/>
</segment>

Segment attributes

  • id (required): Movida internal identifier of the segment.

  • external-id (optional): Identifier of the segment in a external system.

  • type (optional): the type of the segment. There is a closed list of values.

  • position (optional): Position of the segment within the asset. If none is given, the last position will be assigned.

  • start (optional): Timecode representing the beginning of the segment. Required only if end is present and it should be less than the end.

  • end (optional): timecode representing the end of the segment. Mandatory only if start is present and it should be greater than the start.

Get a list of all segments of an asset

Segments are accessed via an asset. Inside an asset, one of the related link nodes is the segments node, identified by the rel attribute. Like here:

<asset>
  <!-- ... -->
  <link rel="segments" href="https://movida.bebanjo.net/api/assets/123/segments"/>
</asset>

If we follow that link, we can fetch the list of all segments for that asset.

$ curl --digest -u robot_user:password https://movida.bebanjo.net/api/assets/123/segments
<?xml version="1.0" encoding="utf-8" ?>
<segments type="array">
  <total-entries>2</total-entries>
  <segment>
    <id type="integer">245</id>
    <external-id>AB123</external-id>
    <type>Segment type</type>
    <position>1</position>
    <start>00:00:10.100</start>
    <end>00:01:20.355</end>
    <link rel="self" href="https://movida.bebanjo.net/api/segments/245"/>
    <link rel="asset" href="https://movida.bebanjo.net/api/assets/123"/>
  </segment>
  <segment>
    <id type="integer">246</id>
    <external-id>AB124</external-id>
    <type>Segment type</type>
    <position>2</position>
    <start>00:01:20.211</start>
    <end>00:03:23.333</end>
    <link rel="self" href="https://movida.bebanjo.net/api/segments/246"/>
    <link rel="asset" href="https://movida.bebanjo.net/api/assets/123"/>
  </segment>
</segments>

This is a paginated resource.

Creating segments for an asset

To create segments, you just need to POST proper XML segment representation (similar to the ones you get when fetching a segment) to the segments URL of an asset. That URL can be found in a link which rel attribute equals to segments.

For example, this POST would create an segment (we’ll use curl’s @ option, which reads data to be posted from a file):

$ cat segment.xml
<segment>
  <external-id>AB123</external-id>
  <position>3</position>
  <start>00:02:10</start>
  <end>00:03:20</end>
</segment>
$ curl -u robot_user:password --digest -H "Content-Type: application/xml" -X POST -d @segment.xml
"https://movida.bebanjo.net/api/assets/123/segments"

Movida will return the full XML of the segment just created:

<?xml version="1.0" encoding="UTF-8"?>
<segment>
  <id type="integer">246</id>
  <external-id>AB123</external-id>
  <type nil="true"></type>
  <position>3</position>
  <start>00:02:10.000</start>
  <end>00:03:20.000</end>
  <link rel="self" href="https://movida.bebanjo.net/api/segments/246"/>
  <link rel="asset" href="https://movida.bebanjo.net/api/assets/123"/>
</segment>

Creating segments for an asset providing a type

If the Segment Types enumeration exists, you can add types to your segments, eg: this enumeration has the following values: Type 1, Type2 and Type 3. If the enumeration has these values: Type 1, Type 2 and Type 3. If you try to create a segment with an invalid type, e.g. Type 4, then you will receive an message error.

$ cat segment.xml
<segment>
  <external-id>AB123</external-id>
  <type>Type 1</type>
  <position>3</position>
  <start>00:02:10</start>
  <end>00:03:20</end>
</segment>
$ curl -u robot_user:password --digest -H "Content-Type: application/xml" -X POST -d @segment.xml
"https://movida.bebanjo.net/api/assets/123/segments"

Movida will return the full XML of the segment just created with the type included:

<?xml version="1.0" encoding="UTF-8"?>
<segment>
  <id type="integer">246</id>
  <external-id>AB123</external-id>
  <type>Type 1</type>
  <position>3</position>
  <start>00:02:10.000</start>
  <end>00:03:20.000</end>
  <link rel="self" href="https://movida.bebanjo.net/api/segments/246"/>
  <link rel="asset" href="https://movida.bebanjo.net/api/assets/123"/>
</segment>

Updating a segment

You can update segments issuing a PUT request to the URL of a given segment, as the following example illustrates. This example only updates the segments’s start timecode.

$ cat segment.xml
<segment>
  <type>Type 2</type>
  <start>00:02:20.123</start>
</segment>

Now we send the XML as the body of a PUT request to the segments’s URL:

$ curl -u robot_user:password --digest -H "Content-Type: application/xml" -X PUT -d @segments.xml
"https://movida.bebanjo.net/api/segments/246"

The PUT request would return the updated XML of the segment:

<segment>
  <id type="integer">246</id>
  <external-id>AB123</external-id>
  <type>Type 2</type>
  <start>00:02:20.123</start>
  <end>00:03:20.345</end>
  <link rel="self" href="https://movida.bebanjo.net/api/segments/246"/>
  <link rel="asset" href="https://movida.bebanjo.net/api/assets/123"/>
</segment>

Delete a segment of an asset

The following example shows how to destroy a particular segment. Only a DELETE HTTP request to its URL is required:

$ curl -u robot_user:password --digest -H "Content-Type: application/xml" -X DELETE
"https://movida.bebanjo.net/api/segments/246"

The DELETE request doesn’t return anything, as that segment is now gone.

Deleting an segment won’t have any side-effect on linked resources such as the parent asset.

Last updated March 31st, 2017.