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:
Paillat
2023-07-02 12:43:43 +02:00
parent f7835f6604
commit d81b2ccebf
4 changed files with 58 additions and 13 deletions

View File

@@ -60,7 +60,7 @@ class Video:
"title": self.idea['title'],
"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'])
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}")
@@ -71,6 +71,8 @@ class Video:
"path": self.path,
"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:
yaml.dump(video_meta_file, f)
f.close()

View File

@@ -15,7 +15,7 @@ from utils.wiki_downloader import download_image as wiki_download_image
unsplash_access = getenv("unsplash_access_key")
if not unsplash_access:
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):
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"):
os.mkdir(path + "/slides/assets")
url= unsplash_url + script[i]['image'].replace("+", ",")
r = requests.get(url)
real_url = r.json()['urls']['raw']
#r = requests.get(url)
#real_url = r.json()['urls']['raw']
real_url = url
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()
content = marp + f"\n\n![bg 70%](assets/slide{i}.jpg)"
content = marp.replace("[imagesrc]", "assets/slide" + str(i) + ".jpg")
with open(path + "/slides/slide" + str(i) + ".md", 'w', encoding='utf-8') as f:
f.write(content)
elif "wikimage" in script[i]:
@@ -62,6 +63,9 @@ async def prepare(path):
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")))
print("Downloaded image for slide with wikiimage " + str(i))
if not os.path.exists(os.path.join(path, "slides", "assets", "slide" + str(i) + ".jpg")):
raise FileNotFoundError
else:
break
except:
r += 1

View File

@@ -6,3 +6,28 @@ class:
- invert
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>

View File

@@ -22,11 +22,25 @@ def download_image(query, download_path):
to.click()
break
time.sleep(1)
image = driver.find_element(By.CLASS_NAME, "rg_i")
image.click()
while True:
try:
image = driver.find_element(By.CLASS_NAME, "rg_i").click()
break
except:
pass
finally:
time.sleep(1)
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
if image.startswith("data:"):