3 November 2019

Telegram bot file_id parser

function base64url_decode($data) {
  return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
 function rle_decode($string)
    {
        $new = '';
        $last = '';
        $null = chr(0);
        foreach (str_split($string) as $cur) {
            if ($last === $null) {
                $new .= str_repeat($last, ord($cur));
                $last = '';
            } else {
                $new .= $last;
                $last = $cur;
            }
        }
        $string = $new.$last;
        return $string;
    }
function parse($s)
{
$s = base64url_decode($s);
$s=rle_decode($s);
   $r=unpack("ifile_type/idc_id/qfile_id/qaccess_hash",$s);
    return $r;
}

var_dump(parse('AgADBAADZbMxG7cJAVGXAeNiLWOiH5lPqBsABAEAAwIAA3kAAzcYAwABFgQ'));

possbible file_type list

0 = thumbnail
2 = photo
3 = voice
4 = video
5 = document
8 = sticker
9 = audio
10 = gif
13 = video_note (round video)

No comments:

Post a Comment