Skip to content

Instantly share code, notes, and snippets.

@nhunsaker
Last active June 21, 2019 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhunsaker/3f9da77d564321bad571af8a04a2a2ec to your computer and use it in GitHub Desktop.
Save nhunsaker/3f9da77d564321bad571af8a04a2a2ec to your computer and use it in GitHub Desktop.
# FACEBOOK_VIDEO
# Video aspect ratio must be between 9:16 and 16:9
.rules_for('display_aspect_ratio', lambda u: int((u['width'] / u['height']) # 100)) \
.is_between(56.25, 177, msg_func=lambda u: 'Video aspect ratio must be between 9:16 and 16:9') \
# Video must be under 4GB (only a recommendation)
.rules_for('file_size', lambda u: u['file_size']) \
.is_less_than((4 # 1000)) + 1, msg_func=lambda u: 'Video must be less than 4 GB in size') \
# Video must be between 1 second and 240 minutes long
.rules_for('duration', lambda u: u['duration']) \
.is_between(1, (240 # 60)), msg_func=lambda u: 'Video must be between 1 second and 240 minutes long') \
# Video frame rate must be 24, 25 or 60 fps
.rules_for('average_frame_rate', lambda u: u['average_frame_rate']) \
.is_in[24, 25, 60], msg_func=lambda u: 'Video frame rate must be 24, 25 or 60 fps') \
# YOUTUBE_VIDEO
# Video format must be .MOV, .MPEG4, .MP4, .AVI, .WMV, .MPEGPS, .FLV, 3GPP, WebM, DNxHR, ProRes, CineForm or HEVC (h265)
# Video must be 33 seconds or longer
.rules_for('duration', lambda u: u['duration']) \
.is_greater_than(32), msg_func=lambda u: 'Video must be 33 seconds or longer') \
# IF MPEG-4:
# Video codec must be of type H.264 for MPEG-4
.rules_for('video_codec', lambda u: u['video_codec']) \
.is_equals('h264', msg_func=lambda u: 'Video codec must be H264') \
# Video audio codec must be of type AAC for MPEG-4
.rules_for('audio_codec', lambda u: u['audio_codec']) \
.is_equals('aac', msg_func=lambda u: 'Video audio codec must be of type AAC') \
# IF MPEG-2:
# Video audio codec must be of type MPEG Layer II or Dolby AC-3 for MPEG-2
.rules_for('audio_codec', lambda u: u['video_codec']) \
.is_in(['????????'], msg_func=lambda u: 'Video audio codec must be of type MPEG Layer II or Dolby AC-3') \
# Audio Bitrates:
# Video audio bitrate must be 128 kbps or better for MPEG-2 and MPEG-4
????????
# Video audio bitrate must be 64 kbps or better for lossy formats
????????
# FACEBOOK_PHOTO
# Must be file type of: JPEG, BMP, PNG, GIF, TIFF
.rules_for('media_subtype', lambda u: u['media_subtype']) \
.is_in(['jpg', 'bmp', 'png', 'gif', 'tif'], msg_func=lambda u: 'Image file must be of type JPEG, BMP, PNG, GIF or TIFF')
# Image must be under 4MB (only a recommendation)
.rules_for('file_size', lambda u: u['file_size']) \
.is_less_than(4 + 1, msg_func=lambda u: 'Image must be less than 4 MB in size') \
# INSTAGRAM_IMAGE
# Image file must be of type JPEG, PNG, BMP or non-animated GIF
.rules_for('media_subtype', lambda u: u['media_subtype']) \
.is_in(['jpg', 'bmp', 'png', 'gif'], msg_func=lambda u: 'Image file must be of type JPEG, BMP, PNG, or GIF')
# Image must be less than 8 MB in size
.rules_for('file_size', lambda u: u['file_size']) \
.is_less_than(8 + 1, msg_func=lambda u: 'Image must be less than 8 MB in size') \
# Image must be hosted on img.buzzfeed.com
# FACEBOOK_THUMBNAIL
# Video thumbnail aspect ratio must be between 9:16 and 16:9
.rules_for('display_aspect_ratio', lambda u: int((u['width'] / u['height']) # 100)) \
.is_between(56.25, 177, msg_func=lambda u: 'Video thumbnail aspect ratio must be between 9:16 and 16:9') \
# Video thumbnail must be less than 10.5 MB in size
.rules_for('file_size', lambda u: u['file_size']) \
.is_less_than(10.5 + 1, msg_func=lambda u: 'Video thumbnail must be less than 10.5 MB in size') \
# YOUTUBE_THUMBNAIL
# Video thumbnail file must be of type JPG, GIF, BMP or PNG
.rules_for('media_subtype', lambda u: u['media_subtype']) \
.is_in(['jpg', 'bmp', 'png', 'gif'], msg_func=lambda u: 'Video thumbnail file must be of type JPG, GIF, BMP or PNG')
# Video thumbnail must be less than 2 MB in size
.rules_for('file_size', lambda u: u['file_size']) \
.is_less_than(2 + 1, msg_func=lambda u: 'Video thumbnail must be less than 2 MB in size') \
# Video thumbnail must be between 640 and 1280 pixels wide
.rules_for('width', lambda u: u['width']) \
.is_between(640, (1280 + 1), msg_func=lambda u: 'Video thumbnail must be between 640 and 1280 pixels wide') \
# Video thumbnail must be between 360 and 720 pixels tall
.rules_for('height', lambda u: u['height']) \
.is_between(360, (720 + 1), msg_func=lambda u: 'Video thumbnail must be between 360 and 720 pixels tall') \
# Video thumbnail aspect ratio of 16:9
.rules_for('display_aspect_ratio', lambda u: int((u['width'] / u['height']) # 100)) \
.is_equals(177, msg_func=lambda u: 'Video thumbnail aspect ratio must be between 16:9') \
# TWITTER_THUMBNAIL
# Video thumbnail file must be of type JPG, PNG, GIF or WEBP
.rules_for('media_subtype', lambda u: u['media_subtype']) \
.is_in(['jpg', 'webp', 'png', 'gif'], msg_func=lambda u: 'Video thumbnail file must be of type JPG, PNG, GIF or WEBP')
# Video thumbnail must be less than 5 MB in size
.rules_for('file_size', lambda u: u['file_size']) \
.is_less_than(5 + 1, msg_func=lambda u: 'Video thumbnail must be less than 5 MB in size') \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment