subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.22k stars 667 forks source link

Handling of "raven_media" direct message #675

Open ghrlt opened 2 years ago

ghrlt commented 2 years ago

basically title

"raven_media" are both one view direct photo / two view direct photo

will try to do myself and pr

ghrlt commented 2 years ago

I am not successful in sniffing instagram with physical devices (6> & 6<), with any methods found, even though its working for any other apps

Will have to work on emulator, so, later

ghrlt commented 2 years ago

Okay so, this is what API return

{
  "item_type": "raven_media",
  "visual_media": {
    "media": {
      "id": "17867648009711100",
      "image_versions2": {
        "candidates": [
          {
            "width": 1080,
            "height": 1920,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?_nc_cat=100&ccb=1-7&_nc_sid=d0e35b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARq6McGaYyNLNVuFaw10JbVr9swb9sipqLAdpi6DfnsaQQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              10418,
              20836,
              31255,
              41673,
              52091,
              62874,
              76115,
              84767,
              93765
            ]
          },
          {
            "width": 1080,
            "height": 1920,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARq6McGaYyNLNVuFaw10JbVr9swb9sipqLAdpi6DfnsaQQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              10418,
              20836,
              31255,
              41673,
              52091,
              62874,
              76115,
              84767,
              93765
            ]
          },
          {
            "width": 640,
            "height": 1138,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_p640x640&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARrHr8C_rzpedti9b-Oh79eCeysZXNQnJNbIP7HxFy71jQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              7581,
              15163,
              22745,
              30327,
              37909,
              45756,
              55392,
              61688,
              68237
            ]
          },
          {
            "width": 480,
            "height": 853,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_p480x480&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARpT_ip2gnxsO_ChDbyhu_dRXMeeWZpqIbkrCzlP7ZI3-w&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              5077,
              10155,
              15233,
              20311,
              25388,
              31693,
              409325,
              45700,
              45700
            ]
          },
          {
            "width": 360,
            "height": 640,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_s640x640&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARrH3UaQFp4_CA0YlJ2oOe-65VT_3PMRKNMQjOpCHd2ymQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              3335,
              6670,
              10006,
              13341,
              16677,
              20818,
              268879,
              30019,
              30019
            ]
          },
          {
            "width": 350,
            "height": 622,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_p350x350&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARqqc1PxhJ9g7xkukdqLeBcz0w7quOGDJYl07es0hXE1zw&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              3200,
              6400,
              9600,
              12800,
              16000,
              19973,
              257964,
              28801,
              28801
            ]
          },
          {
            "width": 270,
            "height": 480,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_s480x480&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARqDoIz-cgIJ2BI8pNvyvUYG_jvDGxE7TJL2TmsCKmmeUQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              2190,
              4380,
              6571,
              8761,
              10951,
              13671,
              176571,
              19713,
              19713
            ]
          },
          {
            "width": 206,
            "height": 366,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_p206x206&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARrzfrH9RQ3_UZH7M3rbDUfF0d-s6LlqsuWLdSbTYT6mag&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              1474,
              2948,
              4422,
              5896,
              7371,
              9201,
              118842,
              13268,
              13268
            ]
          },
          {
            "width": 180,
            "height": 320,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_s180x540&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARqvof9JoCIXwX4Dx1lC5GzkYHejjHHImMS6QbzFWFGNUQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              1210,
              2421,
              3632,
              4843,
              6054,
              7558,
              97613,
              10898,
              10898
            ]
          },
          {
            "width": 135,
            "height": 240,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_s240x240&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARrYphjZeKtwgr-b9VVa5CFjDvUlb0z-lRoShfwXjchLcg&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              795,
              1590,
              2385,
              3180,
              3975,
              4963,
              64102,
              7156,
              7156
            ]
          },
          {
            "width": 110,
            "height": 196,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_p110x80&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARoyH2LLtGyubGN7i683JxpLq8ZlF6ItCVXAMbRs504ITg&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              590,
              1180,
              1771,
              2361,
              2952,
              3685,
              47597,
              5314,
              5314
            ]
          },
          {
            "width": 90,
            "height": 160,
            "url": "https://video.cdninstagram.com/v/t69.10827-2/283706442_1202737480268965_7979101142966183712_n.webp?stp=dst-webp_s160x160&_nc_cat=100&ccb=1-7&_nc_sid=5a057b&_nc_ohc=n-0Elj0YkQgAX9w21u0&_nc_ht=video.cdninstagram.com&oh=02_ARrEh_eBuleF6C2lFG6u6zZj-pY_4WM7WCS0wUTooZSEyQ&oe=628BCFE1",
            "fallback": {
              "url": "https://i.instagram.com/api/v1/direct_v2/media_fallback/?entity_id=5248846021805350&entity_type=25"
            },
            "url_expiration_timestamp_us": 1653329889000000,
            "scans_profile": "e35",
            "estimated_scans_sizes": [
              439,
              879,
              1318,
              1758,
              2197,
              2743,
              35437,
              3956,
              3956
            ]
          }
        ]
      },
      "original_height": 1920,
      "original_width": 1080,
      "media_type": 1,
      "media_id": 17867648009711100,
      "organic_tracking_token": "eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjkzN2Q0YWEyZTcxMTRiZmM4ZTM3NTg1MDVjNmIzYjEyMTc4Njc2NDgwMDk3MTExMDAiLCJzZXJ2ZXJfdG9rZW4iOiIxNjUzMjIyODU0MTgxfDE3ODY3NjQ4MDA5NzExMTAwfDM3NzIzMDQxMDA4fDk0NTAzYTk0M2FlMzgwYzdkMWNhMjJlYjVjN2JmNzUwYjQxMDA1ODZjMWViYmM0Nzk1YjM0ZmRiOTBkZDcxZGEifSwic2lnbmF0dXJlIjoiIn0=",
      "user": {
        "pk": 44404267539,
        "username": "gahrlt",
        "full_name": "Gaëtan 🌍🐼",
        "profile_pic_url": "https://scontent.cdninstagram.com/v/t51.2885-15/281571086_743094373363926_3874981299375825928_n.jpg?stp=dst-jpg_s200x200&_nc_cat=104&ccb=1-7&_nc_sid=8ae9d6&_nc_ohc=7hukxT6S2vQAX8yaNRT&_nc_ad=z-m&_nc_cid=0&_nc_ht=scontent.cdninstagram.com&oh=00_AT9jxzaotVvZel00u3MEqqTqqM9CGRzKJkv6iGvXNp2DiQ&oe=628B8E10",
        "interop_user_type": 0,
        "interop_messaging_user_fbid": 17842015241483540,
        "friendship_status": {

        },
        "short_name": None
      },
      "expiring_media_action_summary": None,
      "creative_config": None,
      "create_mode_attribution": None
    },
    "url_expire_at_secs": 1653329889,
    "seen_user_ids": [

    ],
    "view_mode": "replayable",
    "seen_count": 0,
    "replay_expiring_at_us": None,
    "playback_duration_secs": 5,
    "reply_type": None,
    "tap_models": [

    ],
    "expiring_media_action_summary": None,
    "story_app_attribution": None
  },
  "client_context": "6934119171462951866",
  "is_sent_by_viewer": False,
  "is_shh_mode": False,
  "item_id": "30496578709405145717164749715668992",
  "show_forward_attribution": False,
  "timestamp": 1653222844505612,
  "user_id": 44404267539,
  "tq_seq_id": 447,
  "uq_seq_id": 120746,
  "thread_id": "340282366841710300949128184464324806925"
}

TBH, I'm not sure how to implement it other than just adding the whole json to a visual_media attribute of the DirectMessage class, so I'm not going to make a PR

ghrlt commented 2 years ago

I'm unable to mark the message as read, like, I can mark the whole thread as read, but even though I downloaded the media 10 times, it is still marked as unread.

I tried to make a request to the fallback url, but all I got was this

>>> r = cl.private.request(
>>>     "GET",
>>>     msg.visual_media['media']['image_versions2']['candidates'][0]['fallback']['url']
>>> )
>>> print(r, r.content)
<Response [400]> b'{"message":"can\'t load media","status":"fail"}'

and Response 405 for OPTIONS or POST requests

hittiks commented 2 years ago

Ru: Столкнулся с подобной проблемой. Нужно вытягивать фото/видео, которые собеседник отправляет с одноразовым или двухразовым просмотром. Но, к сожалению, данные об этих медиа не собираются с помощью Instagrapi, а лишь отмечаются, как "raven_media"

En: Faced a similar problem. I need to pull out the photos/videos that the companion sends with a one-time or two-time view. But, unfortunately, data about these media is not collected using Instagrapi, it is only marked as "raven_media"

ghrlt commented 2 years ago

Check my edit, pending a general modification

https://github.com/ghrlt/instagrapi/commit/512bee8581aa88f4228f9656720f5f089384174f

But you will still face my problem of not being able to mark it as read (which, in a way, is nice -> able to see media forever)

adw0rd commented 2 years ago

@ghrlt will you send me PR?

ghrlt commented 2 years ago

I would have liked to have a fully functional edit before making a PR.

What's missing is:

hittiks commented 2 years ago

Thanks, that's exactly what I needed (not being able to mark it as read and able to see media forever)