Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Update #178, implement BBC BMX MTD import, start rewrap engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdsdi3g committed Aug 5, 2016
1 parent 3b02c2d commit d9a288a
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 23 deletions.
41 changes: 26 additions & 15 deletions app/hd3gtv/mydmam/MyDMAM.java
Expand Up @@ -27,6 +27,7 @@
import java.security.NoSuchProviderException;
import java.security.Security;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
Expand All @@ -37,6 +38,7 @@
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.datatype.XMLGregorianCalendar;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

Expand All @@ -50,6 +52,7 @@
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;

import hd3gtv.configuration.Configuration;

Expand Down Expand Up @@ -242,16 +245,6 @@ public static void checkIsAccessibleClass(Class<?> context, boolean can_to_be_st

}

/*private static volatile GsonBuilder gsonbuilder;
public static Gson getGson() {
if (gsonbuilder == null) {
gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeAdapter(SourcePathIndexerElement.class, new SourcePathIndexerElement());
}
return gsonbuilder.create();
}*/

public static class GsonClassSerializer implements JsonSerializer<Class<?>>, JsonDeserializer<Class<?>> {

public JsonElement serialize(Class<?> src, Type typeOfSrc, JsonSerializationContext context) {
Expand All @@ -270,11 +263,6 @@ public Class<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationC
}
}

public static void registerJsonArrayAndObjectSerializer(GsonBuilder gson_builder) {
gson_builder.registerTypeAdapter(JsonArray.class, new MyDMAM.GsonJsonArraySerializer());
gson_builder.registerTypeAdapter(JsonObject.class, new MyDMAM.GsonJsonObjectSerializer());
}

/**
* Direct (de)serializer.
*/
Expand Down Expand Up @@ -319,6 +307,29 @@ public JsonObject deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
}
}

public static class XMLGregorianCalendarSerializer implements JsonSerializer<XMLGregorianCalendar>, JsonDeserializer<XMLGregorianCalendar> {

public XMLGregorianCalendar deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(json.getAsBigInteger().longValue());
return new XMLGregorianCalendarImpl(gc);
}

public JsonElement serialize(XMLGregorianCalendar src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.toGregorianCalendar().getTimeInMillis());
}
}

/**
* Register JsonArray, JsonObject, XMLGregorianCalendar, Class.
*/
public static void registerBaseSerializers(GsonBuilder gson_builder) {
gson_builder.registerTypeAdapter(JsonArray.class, new MyDMAM.GsonJsonArraySerializer());
gson_builder.registerTypeAdapter(JsonObject.class, new MyDMAM.GsonJsonObjectSerializer());
gson_builder.registerTypeAdapter(XMLGregorianCalendar.class, new MyDMAM.XMLGregorianCalendarSerializer());
gson_builder.registerTypeAdapter(Class.class, new MyDMAM.GsonClassSerializer());
}

/**
* Search application.conf in classpath, and return the /mydmam main directory.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/auth/AuthTurret.java
Expand Up @@ -115,7 +115,7 @@ public AuthTurret(Keyspace keyspace) throws ConnectionException, NoSuchAlgorithm
/**
* Outside of this package serializers
*/
builder.registerTypeAdapter(Class.class, new MyDMAM.GsonClassSerializer());
MyDMAM.registerBaseSerializers(builder);

gson_simple = builder.create();

Expand Down
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/manager/AppManager.java
Expand Up @@ -68,7 +68,7 @@ public final class AppManager implements InstanceActionReceiver, InstanceStatusI
/**
* Outside of this package serializers
*/
builder.registerTypeAdapter(Class.class, new MyDMAM.GsonClassSerializer());
MyDMAM.registerBaseSerializers(builder);

simple_gson = builder.create();

