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

Commit

Permalink
Correct #216: change the Date parser (and do a brute-force parsing) a…
Browse files Browse the repository at this point in the history
…nd add special case for audio stat ffmpeg result.
  • Loading branch information
hdsdi3g committed Dec 18, 2016
1 parent 2a8da78 commit d8d3ece
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.apache.commons.lang.math.NumberUtils;

import hd3gtv.mydmam.Loggers;

public class FFmpegAudioDeepAnalystChannelStat {

public String toString() {
Expand Down Expand Up @@ -103,8 +105,13 @@ public void parseFromFFmpegLine(String line) throws IndexOutOfBoundsException, N
}
String name = content[0].trim();
Number value = -144.49f;
if (content[1].trim().equals("-inf") == false) {
value = NumberUtils.createNumber(content[1].trim());
if (content[1].trim().equals("-inf") == false && (name.startsWith("Bit depth") == false)) {
try {
value = NumberUtils.createNumber(content[1].trim());
} catch (NumberFormatException e) {
Loggers.Transcode_Metadata.error("Can't parse number. Raw input: \"" + line + "\", selected entry: " + content[1]);
throw e;
}
}

if (name.startsWith("Channel")) {
Expand Down
40 changes: 18 additions & 22 deletions app/hd3gtv/mydmam/transcode/mtdgenerator/FFprobeAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -269,40 +270,38 @@ public ContainerEntryResult processFull(Container container, StoppableProcessing
return new ContainerEntryResult(result);
}

private static final DateFormat[] formats = { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), new SimpleDateFormat("yyyy-MM-dd") };

private static Date bruteForceDateParser(String date_value) {
for (int pos = 0; pos < formats.length; pos++) {
try {
return formats[pos].parse(date_value);
} catch (ParseException e) {
}
}
return null;
}

private static void patchTagDate(JsonObject tags) {
if (tags == null) {
return;
}
String key;
String value;
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

HashMap<String, JsonPrimitive> new_values = new HashMap<String, JsonPrimitive>();
List<String> remove_values = new ArrayList<String>();

Date parsed_date;
/**
* Search and prepare changes
*/
for (Map.Entry<String, JsonElement> entry : tags.entrySet()) {
key = (String) entry.getKey();
value = entry.getValue().getAsString();
try {
if (key.equals("creation_time")) {
new_values.put(key, new JsonPrimitive(format.parse(value).getTime()));
} else if (key.equals("date")) {
if (value.length() == "0000-00-00T00:00:00Z".length()) {
new_values.put(key, new JsonPrimitive(format.parse(value.substring(0, 10) + " " + value.substring(11, 19)).getTime()));
} else if (value.length() == "0000-00-00 00:00:00".length()) {
new_values.put(key, new JsonPrimitive(format.parse(value).getTime()));
} else if (value.length() == "0000-00-00".length()) {
new_values.put(key, new JsonPrimitive(format.parse(value.substring(0, 10) + " 00:00:00").getTime()));
} else {
remove_values.add(key);
new_values.put(key + "-raw", new JsonPrimitive("#" + value));
}
}
} catch (ParseException e) {
Loggers.Transcode_Metadata.error("Can't parse date, tags: " + tags, e);
parsed_date = bruteForceDateParser(value);
if (parsed_date != null) {
new_values.put(key, new JsonPrimitive(parsed_date.getTime()));
}
}

Expand All @@ -312,9 +311,6 @@ private static void patchTagDate(JsonObject tags) {
for (Map.Entry<String, JsonPrimitive> entry : new_values.entrySet()) {
tags.add(entry.getKey(), entry.getValue());
}
for (int pos = 0; pos < remove_values.size(); pos++) {
tags.remove(remove_values.get(pos));
}
}

public String getLongName() {
Expand Down

0 comments on commit d8d3ece

Please sign in to comment.