Skip to content

guozheng/jvast

Repository files navigation

jvast

A Java library for video ad processing, e.g. insert pixels, etc.

Workflow Status

Overview

This is a Java library that supports VAST video ad processing, currently supporting pixel insertion. We are using a purely string manipulation based on index to achieve a better performance than typical DOM or SAX approaches.

Usage

//get VAST ad, e.g. from an HTTP response, a file, etc.
String ad = ...;

//construct input data for ad processing, e.g. insert pixels and tracking events
Multimap<PixelElementType, String> pixelMap = ArrayListMultimap.create();
final String impressionPixel = "https://adclick.com/impression";
pixelMap.put(PixelElementType.Impression, impressionPixel);

Multimap<TrackingEventElementType, String> trackingEventMap = ArrayListMultimap.create();
final String startTrackingEvent = "https://adclick.com/start";
trackingEventMap.put(TrackingEventElementType.start, startTrackingEvent);

InputData inputData = InputData.builder()
    .pixelMap(pixelMap)
    .trackingEventMap(trackingEventMap)
    .build();

//process ad
videoAd = VideoAdProcessor.process(videoAd, inputData);

You can clone this repo and build the jar to use. Or you can use the library from Maven Central project: https://mvnrepository.com/artifact/io.github.guozheng/jvast

Build

./gradles fatJar

The jar file can be located in build/libs/jvast.jar.

Testing

The testing logic has two parts:

  1. the updated VAST XML contains the right updates, e.g. pixels are inserted
  2. the updated VAST XML is a valid XML against IAB XML schema, based on VAST version, etc.

We are using a VAST parser (in src/test/java/jvast/vastparser) to implement the tests. It supports XML validation against schema and getting XML elements like pixels and tracking events. You can find sample tests in VideoAdProcessorTest.java.

To run the tests:

./gradlew test

Publishing to Maven Central

./gradlew publishToSonatype closeSonatypeStagingRepository

For more information on how to publish to Maven Central, check out this Medium article.

Todo Tasks

  • Support VAST 4.x
  • Support VMAP

About

A Java library for video ad processing, e.g. insert pixels, etc.

Resources

License

Stars

Watchers

Forks

Languages