Kakulukian / youtube-transcript

Fetch transcript from a youtube video
240 stars 51 forks source link

' instead on apostrophe (') #28

Open campar opened 3 months ago

campar commented 3 months ago

Apostrophe inside response is HTML encoded for some reason.

retrieving ' instead of apostrophe('),

[
  {
    text: 'there's so much to learn in javascript',
    duration: 3.92,
    offset: 0.64,
    lang: 'en'
  },
...
Jonathan-Asher commented 2 months ago

This function translates HTML entities back to readable characters:

function decodeHtmlEntities(str: string): string {
  const entities: { [key: string]: string } = {
    '"': '"',
    ''': "'",
    '&lt;': '<',
    '&gt;': '>',
    '"': '"',
    ''': "'",
    '<': '<',
    '>': '>',
    '&amp;': '&',
    '&': '&',
  };
  return str.replace(
    /&amp;#39;|&amp;lt;|&amp;gt;|&amp;quot;|&amp;amp;|&#39;|&lt;|&gt;|&quot;|&amp;/g,
    (match) => entities[match],
  );
}