fixed instagram over 60 seconds

This commit is contained in:
Joe Steele
2024-07-02 09:03:11 -04:00
parent 99d7ac8d63
commit f8b6200168
2 changed files with 25 additions and 4 deletions
Binary file not shown.
+25 -4
View File
@@ -1240,8 +1240,17 @@ def post_to_instagram2(title, content, headers, date, rating, address, picslist,
pics = ((picslist[1:-1].replace(",","")).replace("'","")).split(" ") pics = ((picslist[1:-1].replace(",","")).replace("'","")).split(" ")
video, outputmontage = make_montage_video_from_google(pics) video, outputmontage = make_montage_video_from_google(pics)
try: try:
instasession.video_upload(outputmontage, data) duration, fps, (width, height)=with_moviepy(outputmontage)
except AttributeError as error: if duration < 60:
instasession.video_upload(outputmontage, data)
else:
if not os.path.isfile(outputmontage+".trim.mp4"):
video = VideoFileClip(outputmontage)
video = video.subclip(0, 60)
print (' IG video duration too long 60 : ',duration, fps, (width,height))
video.write_videofile(outputmontage+".trim.mp4")
instasession.video_upload(outputmontage+".trim.mp4", data)
except BaseException as error:
print(" An error occurred uploading video to Instagram:", type(error).__name__) print(" An error occurred uploading video to Instagram:", type(error).__name__)
return False return False
return True return True
@@ -1251,6 +1260,16 @@ def post_to_instagram2(title, content, headers, date, rating, address, picslist,
################################################################################################## ##################################################################################################
def with_moviepy(filename):
from moviepy.editor import VideoFileClip
clip = VideoFileClip(filename)
duration = clip.duration
fps = clip.fps
width, height = clip.size
return duration, fps, (width, height)
##################################################################################################
def post_to_wordpress(title,content,headers,date,rating,address,picslist,local_outputs): def post_to_wordpress(title,content,headers,date,rating,address,picslist,local_outputs):
""" """
Post to WordPress. Post to WordPress.
@@ -1419,6 +1438,8 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,local_o
#postneedsupdate = True #postneedsupdate = True
else: else:
print (' Post already existed: Post ID : ',post_id) print (' Post already existed: Post ID : ',post_id)
if not env.force_web_create:
return True
for pic in picchop: for pic in picchop:
if pic != '': if pic != '':
picslice2 = pic.split("/")[-1] picslice2 = pic.split("/")[-1]
@@ -1524,11 +1545,11 @@ def post_to_wordpress(title,content,headers,date,rating,address,picslist,local_o
business_url_list = local_outputs['postssession'].query(Posts).filter(Posts.name == \ business_url_list = local_outputs['postssession'].query(Posts).filter(Posts.name == \
title).all() title).all()
business_url = "<a href="+str(business_url_list[0].businessurl)+">"+\ business_url = "<a href="+str(business_url_list[0].businessurl)+">"+\
str(business_url_list[0].businessurl)+"</a>" title+"</a>"
# wpurllist = local_outputs['postssession'].query(Posts).filter(Posts.name == title).all() # wpurllist = local_outputs['postssession'].query(Posts).filter(Posts.name == title).all()
# wpurl = wpurllist[0].wpurl # wpurl = wpurllist[0].wpurl
# if business_url or business_url is False: # if business_url or business_url is False:
status_message = str(title) + ': Business website: '+ business_url status_message = str(title) + ':\nBusiness website: '+ business_url
response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), \ response_piclinks = requests.post(env.wpAPI+"/posts/"+ str(post_id), \
data={"content" : title+' - '+status_message+'\n\n'+content+'\n'+googleadress+'\n'+\ data={"content" : title+' - '+status_message+'\n\n'+content+'\n'+googleadress+'\n'+\
rating+contentpics,"featured_media":fmedia,"rank_math_focus_keyword":title},\ rating+contentpics,"featured_media":fmedia,"rank_math_focus_keyword":title},\