Network broadcasting - working with encodings

    Having connected to Corbin (no, this is not an advertisement), and browsing their site for the sake of interest, I came across a large number of Internet radio stations, to which I tried to immediately become addicted. My disappointment was great. I did not find a single player that would normally work with the encoding of stream tags. The last hope was VLC, but it turned out to be the worst of all - it received only general information about the stream, but did not receive the information about the current composition transmitted by the server.
    Mplayer gave me the following in the console:
    torkvemada@inquisitia-nout ~ $ mplayer 85.21.79.5:8185/listen.pls
    MPlayer 1.0rc2-4.3.3 (C) 2000-2007 MPlayer Team
    CPU: Intel(R) Atom(TM) CPU N270 @ 1.60GHz (Family: 6, Model: 28, Stepping: 2)
    CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    mplayer: could not connect to socket
    mplayer: No such file or directory
    Failed to open LIRC support. You will not be able to use your remote control.

    Playing 85.21.79.5:8185/listen.pls.
    Resolving 85.21.79.5 for AF_INET6...
    Couldn't resolve name for AF_INET6: 85.21.79.5
    Connecting to server 85.21.79.5[85.21.79.5]: 8185...
    Cache size set to 320 KBytes

    Playing 85.21.79.5:8185/.
    Resolving 85.21.79.5 for AF_INET6...
    Couldn't resolve name for AF_INET6: 85.21.79.5
    Connecting to server 85.21.79.5[85.21.79.5]: 8185...
    Name : 101.ru: Aquarium BG
    Genre : N/A
    Website: www.101.ru
    Public : yes
    Bitrate: 0kbit/s
    Cache size set to 320 KBytes
    Cache fill: 0.00% (0 bytes)
    ICY Info: StreamTitle='ÀÊÂÀÐÈÓÌ - Íàóêè Þíîøåé - 0:00';StreamUrl='';
    Cache fill: 15.00% (49152 bytes)
    Audio file file format detected.
    ==========================================================================
    Forced audio codec: mad
    Opening audio decoder: [libmad] libmad mpeg audio decoder
    AUDIO: 44100 Hz, 2 ch, s16le, 96.0 kbit/6.80% (ratio: 12000->176400)
    Selected audio codec: [mad] afm: libmad (libMAD MPEG layer 1-2-3)
    ==========================================================================
    AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)
    Video: no video
    Starting playback...
    A: 27.8 (27.8) of -0.0 (unknown) 3.7% 45%
    ICY Info: StreamTitle='ÀÊÂÀÐÈÓÌ - Âåëèêèé Äâîðíèê - 0:00';StreamUrl='';
    A: 212.2 (03:32.2) of -0.0 (unknown) 3.7% 45%
    ICY Info: StreamTitle='ADVBEGIN - ADVBEGIN - 0:00';StreamUrl='';
    A: 213.5 (03:33.5) of -0.0 (unknown) 3.7% 45%
    ICY Info: StreamTitle='ADV_0001 - 0:00';StreamUrl='';
    A: 243.6 (04:03.5) of -0.0 (unknown) 3.7% 45%
    ICY Info: StreamTitle='ADVENG - ADVENG - 0:00';StreamUrl='';
    A: 247.7 (04:07.6) of -0.0 (unknown) 3.7% 45%
    ICY Info: StreamTitle='ÀÊÂÀÐÈÓÌ - Áëþç Ïðîñòîãî ×åëîâåêà - 0:00';StreamUrl='';
    A: 348.7 (05:48.7) of -0.0 (unknown) 3.6% 45%
    Exiting... (Quit)

    As you can see, all the information is obtained, but the cp1251 mplayer encoding was not able to recognize. Like all other players. A similar situation, by the way, would be highly likely to be repeated in Windows, it would be enough just to find a stream with UTF-8. But we, fortunately, have the opportunity to rectify the situation. For an hour of digging into the source of mplayer and a couple of recompilations (alas, my atom leaves much to be desired in terms of compilation speed), I sketched a small patch that allows the command-line parameter to indicate in which encoding the stream comes to us and displays the information in the correct encoding. The patch uses iconv, so it can be adapted to absolutely any player if desired, to display both id3 tags and stream information in your linux system.
    All the rest of the manual refers to APT systems (Ubuntu, Debian, possibly AltLinux etc.), but it is easy to repeat on an arbitrary system.
    We run ` apt-get source mplayer` to get the mplayer sources.
    We go into the resulting directory (I have mplayer-1.0 ~ rc2 ) and edit the files:
    • cfg-common.h:
      Add somewhere on the 90th line
      1. #ifdef USE_ICONV
      2.         {"tagcp", &tag_cp, CONF_TYPE_STRING,  0,  0,  0, NULL},
      3. #endif
    • libass / ass_mp.c:
      Add on the 36th line:
      1. #ifdef USE_ICONV
      2. extern char* tag_cp;
      3. #else
      4. static char* tag_cp = 0;
      5. #endif
    • stream / stream.h:
      Add to the 302nd line:
      1. extern char * tag_cp;
    • stream / http.c:
      Add on the 30th line:
      1. #ifdef USE_ICONV
      2. #include
      3. char *tag_cp = 0;
      4. #endif

      And on line 121 (after the line " info [len] = 0; "):
      1. #ifdef USE_ICONV
      2.     iconv_t iconv_converter = (iconv_t)(-1);
      3.     char *outcp = "UTF-8";
      4.     char *incp = tag_cp;
      5.     if (tag_cp && (iconv_converter == (iconv_t)(-1)))
      6.     {
      7.             if ((iconv_converter = iconv_open (outcp, incp)) == (iconv_t)(-1))
      8.             {
      9.                     mp_msg(MSGT_DEMUXER, MSGL_ERR, "ICY: can't open iconv.);
      10.             }
      11.     }       
      12.     if (iconv_converter != (iconv_t)(-1))
      13.     {       
      14.             size_t tmp_conv_len = nlen * 4;
      15.             size_t conv_len = tmp_conv_len;
      16.             size_t tmp_len = nlen;
      17.             char *tmp_info = info;
      18.             char *converted_info = (char*)malloc(conv_len + 1);
      19.             if (!converted_info)
      20.                     mp_msg(MSGT_DEMUXER, MSGL_ERR, "ICY: can't allocate memory.);
      21.             char *tmp_conv_info = converted_info;
      22.             if ((conv_len = iconv(iconv_converter, &tmp_info, &tmp_len, &tmp_conv_info, &tmp_conv_len)) == (size_t)(-1))
      23.             {
      24.                    mp_msg(MSGT_DEMUXER, MSGL_WARN, "ICY: error while iconving info.);
      25.                     free(converted_info);
      26.                     (void)iconv_close(iconv_converter);
      27.             }       
      28.            else    
      29.             {       
      30.                     *tmp_conv_info='\0';
      31.                     free(info);
      32.                     info = converted_info;
      33.                     (void)iconv_close(iconv_converter);
      34.                     iconv_converter = (iconv_t)(-1);
      35.             }
      36.     }
      37. #endif /* USE_ICONV */


    Now it remains to assemble and install. We type ` debuild` and either get abuse on the missing packages (install them and run debuild again), or after a while we have some deb packages collected. We install: ` sudo dpkg -i ../mplayer_1.0~rc2-0ubuntu19+medibuntu1_i386.deb` and fix it so that the package manager does not think of reinstalling the package from the repository: ` sudo aptitude hold mplayer` .
    Lazy can download:

    Now specify the `tagcp` parameter and enjoy:
    torkvemada@inquisitia-nout ~ $ mplayer -tagcp cp1251 85.21.79.5:8185/listen.pls
    MPlayer 1.0rc2-4.3.3 (C) 2000-2007 MPlayer Team
    CPU: Intel(R) Atom(TM) CPU N270 @ 1.60GHz (Family: 6, Model: 28, Stepping: 2)
    CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    mplayer: could not connect to socket
    mplayer: No such file or directory
    Failed to open LIRC support. You will not be able to use your remote control.

    Playing 85.21.79.5:8185/listen.pls.
    Resolving 85.21.79.5 for AF_INET6...
    Couldn't resolve name for AF_INET6: 85.21.79.5
    Connecting to server 85.21.79.5[85.21.79.5]: 8185...
    Cache size set to 320 KBytes

    Playing 85.21.79.5:8185/.
    Resolving 85.21.79.5 for AF_INET6...
    Couldn't resolve name for AF_INET6: 85.21.79.5
    Connecting to server 85.21.79.5[85.21.79.5]: 8185...
    Name : 101.ru: Aquarium BG
    Genre : N/A
    Website: www.101.ru
    Public : yes
    Bitrate: 0kbit/s
    Cache size set to 320 KBytes
    Cache fill: 0.00% (0 bytes)
    ICY Info: StreamTitle='АКВАРИУМ - Заповедная Песня - 0:00';StreamUrl='';
    Cache fill: 15.00% (49152 bytes)
    Audio file file format detected.
    ==========================================================================
    Forced audio codec: mad
    Opening audio decoder: [libmad] libmad mpeg audio decoder
    AUDIO: 44100 Hz, 2 ch, s16le, 96.0 kbit/6.80% (ratio: 12000->176400)
    Selected audio codec: [mad] afm: libmad (libMAD MPEG layer 1-2-3)
    ==========================================================================
    AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)
    Video: no video
    Starting playback...
    A: 14.9 (14.8) of -0.0 (unknown) 6.6% 45%
    ICY Info: StreamTitle='АКВАРИУМ - Песня №2 - 0:00';StreamUrl='';
    A: 19.8 (19.8) of -0.0 (unknown) 6.5% 46%
    Exiting... (Quit)

    Also popular now: