Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/mkdocs-minify-plugin-0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
adw0rd authored Jan 31, 2023
2 parents 19163d5 + 27110ff commit 4711515
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 17 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Features:

Fast and effective Instagram Private API wrapper (public+private requests and challenge resolver) without selenium. Use the most recent version of the API from Instagram, which was obtained using [reverse-engineering with Charles Proxy](https://adw0rd.com/2020/03/26/sniffing-instagram-charles-proxy/en/) and [Proxyman](https://proxyman.io/).

*Instagram API valid for **3 January 2022** (last reverse-engineering check)*
*Instagram API valid for **21 December 2022** (last reverse-engineering check)*

Support **Python >= 3.8**
Support **Python >= 3.9**

For any other languages (e.g. C++, C#, F#, D, [Golang](https://github.com/adw0rd/instagrapi-rest/tree/main/golang), Erlang, Elixir, Nim, Haskell, Lisp, Closure, Julia, R, Java, Kotlin, Scala, OCaml, JavaScript, Crystal, Ruby, Rust, [Swift](https://github.com/adw0rd/instagrapi-rest/tree/main/swift), Objective-C, Visual Basic, .NET, Pascal, Perl, Lua, PHP and others), I suggest using [instagrapi-rest](https://github.com/adw0rd/instagrapi-rest) or [Lamadava SaaS](https://lamadava.com)

Expand Down Expand Up @@ -130,3 +130,10 @@ cl.video_upload_to_story(
* [Handle Exceptions](https://adw0rd.github.io/instagrapi/usage-guide/handle_exception.html)
* [Challenge Resolver](https://adw0rd.github.io/instagrapi/usage-guide/challenge_resolver.html)
* [Exceptions](https://adw0rd.github.io/instagrapi/exceptions.html)

## PyPI

To release, you need to call the following commands:

python setup.py sdist
twine upload dist/*
2 changes: 1 addition & 1 deletion docker/devbox.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.0-buster
FROM python:3.11.1-buster

ARG _USER="instagrapi"
ARG _UID="1001"
Expand Down
27 changes: 24 additions & 3 deletions instagrapi/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Account,
Collection,
Comment,
ReplyMessage,
DirectMedia,
DirectMessage,
DirectResponse,
Expand Down Expand Up @@ -187,9 +188,9 @@ def extract_user_gql(data):
def extract_user_v1(data):
"""For Private API"""
data["external_url"] = data.get("external_url") or None
pic_hd = data.get("hd_profile_pic_url_info") or data.get("hd_profile_pic_versions")
if pic_hd:
data["profile_pic_url_hd"] = pic_hd.get("url")
versions = data.get("hd_profile_pic_versions")
pic_hd = versions[-1] if versions else data.get("hd_profile_pic_url_info", {})
data["profile_pic_url_hd"] = pic_hd.get("url")
return User(**data)


Expand Down Expand Up @@ -267,8 +268,28 @@ def extract_direct_response(data):
return DirectResponse(**data)


def extract_reply_message(data):
data["id"] = data.get("item_id")
if "media_share" in data:
ms = data["media_share"]
if not ms.get("code"):
ms["code"] = InstagramIdCodec.encode(ms["id"])
data["media_share"] = extract_media_v1(ms)
if "media" in data:
data["media"] = extract_direct_media(data["media"])
clip = data.get("clip", {})
if clip:
if "clip" in clip:
# Instagram ¯\_(ツ)_/¯
clip = clip.get("clip")
data["clip"] = extract_media_v1(clip)
return ReplyMessage(**data)


def extract_direct_message(data):
data["id"] = data.get("item_id")
if "replied_to_message" in data:
data["reply"] = extract_reply_message(data["replied_to_message"])
if "media_share" in data:
ms = data["media_share"]
if not ms.get("code"):
Expand Down
6 changes: 3 additions & 3 deletions instagrapi/mixins/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PrivateRequestMixin:
handle_exception = None
challenge_code_handler = manual_input_code
change_password_handler = manual_change_password
request_logger = logging.getLogger("private_request")
private_request_logger = logging.getLogger("private_request")
request_timeout = 1
last_response = None
last_json = {}
Expand Down Expand Up @@ -370,7 +370,7 @@ def _send_private_request(
raise ClientThrottledError(e, response=e.response, **last_json)
elif e.response.status_code == 404:
self.logger.warning(
"Status 404: Endpoint %s does not exists", endpoint)
"Status 404: Endpoint %s does not exist", endpoint)
raise ClientNotFoundError(e, response=e.response, **last_json)
elif e.response.status_code == 408:
self.logger.warning("Status 408: Request Timeout")
Expand All @@ -395,7 +395,7 @@ def _send_private_request(
return last_json

def request_log(self, response):
self.request_logger.info(
self.private_request_logger.info(
"%s [%s] %s %s (%s)",
self.username,
response.status_code,
Expand Down
8 changes: 4 additions & 4 deletions instagrapi/mixins/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PublicRequestMixin:
GRAPHQL_PUBLIC_API_URL = "https://www.instagram.com/graphql/query/"
last_public_response = None
last_public_json = {}
request_logger = logging.getLogger("public_request")
public_request_logger = logging.getLogger("public_request")
request_timeout = 1

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -115,11 +115,11 @@ def _send_public_request(
response=response,
)

self.request_logger.debug(
self.public_request_logger.debug(
"public_request %s: %s", response.status_code, response.url
)

self.request_logger.info(
self.public_request_logger.info(
"[%s] [%s] %s %s",
self.public.proxies.get("https"),
response.status_code,
Expand All @@ -137,7 +137,7 @@ def _send_public_request(
if "/login/" in response.url:
raise ClientLoginRequired(e, response=response)

self.request_logger.error(
self.public_request_logger.error(
"Status %s: JSONDecodeError in public_request (url=%s) >>> %s",
response.status_code,
response.url,
Expand Down
22 changes: 22 additions & 0 deletions instagrapi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,37 @@ class DirectMedia(BaseModel):
video_url: Optional[HttpUrl]


class ReplyMessage(BaseModel):
id: str
user_id: Optional[int]
timestamp: datetime
item_type: Optional[str]
is_sent_by_viewer: Optional[bool]
is_shh_mode: Optional[bool]
text: Optional[str]
link: Optional[dict]
animated_media: Optional[dict]
media: Optional[DirectMedia]
visual_media: Optional[dict]
media_share: Optional[Media]
reel_share: Optional[dict]
story_share: Optional[dict]
felix_share: Optional[dict]
clip: Optional[Media]
placeholder: Optional[dict]


class DirectMessage(BaseModel):
id: str # e.g. 28597946203914980615241927545176064
user_id: Optional[int]
thread_id: Optional[int] # e.g. 340282366841710300949128531777654287254
timestamp: datetime
item_type: Optional[str]
is_sent_by_viewer: Optional[bool]
is_shh_mode: Optional[bool]
reactions: Optional[dict]
text: Optional[str]
reply: Optional[ReplyMessage]
link: Optional[dict]
animated_media: Optional[dict]
media: Optional[DirectMedia]
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ isort==5.10.1
bandit==1.7.4
mike==1.1.2
markdown-include==0.7.0
mkdocs-material==8.5.10
mkdocs-material==9.0.8
mkdocs-minify-plugin==0.6.2
mkdocstrings==0.19.0
./util/mkdocs-redirects
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ requests==2.28.1
PySocks==1.7.1
pydantic==1.10.2
moviepy==1.0.3
pycryptodomex==3.15.0
pycryptodomex==3.17
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'requests<3.0,>=2.25.1',
'PySocks==1.7.1',
'pydantic==1.10.2',
'pycryptodomex==3.15.0'
'pycryptodomex==3.17'
]
# requirements = [
# line.strip()
Expand All @@ -30,7 +30,7 @@

setup(
name='instagrapi',
version='1.16.30',
version='1.16.31',
author='Mikhail Andreev',
author_email='[email protected]',
license='MIT',
Expand Down

0 comments on commit 4711515

Please sign in to comment.