From eb789cdc98ffa22b4918904c6622330ac2af3a29 Mon Sep 17 00:00:00 2001 From: Garland Trice Date: Wed, 21 Mar 2018 01:40:30 -0700 Subject: [PATCH 1/2] add media category hacking thru this gif thing for now. It takes more than 5mb --- twitter/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitter/api.py b/twitter/api.py index f0541b85..47a8709d 100644 --- a/twitter/api.py +++ b/twitter/api.py @@ -1262,7 +1262,7 @@ def _UploadMediaChunkedInit(self, """ url = '%s/media/upload.json' % self.upload_url - media_fp, filename, file_size, media_type = parse_media_file(media) + media_fp, filename, file_size, media_type = parse_media_file(media, media_category) if not all([media_fp, filename, file_size, media_type]): raise TwitterError({'message': 'Could not process media file'}) From 7dd2ff50676cfd977abbde18b2b349c474d35c6b Mon Sep 17 00:00:00 2001 From: Garland Trice Date: Wed, 21 Mar 2018 01:45:05 -0700 Subject: [PATCH 2/2] media category fix 2 doing this from github ui. bad thing to do, don't do this. --- twitter/twitter_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/twitter/twitter_utils.py b/twitter/twitter_utils.py index e68804cc..7ebc5d23 100644 --- a/twitter/twitter_utils.py +++ b/twitter/twitter_utils.py @@ -216,7 +216,7 @@ def http_to_file(http): return data_file -def parse_media_file(passed_media): +def parse_media_file(passed_media, media_category=None): """ Parses a media file and attempts to return a file-like object and information about the media file. @@ -265,7 +265,8 @@ def parse_media_file(passed_media): media_type = mimetypes.guess_type(os.path.basename(filename))[0] if media_type is not None: if media_type in img_formats and file_size > 5 * 1048576: - raise TwitterError({'message': 'Images must be less than 5MB.'}) + if media_category is not 'tweet_gif': + raise TwitterError({'message': 'Images must be less than 5MB.'}) elif media_type in video_formats and file_size > 15 * 1048576: raise TwitterError({'message': 'Videos must be less than 15MB.'}) elif media_type not in img_formats and media_type not in video_formats: