def analyze(self) -> bool: """Analyze an imgur gif and determine how to reverse and upload""" if not self.pic: return False # pprint(self.pic) if not self.pic['animated']: print("Not a gif!") return False r = requests.get(self.pic['mp4']) file = BytesIO(r.content) self.duration = get_duration(file) self.files.append(GifFile(file, host=self.host, gif_type=consts.MP4, duration=self.duration, size=self.pic['mp4_size']/1000000)) # If the file type is a gif, add it as an option and prioritize it if self.pic['type'] == 'image/gif': r = requests.get(self.pic['gifv'][:-1]) gif = BytesIO(r.content) if is_valid(gif): gif_file = GifFile(gif, host=self.host, gif_type=consts.GIF, duration=self.duration) # else: # gif_file = GifFile(file, host=self.host, gif_type=consts.GIF, duration=self.duration) print("added gif file") self.files.insert(0, gif_file) print(self.files) return True
def __init__(self, file, id, host=None, video_type=None, size=None, duration=None, frames=0, audio=None): self.file = file self.id = id self.file.seek(0) self.type = video_type self.size = None self.frames = frames # Make unified metadata grabber function if audio is None: self.audio = has_audio(self.file) else: self.audio = audio if video_type == consts.VIDEO and not frames: self.frames = get_frames(self.file) if size: self.size = size else: if isinstance(file, BytesIO): self.size = file.getbuffer().nbytes / 1000000 if duration: self.duration = duration else: self.duration = get_duration(self.file) self.host = host
def analyze(self): # Follow redirect to post URL headers = {"User-Agent": consts.spoof_user_agent} r = requests.get("https://v.redd.it/{}".format(self.id), headers=headers) submission_id = REPatterns.reddit_submission.findall(r.url) if submission_id: submission = self.reddit.submission(id=submission_id[0][2]) if submission.is_video: self.url = submission.media['reddit_video']['fallback_url'] else: # Maybe it was deleted? self.id = None r = requests.get(self.url) self.url = r duration = get_duration(BytesIO(r.content)) if duration < 31: # likely uploaded as a mp4, reupload through imgur self.uploader = consts.IMGUR return consts.VIDEO elif duration < 61: # fallback to gfycat self.uploader = consts.GFYCAT return consts.VIDEO else: # fallback as a gif, upload to gfycat # I would like to be able to predict a >200MB GIF file size and switch from self.uploader = consts.GFYCAT return consts.GIF
def analyze(self): """Analyze an imgur gif using the imgurpython library and determine how to reverse and upload""" # pprint(vars(self.pic)) if not self.pic.animated: print("Not a gif!") return False r = requests.get(self.pic.mp4) duration = get_duration(BytesIO(r.content)) # If under a certain duration, it was likely uploaded as an mp4 (and it's easier # for us to reverse it that way anyways) if duration < 31: # Interestingly, imgur appears to allow mp4s under 31 seconds # self.url = self.pic.mp4 # (rather than capping at 30 like they advertise) self.url = r return consts.VIDEO else: # has to have been a gif self.url = self.pic.gifv[:-1] size = get_gif_size(self.url) print("size in MB", size) # Due to gifski bloat, we may need to redirect to gfycat if size > 175: self.uploader = consts.GFYCAT return consts.GIF
def analyze(self): r = requests.get(self.url) self.url = r duration = get_duration(BytesIO(r)) if duration < 31: self.uploader = consts.IMGUR return consts.VIDEO elif duration < 61: self.uploader = consts.GFYCAT return consts.VIDEO else: return None
def __init__(self, file, host=None, gif_type=None, size=None, duration=None, frames=0, audio=None, conversion=None): self.file = file self.info = MediaInfo(self.file) self.file.seek(0) self.type = gif_type self.size = None self.frames = frames # Make unified metadata grabber function if audio is None: self.audio = False else: if audio: self.audio = True else: self.audio = has_audio(self.file) if gif_type == consts.GIF and not frames: self.frames = get_frames(self.file) if self.frames == 0: if self.info.frame_count: self.frames = self.info.frame_count if size: self.size = size else: if isinstance(file, BytesIO): self.size = file.getbuffer().nbytes / 1000000 else: self.size = os.fstat( file.fileno()).st_size / 1000000 # Convert to MB if duration: self.duration = duration else: self.duration = get_duration(self.file) self.conversion = conversion if self.conversion: # If we are converting from MP4 to GIF we to need to estimate the resulting size if conversion == consts.MP4 and self.type == consts.GIF: self.pngs_size = estimate_frames_to_pngs( self.info.dimensions[0], self.info.dimensions[1], self.frames) self.host = host
def analyze(self) -> bool: """Analyze an imgur gif using the imgurpython library and determine how to reverse and upload""" if not self.pic: return False pprint(vars(self.pic)) if not self.pic.animated: print("Not a gif!") return False r = requests.get(self.pic.mp4) file = BytesIO(r.content) self.duration = get_duration(file) self.files.append( GifFile(file, host=self.host, gif_type=consts.MP4, duration=self.duration, size=self.pic.mp4_size / 1000000)) # If the file type is a gif, add it as an option and prioritize it if self.pic.type == 'image/gif': r = requests.get(self.pic.gifv[:-1]) gif = BytesIO(r.content) if is_valid(gif): gif_file = GifFile(gif, host=self.host, gif_type=consts.GIF, duration=self.duration) else: gif_file = GifFile(file, host=self.host, gif_type=consts.GIF, duration=self.duration) self.files.insert(0, gif_file) return True