@@ -216,22 +216,25 @@ def http_to_file(http):
216216 return data_file
217217
218218
219- def parse_media_file (passed_media ):
219+ def parse_media_file (passed_media , async_upload = False ):
220220 """ Parses a media file and attempts to return a file-like object and
221221 information about the media file.
222222
223223 Args:
224224 passed_media: media file which to parse.
225+ async_upload: flag, for validation media file attributes.
225226
226227 Returns:
227228 file-like object, the filename of the media file, the file size, and
228229 the type of media.
229230 """
230231 img_formats = ['image/jpeg' ,
231232 'image/png' ,
232- 'image/gif' ,
233233 'image/bmp' ,
234234 'image/webp' ]
235+ long_img_formats = [
236+ 'image/gif'
237+ ]
235238 video_formats = ['video/mp4' ,
236239 'video/quicktime' ]
237240
@@ -266,9 +269,13 @@ def parse_media_file(passed_media):
266269 if media_type is not None :
267270 if media_type in img_formats and file_size > 5 * 1048576 :
268271 raise TwitterError ({'message' : 'Images must be less than 5MB.' })
269- elif media_type in video_formats and file_size > 15 * 1048576 :
272+ elif media_type in long_img_formats and file_size > 15 * 1048576 :
273+ raise TwitterError ({'message' : 'GIF Image must be less than 15MB.' })
274+ elif media_type in video_formats and not async_upload and file_size > 15 * 1048576 :
270275 raise TwitterError ({'message' : 'Videos must be less than 15MB.' })
271- elif media_type not in img_formats and media_type not in video_formats :
276+ elif media_type in video_formats and async_upload and file_size > 512 * 1048576 :
277+ raise TwitterError ({'message' : 'Videos must be less than 512MB.' })
278+ elif media_type not in img_formats and media_type not in video_formats and media_type not in long_img_formats :
272279 raise TwitterError ({'message' : 'Media type could not be determined.' })
273280
274281 return data_file , filename , file_size , media_type
0 commit comments