raydouglass / xmltv-to-mxf

Converts XMLTV to WMC MXF format
GNU General Public License v3.0
6 stars 3 forks source link

xmltv_ns (season/episode/part number) should be zero indexed #2

Closed tonywagner closed 4 years ago

tonywagner commented 4 years ago

According to the XMLTV spec, xmltv_ns (season/episode/part number) is zero indexed, so we should be adding 1 to those values for our MXF output. For example, "0.20" means season 1, episode 21.

Also according to the spec, total values after a slash are not zero indexed -- for example, "0.12/13" would represent the last episode out of 13 in season 1. I don't believe this program does anything with those values after the slash anyway, but my code below should correctly pass them through without incrementing.

This fix should go in src/main/java/com/dontocsata/xmltv/parser/ProgramHandler.java -- line 90 under the xmltv_ns case is currently this:

XmlTvProgramId xmlTvProgramId = XmlTvProgramId.parse(getString());

You can replace that line with the following code block -- although I'm open to a more graceful method!

String str = getString();
String[] arrOfStr = str.replaceAll("\\s+","").split("\\.");
int length = arrOfStr.length;
str = "";
for(int i=0; i < length; i++){
  String[] subArr = arrOfStr[i].split("/");
  int sublength = subArr.length;
  str += Integer.parseInt(subArr[0]) + 1;
  if ( sublength == 2 ) {
    str += "/" + subArr[1];
  }
  str += ".";
}
XmlTvProgramId xmlTvProgramId = XmlTvProgramId.parse(str);
raydouglass commented 4 years ago

@tonywagner Can you take a quick look at #4? I think it resolves this issue.