|
19 | 19 | """This module contains an object that represents a Telegram File."""
|
20 | 20 | from base64 import b64decode
|
21 | 21 | from os.path import basename
|
| 22 | +import os |
22 | 23 |
|
23 | 24 | from future.backports.urllib import parse as urllib_parse
|
24 | 25 |
|
@@ -76,9 +77,10 @@ def de_json(cls, data, bot):
|
76 | 77 | def download(self, custom_path=None, out=None, timeout=None):
|
77 | 78 | """
|
78 | 79 | Download this file. By default, the file is saved in the current working directory with its
|
79 |
| - original filename as reported by Telegram. If a :attr:`custom_path` is supplied, it will be |
80 |
| - saved to that path instead. If :attr:`out` is defined, the file contents will be saved to |
81 |
| - that object using the ``out.write`` method. |
| 80 | + original filename as reported by Telegram. If the file has no filename, it the file ID will |
| 81 | + be used as filename. If a :attr:`custom_path` is supplied, it will be saved to that path |
| 82 | + instead. If :attr:`out` is defined, the file contents will be saved to that object using |
| 83 | + the ``out.write`` method. |
82 | 84 |
|
83 | 85 | Note:
|
84 | 86 | :attr:`custom_path` and :attr:`out` are mutually exclusive.
|
@@ -116,8 +118,10 @@ def download(self, custom_path=None, out=None, timeout=None):
|
116 | 118 | else:
|
117 | 119 | if custom_path:
|
118 | 120 | filename = custom_path
|
119 |
| - else: |
| 121 | + elif self.file_path: |
120 | 122 | filename = basename(self.file_path)
|
| 123 | + else: |
| 124 | + filename = os.path.join(os.getcwd(), self.file_id) |
121 | 125 |
|
122 | 126 | buf = self.bot.request.retrieve(url, timeout=timeout)
|
123 | 127 | if self._credentials:
|
|
0 commit comments