Expand Down
2 changes: 2 additions & 0 deletions app/hd3gtv/mydmam/metadata/MetadataCenter.java
Expand Up @@ -32,6 +32,7 @@
import hd3gtv.mydmam.transcode.images.ImageMagickThumbnailer.Cartridge;
import hd3gtv.mydmam.transcode.images.ImageMagickThumbnailer.FullDisplay;
import hd3gtv.mydmam.transcode.images.ImageMagickThumbnailer.Icon;
import hd3gtv.mydmam.transcode.mtdgenerator.BBCBmxAnalyser;
import hd3gtv.mydmam.transcode.mtdgenerator.FFmpegAlbumartwork;
import hd3gtv.mydmam.transcode.mtdgenerator.FFmpegAudioDeepAnalyser;
import hd3gtv.mydmam.transcode.mtdgenerator.FFmpegInterlacingDetection;
Expand Down Expand Up @@ -155,6 +156,7 @@ public String toString() {
addExtractor(new FFmpegInterlacingDetection());
addExtractor(new FFmpegSnapshot());
addExtractor(new FFmpegAlbumartwork());
addExtractor(new BBCBmxAnalyser());

addExtractor(new ImageMagickThumbnailer(FullDisplay.class, PreviewType.full_size_thumbnail, FullDisplay.profile_name));
addExtractor(new ImageMagickThumbnailer(Cartridge.class, PreviewType.cartridge_thumbnail, Cartridge.profile_name));
Expand Down
2 changes: 2 additions & 0 deletions app/hd3gtv/mydmam/metadata/container/ContainerOperations.java
Expand Up @@ -41,6 +41,7 @@
import com.google.gson.JsonParseException;

import hd3gtv.mydmam.Loggers;
import hd3gtv.mydmam.MyDMAM;
import hd3gtv.mydmam.db.Elasticsearch;
import hd3gtv.mydmam.db.ElasticsearchBulkOperation;
import hd3gtv.mydmam.db.ElasticsearchMultiGetRequest;
Expand Down Expand Up @@ -90,6 +91,7 @@ public static JsonObject getJsonObject(JsonElement json, boolean can_null) throw
GsonIgnoreStrategy ignore_strategy = new GsonIgnoreStrategy();
gson_builder.addDeserializationExclusionStrategy(ignore_strategy);
gson_builder.addSerializationExclusionStrategy(ignore_strategy);
MyDMAM.registerBaseSerializers(gson_builder);

gson_simple = gson_builder.create();

Expand Down
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/transcode/ProcessingKitEngine.java
Expand Up @@ -22,7 +22,7 @@
import hd3gtv.mydmam.MyDMAM;
import hd3gtv.mydmam.manager.AppManager;

public class ProcessingKitEngine {
public final class ProcessingKitEngine {

private HashMap<String, ProcessingKit> list_cache;
private AppManager manager;
Expand Down
153 changes: 150 additions & 3 deletions app/hd3gtv/mydmam/transcode/kit/PKitOpAtomTo1A_XMLBased.java
Expand Up @@ -17,13 +17,30 @@
package hd3gtv.mydmam.transcode.kit;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import org.apache.commons.io.FilenameUtils;

import hd3gtv.mydmam.Loggers;
import hd3gtv.mydmam.metadata.MetadataIndexingLimit;
import hd3gtv.mydmam.metadata.MetadataIndexingOperation;
import hd3gtv.mydmam.metadata.container.Container;
import hd3gtv.mydmam.pathindexing.SourcePathIndexerElement;
import hd3gtv.mydmam.transcode.ProcessingKit;
import hd3gtv.mydmam.transcode.ProcessingKitInstance;
import hd3gtv.mydmam.transcode.mtdcontainer.FFprobe;
import hd3gtv.tools.ExecBinaryPath;
import hd3gtv.tools.ExecprocessBadExecutionException;
import hd3gtv.tools.ExecprocessGettext;
import hd3gtv.tools.XmlData;

public class PKitOpAtomTo1A_XMLBased extends ProcessingKit {

Expand Down Expand Up @@ -58,20 +75,150 @@ public ProcessingKitInstance createInstance(File temp_directory) throws Exceptio
return new Instance(temp_directory);
}

private class Atom {
File path;
Container metadatas;
boolean must_be_extracted = false;
File extracted_path;

private Atom(File path) {
this.path = path;
}
}

public class Instance extends ProcessingKitInstance {

public Instance(File temp_directory) throws NullPointerException, IOException {
super(temp_directory);
}

public List<File> process(File physical_source, Container source_indexing_result) throws Exception {
// TODO Auto-generated method stub
/**
* Open XML.
**/
XmlData order_xml = XmlData.loadFromFile(physical_source);
if (order_xml.getDocumentElement().getTagName().equals("wrap") == false) {
throw new IOException("Invalid format for XML document. Document element is <" + order_xml.getDocumentElement().getTagName() + ">");
}

File file_atom_0 = new File(FilenameUtils.removeExtension(physical_source.getAbsolutePath()) + ".mxf");
File file_atom_1 = new File("");
File file_atom_2 = new File("");
File file_atom_3 = new File("");
File file_atom_4 = new File("");
URL dest_archive = null;

NodeList document_items = order_xml.getDocumentElement().getChildNodes();
for (int pos = 0; pos < document_items.getLength(); pos++) {
Element node = (Element) document_items.item(pos);
if (node.getTagName().equals("atom1")) {
file_atom_1 = new File(FilenameUtils.getFullPath(physical_source.getAbsolutePath()) + node.getTextContent());
} else if (node.getTagName().equals("atom2")) {
file_atom_2 = new File(FilenameUtils.getFullPath(physical_source.getAbsolutePath()) + node.getTextContent());
} else if (node.getTagName().equals("atom3")) {
file_atom_3 = new File(FilenameUtils.getFullPath(physical_source.getAbsolutePath()) + node.getTextContent());
} else if (node.getTagName().equals("atom4")) {
file_atom_4 = new File(FilenameUtils.getFullPath(physical_source.getAbsolutePath()) + node.getTextContent());
} else if (node.getTagName().equals("dest_archive")) {
dest_archive = new URL(node.getTextContent());
} else {
throw new IOException("Invalid element in XML Document. Element is <" + node.getTagName() + ">");
}
}

ArrayList<Atom> mxf_files = new ArrayList<>(5);
if (file_atom_0.exists() && file_atom_0.isFile()) {
mxf_files.add(new Atom(file_atom_0));
} else {
throw new FileNotFoundException("Can't found main MXF file " + file_atom_0);
}
if (file_atom_1.exists() && file_atom_1.isFile()) {
mxf_files.add(new Atom(file_atom_1));
}
if (file_atom_2.exists() && file_atom_2.isFile()) {
mxf_files.add(new Atom(file_atom_2));
}
if (file_atom_3.exists() && file_atom_3.isFile()) {
mxf_files.add(new Atom(file_atom_3));
}
if (file_atom_4.exists() && file_atom_4.isFile()) {
mxf_files.add(new Atom(file_atom_4));
}

/**
* Get all files, do MXF analyst on it.
* Try to process video file (if exists).
* If failed, extract raw content.
*/
mxf_files.forEach(atom -> {
SourcePathIndexerElement spie = new SourcePathIndexerElement();
spie.currentpath = "/cli-request/" + System.currentTimeMillis();
spie.date = atom.path.lastModified();
spie.dateindex = System.currentTimeMillis();
spie.directory = false;
spie.parentpath = "/cli-request";
spie.size = atom.path.length();
spie.storagename = "MyDMAM-Request";

try {
atom.metadatas = new MetadataIndexingOperation(atom.path).setLimit(MetadataIndexingLimit.FAST).doIndexing();
} catch (Exception e) {
Loggers.Metadata.warn("Can't extract medatatas", e);
return;
}
if (atom.metadatas.getByClass(FFprobe.class) == null) {
atom.must_be_extracted = true;
}
});

/**
* Extract raw content.
*/
for (int pos = 0; pos < mxf_files.size(); pos++) {
Atom item = mxf_files.get(pos);
if (item.must_be_extracted == false) {
continue;
}

String temp_file_name = FilenameUtils.getFullPath(item.path.getAbsolutePath()) + item.metadatas.getMtd_key();

ArrayList<String> param = new ArrayList<String>();
param.add("--ess-out");
param.add(temp_file_name);
param.add(item.path.getAbsolutePath());

ExecprocessGettext process = new ExecprocessGettext(ExecBinaryPath.get("mxf2raw"), param);
process.setEndlinewidthnewline(true);
try {
process.start();
} catch (IOException e) {
if (e instanceof ExecprocessBadExecutionException) {
Loggers.Transcode_Metadata.error("Problem with mxf2raw extraction (BBC BMX), " + process + ", " + item.metadatas);
}
throw e;
}

String[] raw_files_names = (new File(FilenameUtils.getFullPath(item.path.getAbsolutePath()))).list(new FilenameFilter() {

@Override
public boolean accept(File dir, String name) {
return name.startsWith(item.metadatas.getMtd_key());
}
});
if (raw_files_names.length != 1) {
throw new IndexOutOfBoundsException("Cant found BMX temp file !" + raw_files_names);
}

item.extracted_path = new File(raw_files_names[0]);
}

/**
* Start ffmpeg for rewrap
*/
// TODO add source timecode
/*ffmpeg -y $ALL_STREAMS -codec:v copy -codec:a copy $ALL_MAPS -f mxf $FILE_DEST.mxf
ALL_STREAMS=$ALL_STREAMS" -i "$(extractStreamPath $2);
ALL_MAPS=$ALL_MAPS" -map 0:0";*/

/**
* Move to dest (ftp)
*/
return null;
Expand Down
56 changes: 56 additions & 0 deletions app/hd3gtv/mydmam/transcode/mtdcontainer/BBCBmx.java
@@ -0,0 +1,56 @@
/*
* This file is part of MyDMAM.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Copyright (C) hdsdi3g for hd3g.tv 2016
*
*/
package hd3gtv.mydmam.transcode.mtdcontainer;

import java.util.List;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

import hd3gtv.mydmam.metadata.container.ContainerEntry;
import hd3gtv.mydmam.metadata.container.EntryAnalyser;
import hd3gtv.mydmam.metadata.container.SelfSerializing;
import uk.co.bbc.rd.bmx.Bmx;

public class BBCBmx extends EntryAnalyser {

private Bmx bmx;

protected void extendedInternalSerializer(JsonObject current_element, EntryAnalyser _item, Gson gson) {
}

public String getES_Type() {
return "bbc_bmx";
}

protected List<Class<? extends SelfSerializing>> getSerializationDependencies() {
return null;
}

protected ContainerEntry internalDeserialize(JsonObject source, Gson gson) {
return null;
}

public Bmx getBmx() {
return bmx;
}

public void setBmx(Bmx bmx) {
this.bmx = bmx;
}

}

0 comments on commit d9a288a

Please sign in to comment.