xtrime-ru / TelegramApiServer

Fast, simple, async php telegram api server: MadelineProto + Amp HTTP Server
https://tg.i-c-a.su
MIT License
575 stars 129 forks source link

Downloading Video Thumbs #42

Closed artin closed 4 years ago

artin commented 4 years ago

Every video message on Telegram has 'thumbs' like this :

array:6 [▼
  "_" => "photoSize"
  "type" => "m"
  "location" => array:3 [▼
    "_" => "fileLocationToBeDeprecated"
    "volume_id" => 400032600322
    "local_id" => 4558
  ]
  "w" => 320
  "h" => 300
  "size" => 19721
]

I am trying to download them but not working and I am getting following error :

{
    "exception": "TypeError",
    "message": "Argument 1 passed to TelegramApiServer\\MadelineProtoExtensions\\ApiExtensions::downloadToResponse() must be of the type array, string given, called in \/home\/telegram\/TelegramApiServer\/src\/Controllers\/AbstractApiController.php on line 169",
    "file": "\/home\/telegram\/TelegramApiServer\/src\/MadelineProtoExtensions\/ApiExtensions.php",
    "line": 461,
    "code": 0,
    "backtrace": [
        {
            "file": "\/home\/telegram\/TelegramApiServer\/src\/Controllers\/AbstractApiController.php",
            "line": 169,
            "function": "downloadToResponse",
            "class": "TelegramApiServer\\MadelineProtoExtensions\\ApiExtensions",
            "type": "->"
        },
        {
            "file": "\/home\/telegram\/TelegramApiServer\/src\/Controllers\/ApiController.php",
            "line": 32,
            "function": "callApiCommon",
            "class": "TelegramApiServer\\Controllers\\AbstractApiController",
            "type": "->"
        },
        {
            "file": "\/home\/telegram\/TelegramApiServer\/src\/Controllers\/AbstractApiController.php",
            "line": 145,
            "function": "callApi",
            "class": "TelegramApiServer\\Controllers\\ApiController",
            "type": "->"
        }
    ]
}

I even tried to put it in "Media" array but not success

array:1 [▼
  "media" => array:6 [▼
    "_" => "photoSize"
    "type" => "m"
    "location" => array:3 [▼
      "_" => "fileLocationToBeDeprecated"
      "volume_id" => 400032600322
      "local_id" => 4558
    ]
    "w" => 320
    "h" => 300
    "size" => 19721
  ]
]

Curl Connection is giving following error ( without any error on the TelegramApiServer) Empty reply from server

Did you ever tried to download Video Thumbnail ?

xtrime-ru commented 4 years ago

Thumbs downloaded with hack after TL layer 100:

See sources of this method: https://github.com/xtrime-ru/TelegramApiServer/blob/7015691686d57cd3422567a498ab5a83f5d5f663/src/MadelineProtoExtensions/ApiExtensions.php#L459:L467

Or you can just use it. It will return thumb image to stream/browser. You can provide 'peer' and 'id', or 'message' object;

artin commented 4 years ago

Can you give an example ? Do I have to pass 'message' object like downloadToResponse Method To getMediaPreview ?

xtrime-ru commented 4 years ago

Can you give an example ? Do I have to pass 'message' object like downloadToResponse Method To getMediaPreview ?

Its my custom method. Im using it like this:

https://github.com/xtrime-ru/TelegramRSS/blob/e1e95f0e118be894ea2c7a501f46aaea2096bec3/app/Controller.php#L233

xtrime-ru commented 4 years ago

Can you give an example ? Do I have to pass 'message' object like downloadToResponse Method To getMediaPreview ?

You can provide message object in “message”, or send “peer” and “id”. Ill send examples later if you still need them.

artin commented 4 years ago

Can you give an example ? Do I have to pass 'message' object like downloadToResponse Method To getMediaPreview ?

Its my custom method. Im using it like this:

