mirror of
https://github.com/Paillat-dev/FABLE.git
synced 2026-01-02 01:06:20 +00:00
fix(video.py): remove unnecessary prompt for generating thumbnail
fix(video.py): assign url and id properties after uploading video fix(montage.py): fix unsplash_url to use source.unsplash.com instead of api.unsplash.com fix(montage.py): fix image download logic in prepare function fix(marp.md): add missing newline at end of file fix(wiki_downloader.py): fix image download logic in download_image function
This commit is contained in:
@@ -60,8 +60,8 @@ class Video:
|
|||||||
"title": self.idea['title'],
|
"title": self.idea['title'],
|
||||||
"description": self.idea['description'] + "\n\n" + credits,
|
"description": self.idea['description'] + "\n\n" + credits,
|
||||||
}
|
}
|
||||||
if input("Do you want to generate a thumbnail ? (y/N) : ").lower() == "y":
|
#if input("Do you want to generate a thumbnail ? (y/N) : ").lower() == "y":
|
||||||
await generate_thumbnail( self.path, self.idea['title'], self.idea['description'])
|
await generate_thumbnail( self.path, self.idea['title'], self.idea['description'])
|
||||||
videoid = await upload_video( self.path, self.idea['title'], self.metadata['description'], 28, "", "private", self.parent.path)
|
videoid = await upload_video( self.path, self.idea['title'], self.metadata['description'], 28, "", "private", self.parent.path)
|
||||||
printm(f"Your video is ready! You can find it in { self.path}")
|
printm(f"Your video is ready! You can find it in { self.path}")
|
||||||
video_meta_file = {
|
video_meta_file = {
|
||||||
@@ -71,6 +71,8 @@ class Video:
|
|||||||
"path": self.path,
|
"path": self.path,
|
||||||
"url": f"https://www.youtube.com/watch?v={videoid}",
|
"url": f"https://www.youtube.com/watch?v={videoid}",
|
||||||
}
|
}
|
||||||
|
self.url = video_meta_file['url']
|
||||||
|
self.id = videoid
|
||||||
with open(os.path.join( self.path, "video.yaml"), "w") as f:
|
with open(os.path.join( self.path, "video.yaml"), "w") as f:
|
||||||
yaml.dump(video_meta_file, f)
|
yaml.dump(video_meta_file, f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from utils.wiki_downloader import download_image as wiki_download_image
|
|||||||
unsplash_access = getenv("unsplash_access_key")
|
unsplash_access = getenv("unsplash_access_key")
|
||||||
if not unsplash_access:
|
if not unsplash_access:
|
||||||
raise Exception("UNSPLASH_ACCESS_KEY is not set in .env file")
|
raise Exception("UNSPLASH_ACCESS_KEY is not set in .env file")
|
||||||
unsplash_url = "https://api.unsplash.com/photos/random/?client_id=" + unsplash_access + "&query="
|
unsplash_url = "https://source.unsplash.com/random/?"
|
||||||
|
|
||||||
async def prepare(path):
|
async def prepare(path):
|
||||||
with open(os.path.join(path, "script.json"), 'r', encoding='utf-8') as f:
|
with open(os.path.join(path, "script.json"), 'r', encoding='utf-8') as f:
|
||||||
@@ -42,12 +42,13 @@ async def prepare(path):
|
|||||||
if not os.path.exists(path + "/slides/assets"):
|
if not os.path.exists(path + "/slides/assets"):
|
||||||
os.mkdir(path + "/slides/assets")
|
os.mkdir(path + "/slides/assets")
|
||||||
url= unsplash_url + script[i]['image'].replace("+", ",")
|
url= unsplash_url + script[i]['image'].replace("+", ",")
|
||||||
r = requests.get(url)
|
#r = requests.get(url)
|
||||||
real_url = r.json()['urls']['raw']
|
#real_url = r.json()['urls']['raw']
|
||||||
|
real_url = url
|
||||||
with open(path + "/slides/assets/slide" + str(i) + ".jpg", 'wb') as f:
|
with open(path + "/slides/assets/slide" + str(i) + ".jpg", 'wb') as f:
|
||||||
f.write(requests.get(real_url).content)
|
f.write(requests.get(real_url, allow_redirects=True).content)
|
||||||
f.close()
|
f.close()
|
||||||
content = marp + f"\n\n"
|
content = marp.replace("[imagesrc]", "assets/slide" + str(i) + ".jpg")
|
||||||
with open(path + "/slides/slide" + str(i) + ".md", 'w', encoding='utf-8') as f:
|
with open(path + "/slides/slide" + str(i) + ".md", 'w', encoding='utf-8') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
elif "wikimage" in script[i]:
|
elif "wikimage" in script[i]:
|
||||||
@@ -62,7 +63,10 @@ async def prepare(path):
|
|||||||
print("Trying to download image for slide " + str(i))
|
print("Trying to download image for slide " + str(i))
|
||||||
wiki_download_image(script[i]['wikimage'], os.path.abspath(os.path.join(path, "slides", "assets", "slide" + str(i) + ".jpg")))
|
wiki_download_image(script[i]['wikimage'], os.path.abspath(os.path.join(path, "slides", "assets", "slide" + str(i) + ".jpg")))
|
||||||
print("Downloaded image for slide with wikiimage " + str(i))
|
print("Downloaded image for slide with wikiimage " + str(i))
|
||||||
break
|
if not os.path.exists(os.path.join(path, "slides", "assets", "slide" + str(i) + ".jpg")):
|
||||||
|
raise FileNotFoundError
|
||||||
|
else:
|
||||||
|
break
|
||||||
except:
|
except:
|
||||||
r += 1
|
r += 1
|
||||||
if r > 5:
|
if r > 5:
|
||||||
|
|||||||
@@ -5,4 +5,29 @@ class:
|
|||||||
- lead
|
- lead
|
||||||
- invert
|
- invert
|
||||||
backgroundImage: url(https://images.unsplash.com/photo-1651604454911-fdfb0edde727)
|
backgroundImage: url(https://images.unsplash.com/photo-1651604454911-fdfb0edde727)
|
||||||
---
|
---
|
||||||
|
<style>
|
||||||
|
section {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container {
|
||||||
|
width: 90%;
|
||||||
|
max-height: 90%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container img {
|
||||||
|
object-fit: contain;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="image-container">
|
||||||
|
<img src="[imagesrc]"/>
|
||||||
|
</div>
|
||||||
@@ -22,11 +22,25 @@ def download_image(query, download_path):
|
|||||||
to.click()
|
to.click()
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
image = driver.find_element(By.CLASS_NAME, "rg_i")
|
while True:
|
||||||
image.click()
|
try:
|
||||||
|
image = driver.find_element(By.CLASS_NAME, "rg_i").click()
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
time.sleep(1)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
image = driver.find_element(By.CLASS_NAME, "r48jcc").get_attribute("src") or ""
|
while True:
|
||||||
|
try:
|
||||||
|
image = driver.find_element(By.CLASS_NAME, "iPVvYb").get_attribute("src") or driver.find_element(By.CLASS_NAME, "pT0Scc").get_attribute("src") or driver.find_element(By.CLASS_NAME, "r48jcc").get_attribute("src") or ""
|
||||||
|
if image != "":
|
||||||
|
break
|
||||||
|
except Exception as a:
|
||||||
|
print(a)
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
time.sleep(1)
|
||||||
image_content = None
|
image_content = None
|
||||||
|
|
||||||
if image.startswith("data:"):
|
if image.startswith("data:"):
|
||||||
|
|||||||
Reference in New Issue
Block a user