Repository: python-telegram-bot/python-telegram-bot

Issue:
[BUG] InputMediaVideo dosen't upload thumb image
<!--
Thanks for reporting issues of python-telegram-bot!

Use this template to notify us if you found a bug.

To make it easier for us to help you please enter detailed information below.

Please note, we only support the latest version of python-telegram-bot and
master branch. Please make sure to upgrade & recreate the issue on the latest
version prior to opening an issue.
-->
### Steps to reproduce
send a video with `send_media_group` including one `input_media_video` with a local video and local thumb image passed as `open('path','rb')`.
thumb image width is less than 320px and size is about 40kb.

### Expected behaviour
video sent with image as thumb.

### Actual behaviour
video sent with no thumb (white background).

note 1: the video sent properly with `send_video` function and the same thumb.
note 2: video size should be more than 10-11mb so telegram use the passed thumb image, instead of it's own generated thumb.
note 3: you can use `edit_message_media` instead of `send_media_group`. this problem is related to `input_media_video`, so any function which has this, is effected.

### Configuration
**Operating System:**
Ubuntu 18.04

**Version of Python, python-telegram-bot & dependencies:**
```
python-telegram-bot 12.3.0
certifi 2019.11.28
future 0.18.2
Python 3.6.8 (default, Jan 14 2019, 11:02:34)  [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
```

### Logs
no logs.



Discussion:
Hey, btw: We discussed your case internally. Right now, we think its rather a telegram/telegram client issue then one with the library. We need to test this though, which is why no one has replied here yet.
Hey, its me again. After taking way too long to recreate this using only requests, I can now safely say that this is an issue with our library, not with telegrams API. Thanks for bringing this bug to our attention, we uhm, shall start fixing it.

Resolving patch:
diff --git a/telegram/utils/request.py b/telegram/utils/request.py
--- a/telegram/utils/request.py
+++ b/telegram/utils/request.py
@@ -317,9 +317,13 @@ def post(self, url, data, timeout=None):
                     # Attach and set val to attached name for all
                     media = []
                     for m in val:
-                        media.append(m.to_dict())
+                        media_dict = m.to_dict()
+                        media.append(media_dict)
                         if isinstance(m.media, InputFile):
                             data[m.media.attach] = m.media.field_tuple
+                            # if the file has a thumb, we also need to attach it to the data
+                            if "thumb" in media_dict:
+                                data[m.thumb.attach] = m.thumb.field_tuple
                     data[key] = json.dumps(media)
                 files = True
 


Test patch:
diff --git a/tests/test_inputmedia.py b/tests/test_inputmedia.py
--- a/tests/test_inputmedia.py
+++ b/tests/test_inputmedia.py
@@ -317,6 +317,20 @@ def test_send_media_group_all_args(self, bot, chat_id, media_group):
         assert all([isinstance(mes, Message) for mes in messages])
         assert all([mes.media_group_id == messages[0].media_group_id for mes in messages])
 
+    def test_send_media_group_with_thumbs(self, bot, chat_id, video_file, photo_file,  # noqa: F811
+                                          monkeypatch):
+        def test(*args, **kwargs):
+            data = kwargs['fields']
+            video_check = data[input_video.media.attach] == input_video.media.field_tuple
+            thumb_check = data[input_video.thumb.attach] == input_video.thumb.field_tuple
+            result = video_check and thumb_check
+            raise(Exception('Test was {}'.format('successful' if result else 'failing')))
+
+        monkeypatch.setattr('telegram.utils.request.Request._request_wrapper', test)
+        input_video = InputMediaVideo(video_file, thumb=photo_file)
+        with pytest.raises(Exception, match='Test was successful'):
+            bot.send_media_group(chat_id, [input_video, input_video])
+
     @flaky(3, 1)  # noqa: F811
     @pytest.mark.timeout(10)  # noqa: F811
     def test_send_media_group_new_files(self, bot, chat_id, video_file, photo_file,  # noqa: F811