def process_submission(submission): new_mirror = MirroredObject(submission.id, submission.url) already_gfycat = False url_to_process = submission.url if submission.domain == "vine.co": url_to_process = retrieve_vine_video_url(url_to_process) elif submission.domain == "v.cdn.vine.co": url_to_process = retrieve_vine_cdn_url(url_to_process) elif submission.domain == "gfycat.com": already_gfycat = True new_mirror.gfycat_url = url_to_process url_to_process = get_gfycat_info(get_id(url_to_process))['mp4Url'] elif submission.domain == "offsided.com": new_mirror.offsided_url = url_to_process url_to_process = get_offsided_info(get_id(url_to_process))['mp4_url'] elif submission.domain == "streamable.com": new_mirror.streamable_url = url_to_process url_to_process = "%s.mp4" % get_streamable_info( get_id(url_to_process))["url_root"] if not url_to_process.startswith('https:'): url_to_process = 'https:' + url_to_process elif submission.domain == "imgur.com" or submission.domain == "i.imgur.com": new_mirror.imgur_url = url_to_process imgur_data = imgur_client.get_image(get_id(url_to_process)) if extension(url_to_process) == "gif": url_to_process = imgur_data.link elif "mp4" in imgur_data.__dict__: url_to_process = imgur_data.__dict__["mp4"] else: return if submission.domain == "giant.gfycat.com": # Just get the gfycat url url_to_process = url_to_process.replace("giant.", "") new_mirror.gfycat_url = url_to_process already_gfycat = True # Get converting log("--Beginning conversion, url to convert is " + url_to_process) if not already_gfycat: gfy_url = gfycat_convert(url_to_process) if gfy_url: new_mirror.gfycat_url = gfy_url log("--Gfy url is " + new_mirror.gfycat_url) remote_size = get_remote_file_size(url_to_process) if submission.domain != "offsided.com": fitba_url = offsided_convert(submission.title, url_to_process) if fitba_url: new_mirror.offsided_url = fitba_url log("--Offsided url is " + new_mirror.offsided_url) if submission.domain != "streamable.com": new_mirror.streamable_url = streamable_convert( url_to_process, retrieve_login_credentials()[2]) log("--Streamable url is " + new_mirror.streamable_url) # if (submission.domain != "imgur.com" and submission.domain != "i.imgur.com") and remote_size < 10485760: # # 10MB file size limit # imgurdata = imgur_client.upload_from_url(url_to_process, config=None, anon=True) # print("Imgurdata - " + imgurdata) # new_mirror.imgur_url = imgurdata.link # log("--Imgur url is " + new_mirror.imgur_url) comment_string = comment_intro + new_mirror.comment_string( submission.domain) + comment_info add_comment(submission, comment_string) if not already_gfycat: # Take some time to avoid rate limiting. Annoying but necessary log('-Waiting 60 seconds', Color.CYAN) time.sleep(60)
def process_submission(submission): new_mirror = MirroredObject(submission.id, submission.url) already_gfycat = False url_to_process = submission.url if submission.domain == "vine.co": url_to_process = retrieve_vine_video_url(url_to_process) elif submission.domain == "v.cdn.vine.co": url_to_process = retrieve_vine_cdn_url(url_to_process) elif submission.domain == "gfycat.com": already_gfycat = True new_mirror.gfycat_url = url_to_process url_to_process = get_gfycat_info(get_id(url_to_process))['mp4Url'] elif submission.domain == "offsided.com": new_mirror.offsided_url = url_to_process url_to_process = get_offsided_info(get_id(url_to_process))['mp4_url'] elif submission.domain == "streamable.com": new_mirror.streamable_url = url_to_process url_to_process = "%s.mp4" % get_streamable_info(get_id(url_to_process))["url_root"] if not url_to_process.startswith('https:'): url_to_process = 'https:' + url_to_process elif submission.domain == "imgur.com" or submission.domain == "i.imgur.com": new_mirror.imgur_url = url_to_process imgur_data = imgur_client.get_image(get_id(url_to_process)) if extension(url_to_process) == "gif": url_to_process = imgur_data.link elif "mp4" in imgur_data.__dict__: url_to_process = imgur_data.__dict__["mp4"] else: return if submission.domain == "giant.gfycat.com": # Just get the gfycat url url_to_process = url_to_process.replace("giant.", "") new_mirror.gfycat_url = url_to_process already_gfycat = True # Get converting log("--Beginning conversion, url to convert is " + url_to_process) if not already_gfycat: gfy_url = gfycat_convert(url_to_process) if gfy_url: new_mirror.gfycat_url = gfy_url log("--Gfy url is " + new_mirror.gfycat_url) remote_size = get_remote_file_size(url_to_process) if submission.domain != "offsided.com": fitba_url = offsided_convert(submission.title, url_to_process) if fitba_url: new_mirror.offsided_url = fitba_url log("--Offsided url is " + new_mirror.offsided_url) if submission.domain != "streamable.com": new_mirror.streamable_url = streamable_convert(url_to_process, retrieve_login_credentials()[2]) log("--Streamable url is " + new_mirror.streamable_url) # if (submission.domain != "imgur.com" and submission.domain != "i.imgur.com") and remote_size < 10485760: # # 10MB file size limit # imgurdata = imgur_client.upload_from_url(url_to_process, config=None, anon=True) # print("Imgurdata - " + imgurdata) # new_mirror.imgur_url = imgurdata.link # log("--Imgur url is " + new_mirror.imgur_url) comment_string = comment_intro + new_mirror.comment_string(submission.domain) + comment_info add_comment(submission, comment_string) if not already_gfycat: # Take some time to avoid rate limiting. Annoying but necessary log('-Waiting 60 seconds', Color.CYAN) time.sleep(60)
def offsided_urls(fit_id): info = get_offsided_info(fit_id) return [[x, info[x]] for x in ('mp4_url', 'webm_url', 'gif_url') if info[x]]