|
47 | 47 | from pyrogram.types import User, TermsOfService |
48 | 48 | from pyrogram.utils import ainput |
49 | 49 | from .dispatcher import Dispatcher |
| 50 | +from .file_id import FileId, FileType, ThumbnailSource |
50 | 51 | from .scaffold import Scaffold |
51 | 52 |
|
52 | 53 | log = logging.getLogger(__name__) |
@@ -493,22 +494,11 @@ async def handle_download(self, packet): |
493 | 494 | final_file_path = "" |
494 | 495 |
|
495 | 496 | try: |
496 | | - data, directory, file_name, progress, progress_args = packet |
| 497 | + file_id, directory, file_name, file_size, progress, progress_args = packet |
497 | 498 |
|
498 | 499 | temp_file_path = await self.get_file( |
499 | | - media_type=data.media_type, |
500 | | - dc_id=data.dc_id, |
501 | | - document_id=data.document_id, |
502 | | - access_hash=data.access_hash, |
503 | | - thumb_size=data.thumb_size, |
504 | | - peer_id=data.peer_id, |
505 | | - peer_type=data.peer_type, |
506 | | - peer_access_hash=data.peer_access_hash, |
507 | | - volume_id=data.volume_id, |
508 | | - local_id=data.local_id, |
509 | | - file_ref=data.file_ref, |
510 | | - file_size=data.file_size, |
511 | | - is_big=data.is_big, |
| 500 | + file_id=file_id, |
| 501 | + file_size=file_size, |
512 | 502 | progress=progress, |
513 | 503 | progress_args=progress_args |
514 | 504 | ) |
@@ -817,22 +807,13 @@ def load_plugins(self): |
817 | 807 |
|
818 | 808 | async def get_file( |
819 | 809 | self, |
820 | | - media_type: int, |
821 | | - dc_id: int, |
822 | | - document_id: int, |
823 | | - access_hash: int, |
824 | | - thumb_size: str, |
825 | | - peer_id: int, |
826 | | - peer_type: str, |
827 | | - peer_access_hash: int, |
828 | | - volume_id: int, |
829 | | - local_id: int, |
830 | | - file_ref: str, |
| 810 | + file_id: FileId, |
831 | 811 | file_size: int, |
832 | | - is_big: bool, |
833 | 812 | progress: callable, |
834 | 813 | progress_args: tuple = () |
835 | 814 | ) -> str: |
| 815 | + dc_id = file_id.dc_id |
| 816 | + |
836 | 817 | async with self.media_sessions_lock: |
837 | 818 | session = self.media_sessions.get(dc_id, None) |
838 | 819 |
|
@@ -874,49 +855,43 @@ async def get_file( |
874 | 855 |
|
875 | 856 | self.media_sessions[dc_id] = session |
876 | 857 |
|
877 | | - file_ref = utils.decode_file_ref(file_ref) |
| 858 | + file_type = file_id.file_type |
878 | 859 |
|
879 | | - if media_type == 1: |
880 | | - if peer_type == "user": |
| 860 | + if file_type == FileType.CHAT_PHOTO: |
| 861 | + if file_id.chat_id > 0: |
881 | 862 | peer = raw.types.InputPeerUser( |
882 | | - user_id=peer_id, |
883 | | - access_hash=peer_access_hash |
884 | | - ) |
885 | | - elif peer_type == "chat": |
886 | | - peer = raw.types.InputPeerChat( |
887 | | - chat_id=peer_id |
| 863 | + user_id=file_id.chat_id, |
| 864 | + access_hash=file_id.chat_access_hash |
888 | 865 | ) |
889 | 866 | else: |
890 | | - peer = raw.types.InputPeerChannel( |
891 | | - channel_id=peer_id, |
892 | | - access_hash=peer_access_hash |
893 | | - ) |
| 867 | + if file_id.chat_access_hash == 0: |
| 868 | + peer = raw.types.InputPeerChat( |
| 869 | + chat_id=file_id.chat_id |
| 870 | + ) |
| 871 | + else: |
| 872 | + peer = raw.types.InputPeerChannel( |
| 873 | + channel_id=file_id.chat_id, |
| 874 | + access_hash=file_id.chat_access_hash |
| 875 | + ) |
894 | 876 |
|
895 | 877 | location = raw.types.InputPeerPhotoFileLocation( |
896 | 878 | peer=peer, |
897 | | - volume_id=volume_id, |
898 | | - local_id=local_id, |
899 | | - big=is_big or None |
| 879 | + volume_id=file_id.volume_id, |
| 880 | + local_id=file_id.local_id, |
| 881 | + big=file_id.thumbnail_source == ThumbnailSource.CHAT_PHOTO_BIG |
900 | 882 | ) |
901 | | - elif media_type in (0, 2): |
| 883 | + elif file_type in (FileType.THUMBNAIL, FileType.PHOTO): |
902 | 884 | location = raw.types.InputPhotoFileLocation( |
903 | | - id=document_id, |
904 | | - access_hash=access_hash, |
905 | | - file_reference=file_ref, |
906 | | - thumb_size=thumb_size |
907 | | - ) |
908 | | - elif media_type == 14: |
909 | | - location = raw.types.InputDocumentFileLocation( |
910 | | - id=document_id, |
911 | | - access_hash=access_hash, |
912 | | - file_reference=file_ref, |
913 | | - thumb_size=thumb_size |
| 885 | + id=file_id.media_id, |
| 886 | + access_hash=file_id.access_hash, |
| 887 | + file_reference=file_id.file_reference, |
| 888 | + thumb_size=file_id.thumbnail_size |
914 | 889 | ) |
915 | 890 | else: |
916 | 891 | location = raw.types.InputDocumentFileLocation( |
917 | | - id=document_id, |
918 | | - access_hash=access_hash, |
919 | | - file_reference=file_ref, |
| 892 | + id=file_id.media_id, |
| 893 | + access_hash=file_id.access_hash, |
| 894 | + file_reference=file_id.file_reference, |
920 | 895 | thumb_size="" |
921 | 896 | ) |
922 | 897 |
|
|
0 commit comments