https://github.com/xtrime-ru/TelegramRSS/blob/e1e95f0e118be894ea2c7a501f46aaea2096bec3/app/Controller.php#L233

I mean to what Api Address I have to send my request ? getMediaPreview ? Sending 'message' objects data like what We are requesting to download a file ? (downloadToResponse)

something like this ?

curl --location --request POST '127.0.0.1:9503/api/getMediaPreview' \
--header 'Content-Type: application/json' \
--data-raw '{
    "media": {
                "_": "message",
                "out": false,
                "mentioned": false,
                "media_unread": false,
                "silent": false,
                "post": true,
                "from_scheduled": false,
                "legacy": false,
                "edit_hide": false,
                "id": 11,
                "to_id": {
                    "_": "peerChannel",
                    "channel_id": 1247413145
                },
                "date": 1587479130,
                "message": "test caption",
                "media": {
                    "_": "messageMediaDocument",
                    "document": {
                        "_": "document",
                        "id": 5834658774639445891,
                        "access_hash": 7348570211076296083,
                        "file_reference": {
                            "_": "bytes",
                            "bytes": "AkpaA5kAAAALXukdNW8iv1F3xS5jpQ8TUgjZC\/k="
                        },
                        "date": 1587479129,
                        "mime_type": "video\/mp4",
                        "size": 1358648,
                        "thumbs": [
                            {
                                "_": "photoStrippedSize",
                                "type": "i",
                                "bytes": {
                                    "_": "bytes",
                                    "bytes": "ASUoYI\/7qY9zUsUROWJ4FKzALuOceuKkjkTYRnjFQWgkIUL7imZQ9VFK5DpkEcGmrEWGQRxQgYpjjYcZFFRncBkggUUxE7SR4Hzce1VzuByikKelMxyP61cyCMggCmguRFA0Rx164FMjYq2aklZNgIJz3OKiaViPlOfU4xUrQqWo64mDqQM9KKiC+apAPzelFMkmMQ9TS+XgfeNFFACMh6bv0phVgD85\/IUUUAxvlbuGZj+NFFFMRw=="
                                }
                            },
                            {
                                "_": "photoSize",
                                "type": "m",
                                "location": {
                                    "_": "fileLocationToBeDeprecated",
                                    "volume_id": 400032600322,
                                    "local_id": 4558
                                },
                                "w": 320,
                                "h": 300,
                                "size": 19721
                            }
                        ],
                        "dc_id": 4,
                        "attributes": [
                            {
                                "_": "documentAttributeVideo",
                                "round_message": false,
                                "supports_streaming": true,
                                "duration": 4,
                                "w": 848,
                                "h": 784
                            },
                            {
                                "_": "documentAttributeFilename",
                                "file_name": "IMG_4503.MOV"
                            }
                        ]
                    }
                },
                "views": 6
            }
}'

It is a little confusing for me ... I tried all methods but no success :(

Please send an example whenever you have free time Спасибо брат :)

xtrime-ru commented 4 years ago

I mean to what Api Address I have to send my request ? getMediaPreview ? something like this ?

Address is correct. Requests alsmoust ok :):

--data-raw '{
    "data":{
        "message": {
            "_": "message",
                          ...

Also you can try to switch to shorted version: http://127.0.0.1:9503/api/getMediaPreview?data[peer]=channel%231247413145&data[id][]=11 It will fetch message if it not provided.

Sending 'message' objects data like what We are requesting to download a file ? (downloadToResponse)

Only full messages supported. Im extracting $message['media'] from them :) MediaObjects not supported.

Спасибо брат :)

خوش آمدید ;)

artin commented 4 years ago

Passing message object didn't work for me .. maybe I am doing something wrong somewhere

but the shorted version just worked perfectly :+1: Thanks :100:

xtrime-ru commented 4 years ago

Passing message object didn't work for me .. maybe I am doing something wrong somewhere

but the shorted version just worked perfectly 👍 Thanks 💯

Great. Actually im using only short syntax too. So maybe there is a bug with "message" key :)