0

Got some issues with Youtube API, it doesnt show åäö in titles. Urltitle script does, after an eggdrop recompile. So any suggestions how to make 2nd script use utf8 or so?

  • 2
    Can you insert in your question: 1. the part of the script that retrieves the title, 2. the part of the script that puts the title in the channel and 3. the current output that is not desired for a give youtube video? – Jerry Jul 31 '20 at 07:13
  • The answer may well involve the `encoding` command, but it _really_ helps to have what you've tried first so that we can recommend the correct way to use it. Getting it wrong will just make the mojibake mess even worse. – Donal Fellows Jul 31 '20 at 11:10
  • I can link the url for the script. I am not the one who made it. I just use it. [link](https://github.com/MadaliNTCL/eggdrop-tcl/blob/master/youtube/youtube.tcl) – Pär Hagnestål Aug 01 '20 at 11:36
  • I saw this at another charset question. `putserv "PRIVMSG $chan :[encoding convertto utf-8 $translated]"` That might work? – Pär Hagnestål Aug 01 '20 at 11:47

1 Answers1

0

There are two key problems here:

  1. Ensuring that the data from the data source is understood correctly by Tcl.
  2. Ensuring that the correct data known by Tcl is reported to the channel in a way that it can digest.

Hopefully the first is already working; the http package and the various database access packages mostly get that right (except when the data source tells lies, as can happen occasionally with real-world data). You can test this by doing:

set msg ""
foreach char [split $data ""] {                # For each UNICODE character...
    append msg [format %04x [scan $char %c]];  # The hex code for the char
}
putserv "PRIVMSG $chan :$msg"

For example, this would generate a message like this for data of åäö€:

00e500e400f620ac

If that's working (it's the hard part to solve if it isn't), all you've got to do is ensure that the data actually goes correctly to the channel. This might be as simple as doing this (if the Tcl side of the channel is in binary mode):

putserv "PRIVMSG $chan :[encoding convertto utf-8 $data]"

In theory, the Tcl channel that putserv writes on could do the conversion for you, but getting that part right is tricky when there's unknown code between your code and the actual channel.

It's also possible that the IRC server expects the data in a different encoding such as iso8859-15. There isn't a universal rule there, alas.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215