Reputation: 129
I want to download all photo from channel. Try to use https://github.com/danog/MadelineProto to get channel message history:
$MadelineProto->messages->getHistory([
'peer' => "-100xxxxxx",
'offset_id' => 0,
'offset_date' => 0,
'add_offset' => 0,
'limit' => 25,
'max_id' => 1000,
'min_id' => 0,
'hash' => 1,
]);
As a result I get an array of messages with media:
array(13) {
["_"] => string(7) "message"
["out"] => bool(false)
["mentioned"] => bool(false)
["media_unread"] => bool(false)
["silent"] => bool(false)
["post"] => bool(false)
["id"] => int(38)
["from_id"] => int(500100000)
["to_id"] => array(2) {
["_"] =>string(11) "peerChannel"
["channel_id"] =>int(1369700000)
}
["date"] => int(1520150410)
["message"] => string(0) ""
["media"] => array(2) {
["_"] =>string(17) "messageMediaPhoto"
["photo"] =>array(6) {
["_"] => string(5) "photo"
["has_stickers"] => bool(false)
["id"] => int(5251753100000000000)
["access_hash"] => int(-6118957000000000000)
["date"] => int(1520150405)
["sizes"] => array(4) {
[0] =>array(6) {
["_"] => string(9) "photoSize"
["type"] => string(1) "s"
["location"] => array(5) {
["_"] =>string(12) "fileLocation"
["dc_id"] =>int(2)
["volume_id"] =>int(235100000)
["local_id"] =>int(250000)
["secret"] =>int(5193339136300000000)
}
["w"] => int(90)
["h"] => int(67)
["size"] => int(1078)
}
....
Now I want to download this file and didnt known how do it. Method https://core.telegram.org/bots/api#getfile request file_id but I havent it.
Message history only give me this photo parameters:
How can I get file_id or generate it from available data?
Or how can I download photo from channel history by another way?
Upvotes: 0
Views: 2008
Reputation: 129
MadelineProto has undocumented functions like download_to_file or download_to_dir.
$MadelineProto->download_to_dir($message['media'], $pathtodir)
Upvotes: 1