vysheng / tg

telegram-cli
GNU General Public License v2.0
6.49k stars 1.53k forks source link

Can't receive original filename #598

Open mihmig opened 9 years ago

mihmig commented 9 years ago

JSON text:

{ "event": "message", "service": false, "flags": 257, "media": { "type": "document" }, "id": 114, "from": { "username": "mihmig", "flags": 257, "id": 47254369, "first_name": "mih", "phone": "xxxxxxxxxxx", "print_name": "mih_mig", "last_name": "mig", "type": "user" }, "to": { "username": "user123", "flags": 264, "id": xxxxxxx, "first_name": "xxxx", "phone": "xxxxxxxxxxx", "print_name": "xxxxxxxxxx", "last_name": "xxxxxxxxxxx", "type": "user", "real_first_name": "xxxxxxxxxxxxxxx", "real_last_name": "xxxxxxxxxx" }, "date": 1433417350, "out": false, "unread": true }

then command:

load_document 114 { "event": "download" ,"result": "/telegram/profiles/xxxxxxxxx/downloads/download_202955969448116263.txt" }

* but no original file name * :(

jonnywilliamson commented 9 years ago

+1

@luckydonald - Would there be any chance of adding the following fields in the event media key?

{#561
  +"event": "message"
<snip>
  +"media": {#573
    +"type": "document"
    +"filename": "example.pdf"
    +"size": "2045"
luckydonald commented 9 years ago

The file is not known when the message got received, only after the file is downloaded. The only thing I could do would be pytg downloading that for you, and merging the message and the filename information. The problem I see with that, is that either we have to halt processing on our message queue or else the messages reach the python script in the wrong order. Also, this would take very long, and would be a very useless feature if you don't want to do anything with the files. (and it would automatically fill your hard drive...)

luckydonald commented 9 years ago

Ew this issue was not in pytg. I was assuming that. Sorry. Didn't see that. Anyway, then never mind that feature, also It's argumentation still remains valid.

jonnywilliamson commented 9 years ago

@luckydonald - I understand. That would not be a great idea waiting for the file to be downloaded I fully agree.

One last question, rather than put the filename in that received message event, is it instead possible to put it in the outbound message event...right after the media file was sent like this example?

{  
   "date":1433751462,
   "service":false,
   "event":"message",
   "flags":259,
   "to":{  
      "phone":"<snip>",
      "flags":257,
      "id":<snip>,
      "type":"user",
      "print_name":"<snip>",
      "username":"<snip>",
      "first_name":"<snip>",
      "last_name":"<snip>"
   },
   "media":{  
      "type":"photo",
      "caption":""
      "filename":"demo.png",
      "size":"123456",
   },
   "id":1609,
   "from":{  
      "phone":"<snip>",
      "flags":264,
      "id":<snip>,
      "type":"user",
      "print_name":"<snip>",
      "username":"<snip>",
      "first_name":"<snip>",
      "last_name":"Server"
   },
   "out":true,
   "unread":true
}
luckydonald commented 9 years ago

It probably is possible, as there is somewhere code to determine the download file name. Still when actually downloading that file, that path might already be taken, and the cli might choose a different path. What is the purpose, or the plus on functionality when knowing a path before there is a file?

luckydonald commented 9 years ago

Okey, one scenario I can imagine is when sending documents, the original filename (given by the sender) is transmitted. In earlier versions there was a caption field representating the original filename. Nowdays it is gone.

# Message:
{
#...
"media": {"type": "document"} 
# ...
}
jonnywilliamson commented 9 years ago

In my case I don't need file path, just name.

I log outgoing messages to a database. I then can mark off when messages have been read. In the case of a normal message, the log shows the text that was sent out. But when I send a media message there's no text information (obviously) and all I can log is what type of media was sent out (ie document/photo/video).

I would like to just log the name of the file that was sent to provide my users with more useful information when they look at their log.

Rather than seeing: 08/Jun/2015 - 13:00 - Your account has been setup! Welcome! 08/Jun/2015 - 13:01 - document sent,

They would see Rather than seeing: 08/Jun/2015 - 13:00 - Your account has been setup! Welcome! 08/Jun/2015 - 13:01 - welcomepack.pdf sent!

luckydonald commented 9 years ago

At least for raw documents (not send_photo) a name should exist in the datastructure. Next time I happen do dig in the code, Ill have a look for that too. I guess there is just no output, even if there is information.

biji commented 8 years ago

same here, no caption received

mmarquezs commented 8 years ago

This would be very nice, because for example I'm doing an script so it downloads the files shared in a channel but unless I'm missing something there isn't a way to download the files with the original name or get the original name so I can rename them after downloading them.

Now I end with lots of documents called for example "download_25245254353453411.pdf" which is pretty much useless to me.

Meanwhile in the telegram app I can see the filename even without downloading it.

bertysoft commented 5 years ago

i'm working with python using port and json I solve by little modification in the json-tg.c

modify the original case tgl_message_media_document: case tgl_message_media_audio: case tgl_message_media_video: case tgl_message_media_document_encr: assert (json_object_set (res, "type", json_string ("document")) >= 0); break;

with

case tgl_message_media_document: case tgl_message_media_audio: case tgl_message_media_video: case tgl_message_media_document_encr: // ORIGINAL // comment the next line With // //assert (json_object_set (res, "type", json_string ("document")) >= 0);

// ----Start modification 

  if (M->document->flags & TGLDF_IMAGE) {
    assert (json_object_set (res, "type",json_string ( "image")) >= 0);
  } else if (M->document->flags & TGLDF_AUDIO) {
    assert (json_object_set (res, "type", json_string ("audio")) >= 0);
  } else if (M->document->flags & TGLDF_VIDEO) {
    assert (json_object_set (res, "type", json_string ("video")) >= 0);
  } else if (M->document->flags & TGLDF_STICKER) {
    assert (json_object_set (res, "type", json_string ("sticker")) >= 0);
  } else {
    assert (json_object_set (res, "type",json_string ( "document")) >= 0);
  }
  if (M->document->caption && strlen (M->document->caption)) {
    assert (json_object_set (res, "filename", json_string (M->document->caption)) >= 0);
  }
  if (M->document->mime_type) {
    assert (json_object_set (res, "mime_type", json_string ( M->document->mime_type)) >= 0);
  }
  if (M->document->w && M->document->h) {
    assert (json_object_set (res, "size_w", json_integer (M->document->w)) >= 0);
    assert (json_object_set (res, "size_h" , json_integer ( M->document->h)) >= 0);
  }
  if (M->document->duration) {
    assert (json_object_set (res, "duration", json_integer ( M->document->duration)) >= 0);
  }
  assert (json_object_set (res, "size", json_integer ( M->document->size)) >= 0);
 /*
  if (M->document->size < (1 << 10)) {
    assert (json_object_set (res, "size_byte",json_integer (M->document->size)) >= 0);
  } else if (M->document->size < (1 << 20)) {
    assert (json_object_set (res, "size_KiB", json_integer ( M->document->size >> 10)) >= 0);
  } else if (M->document->size < (1 << 30)) {
    assert (json_object_set (res, "size_MiB",json_integer ( M->document->size >> 20)) >= 0);
  } else {
    assert (json_object_set (res, "size_GiB", json_integer ( M->document->size >> 30)) >= 0);
  }
  */
// ------End modification

break;

After saving start command make -B

after do you have: type: filename: mime_type size

like example here "media": {"type": "document", "filename": "yourfilename.pdf", "mime_type": "application/pdf", "size": 87967}

I hope was interesting solution