Kevinjil/Jellyfin.Xtream

Missing unicode parsing in EPG

Closed this issue · 1 comments

image

As you can see in the EPG there are \uXXXX codes instead of the right characters.

In this case instead of this:

"U\u017dIVO: U\u017eivo: NFL: DIVISIONAL PLAYOFF G3: DETROIT - TAMPA BAY, ameri\u010dki nogomet"

It should display:

"UŽIVO: Uživo: NFL: DIVISIONAL PLAYOFF G3: DETROIT - TAMPA BAY, američki nogomet"

The encodings for EPG seem to have the C/C++ format, so they don't render in the Jellyfin UI and need to be transformed into HTML entities: https://www.fileformat.info/info/unicode/char/17d/index.htm

This code seems to accomplish it:

// A function to convert a hexadecimal number to a decimal number
function hexToDec(hex) {
  return parseInt(hex, 16);
}

// A function to convert a C style unicode escape sequence to a HTML entity
function unicodeToHtml(unicode) {
  // Remove the backslash and the u from the sequence
  var hex = unicode.slice(2);
  // Convert the hexadecimal number to a decimal number
  var dec = hexToDec(hex);
  // Return the HTML entity using the decimal number as the character code
  return "&#" + dec + ";";
}

// A function to parse a string with C style unicode escape sequences into HTML entities
function parseUnicodeToHtml(str) {
  // Use a regular expression to match all C style unicode escape sequences in the string
  var regex = /\u[0-9a-fA-F]{4}/g;
  // Replace each match with the corresponding HTML entity using the unicodeToHtml function
  var result = str.replace(regex, unicodeToHtml);
  // Return the result
  return result;
}

// A sample string with C style unicode escape sequences
var sample = "U\u017dIVO: U\u017eivo: NFL: DIVISIONAL PLAYOFF G3: DETROIT - TAMPA BAY, ameri\u010dki nogomet";

// Parse the sample string into HTML entities
var parsed = parseUnicodeToHtml(sample);

// Print the result
console.log(parsed);

The string could also contain a double escaped version with two backslashes instead of one.
Probably it would be better to try replacing those first, it is just an additional backslash in the regex above.

Seems to be working in Jellyfin 10.9