Merge branch 'master' into docs
This commit is contained in:
commit
d4c34a1a15
@ -79,13 +79,13 @@ Installation
|
||||
|
||||
.. code:: shell
|
||||
|
||||
$ pip install --upgrade pyrogram
|
||||
$ pip3 install --upgrade pyrogram
|
||||
|
||||
- Or, with TgCrypto_:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
$ pip install --upgrade pyrogram[tgcrypto]
|
||||
$ pip3 install --upgrade pyrogram[tgcrypto]
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
@ -160,9 +160,7 @@ License
|
||||
|
||||
.. _`Layer 75`: compiler/api/source/main_api.tl
|
||||
|
||||
.. _`your own`: https://github.com/pyrogram/pyrogram/wiki/Getting-Started#api-keys
|
||||
|
||||
.. _`Introduction`: https://github.com/pyrogram/pyrogram/wiki/Getting-Started
|
||||
.. _`your own`: https://docs.pyrogram.ml/start/ProjectSetup/#api-keys
|
||||
|
||||
.. _`Telegram`: https://t.me/haskell
|
||||
|
||||
|
@ -337,13 +337,17 @@ class Client:
|
||||
size=document.size,
|
||||
progress=progress
|
||||
)
|
||||
elif isinstance(media, types.MessageMediaPhoto):
|
||||
photo = media.photo
|
||||
elif isinstance(media, (types.MessageMediaPhoto, types.Photo)):
|
||||
if isinstance(media, types.MessageMediaPhoto):
|
||||
photo = media.photo
|
||||
else:
|
||||
photo = media
|
||||
|
||||
if isinstance(photo, types.Photo):
|
||||
if not file_name:
|
||||
file_name = "photo_{}.jpg".format(
|
||||
datetime.fromtimestamp(photo.date).strftime("%Y-%m-%d_%H-%M-%S")
|
||||
file_name = "photo_{}_{}.jpg".format(
|
||||
datetime.fromtimestamp(photo.date).strftime("%Y-%m-%d_%H-%M-%S"),
|
||||
self.rnd_id()
|
||||
)
|
||||
|
||||
photo_loc = photo.sizes[-1].location
|
||||
@ -2587,11 +2591,15 @@ class Client:
|
||||
Raises:
|
||||
:class:`pyrogram.Error`
|
||||
"""
|
||||
if isinstance(message, types.Message):
|
||||
if isinstance(message, (types.Message, types.Photo)):
|
||||
done = Event()
|
||||
media = message.media
|
||||
path = [None]
|
||||
|
||||
if isinstance(message, types.Message):
|
||||
media = message.media
|
||||
else:
|
||||
media = message
|
||||
|
||||
if media is not None:
|
||||
self.download_queue.put((media, file_name, done, progress, path))
|
||||
else:
|
||||
@ -2602,6 +2610,48 @@ class Client:
|
||||
|
||||
return path[0]
|
||||
|
||||
def download_photo(self,
|
||||
photo: types.Photo or types.UserProfilePhoto or types.ChatPhoto,
|
||||
file_name: str = None,
|
||||
block: bool = True):
|
||||
"""Use this method to download a photo not contained inside a Message.
|
||||
For example, a photo of a User or a Chat/Channel.
|
||||
|
||||
Photos are saved in the *downloads* folder.
|
||||
|
||||
Args:
|
||||
photo (:obj:`Photo <pyrogram.api.types.Photo>` | :obj:`UserProfilePhoto <pyrogram.api.types.UserProfilePhoto>` | :obj:`ChatPhoto <pyrogram.api.types.ChatPhoto>`):
|
||||
The photo object.
|
||||
|
||||
file_name (:obj:`str`, optional):
|
||||
Specify a custom *file_name* to be used.
|
||||
|
||||
block (:obj:`bool`, optional):
|
||||
Blocks the code execution until the photo has been downloaded.
|
||||
Defaults to True.
|
||||
|
||||
Returns:
|
||||
The relative path of the downloaded photo.
|
||||
|
||||
Raises:
|
||||
:class:`pyrogram.Error`
|
||||
"""
|
||||
if isinstance(photo, (types.UserProfilePhoto, types.ChatPhoto)):
|
||||
photo = types.Photo(
|
||||
id=0,
|
||||
access_hash=0,
|
||||
date=int(time.time()),
|
||||
sizes=[types.PhotoSize(
|
||||
type="",
|
||||
location=photo.photo_big,
|
||||
w=0,
|
||||
h=0,
|
||||
size=0
|
||||
)]
|
||||
)
|
||||
|
||||
return self.download_media(photo, file_name, block)
|
||||
|
||||
def add_contacts(self, contacts: list):
|
||||
"""Use this method to add contacts to your Telegram address book.
|
||||
|
||||
|
@ -61,7 +61,7 @@ class Session:
|
||||
|
||||
INITIAL_SALT = 0x616e67656c696361
|
||||
NET_WORKERS = 1
|
||||
WAIT_TIMEOUT = 10
|
||||
WAIT_TIMEOUT = 30
|
||||
MAX_RETRIES = 5
|
||||
ACKS_THRESHOLD = 8
|
||||
PING_INTERVAL = 5
|
||||
|
21
setup.py
21
setup.py
@ -42,12 +42,12 @@ setup(
|
||||
name="Pyrogram",
|
||||
version=version,
|
||||
description="Telegram MTProto API Client Library for Python",
|
||||
url="https://github.com/pyrogram/pyrogram",
|
||||
long_description=readme,
|
||||
url="https://github.com/pyrogram",
|
||||
download_url="https://github.com/pyrogram/pyrogram/releases/latest",
|
||||
author="Dan Tès",
|
||||
author_email="admin@pyrogram.ml",
|
||||
license="LGPLv3+",
|
||||
keywords="telegram mtproto api client library python",
|
||||
long_description=readme,
|
||||
classifiers=[
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
@ -59,11 +59,24 @@ setup(
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: Implementation",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
"Topic :: Internet",
|
||||
"Topic :: Communications",
|
||||
"Topic :: Communications :: Chat",
|
||||
"Topic :: Software Development :: Libraries",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules"
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
"Topic :: Software Development :: Libraries :: Application Frameworks"
|
||||
],
|
||||
keywords="telegram mtproto api client library python",
|
||||
project_urls={
|
||||
"Tracker": "https://github.com/pyrogram/pyrogram/issues",
|
||||
"Community": "https://t.me/PyrogramChat",
|
||||
"Source": "https://github.com/pyrogram/pyrogram",
|
||||
"Documentation": "https://docs.pyrogram.ml",
|
||||
},
|
||||
python_requires="~=3.3",
|
||||
packages=find_packages(),
|
||||
zip_safe=False,
|
||||
install_requires=[
|
||||
|
Loading…
Reference in New Issue
Block a user