Replies: 7 comments 5 replies
-
|
As usual (you know me) I'm not sure I correctly understand your problem. If not, sorry, and forget my comment. |
Beta Was this translation helpful? Give feedback.
-
|
I understand your problem but you said that Apple did not allow to pick a video file, manually excepted, and my little script shows it is possible. I just take a video, thus last item in my Photos, and this works |
Beta Was this translation helpful? Give feedback.
-
|
I think that Is not correct. Index is the index of your asset in only the videos but you access the index-th of all photos |
Beta Was this translation helpful? Give feedback.
-
|
Perhaps, you could try my code to have a copy of the video in a local temporary file, read this file in binary mode in your "data" for upload, then remove the local temporary file, just to see if it works. |
Beta Was this translation helpful? Give feedback.
-
|
This is a better formatted version of the script that works except the uploaded video is corrupt. |
Beta Was this translation helpful? Give feedback.
-
|
Sincerely, I can't understand because I can get my last video and copy it as a local file, and I can read it without any problem. This perhaps is your upload the problem. |
Beta Was this translation helpful? Give feedback.
-
|
can you please give me a version of your script that does not use the file picker but gets the last video in your library. If I could see how that works, I could perhaps get my script to do what I need. I don't want a local copy but if it is necessary to be able to do a correct upload then that's fine. As long as there is no manual intervention. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry for cross-posting but I wasn't sure whether here or the other Pythonista-issues page was the right place,
I am trying to write a script (with help from ChatGPT) to get the latest video file from my Photo library, upload to Nextcloud, and return a shareable link to the file. I have a script which works except it won’t do videos. That is, it works fine for .img files but not .mov. ChatGPT has concluded:
**Pythonista cannot access actual video files from the Photos library.
This is a known limitation: while it can work with image filepaths (.JPG, etc.), Apple restricts access to full video assets via Pythonista’s photos module — unless exported manually first (e.g., via Shortcuts or Share Sheet).**
Any help would be most appreciated (of the human or AI variety).
Here is the script:
`import photos
import requests
import clipboard
import os
from datetime import datetime
from base64 import b64encode
import re
——— Configuration ———
USERNAME = ''
APP_PASSWORD = '' # Replace with your real app password
BASE_WEBDAV = ''
UPLOAD_FOLDER = 'SharedVideos/'
SHARE_API = ''
——— Step 1: Get latest asset ———
images = photos.get_assets(media_type='image')
videos = photos.get_assets(media_type='video')
assets = images + videos
assets.sort(key=lambda a: a.creation_date or datetime.min, reverse=True)
if not assets:
print("❌ No media found.")
exit()
latest = assets[0]
media_type = latest.media_type
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
ext = 'jpg' if media_type == 'image' else 'mov'
filename = f"Upload-{timestamp}.{ext}"
print(f"📸 Selected: {filename} ({media_type})")
——— Step 2: Upload ———
auth_header = 'Basic ' + b64encode(f'{USERNAME}:{APP_PASSWORD}'.encode()).decode()
upload_url = f"{BASE_WEBDAV}{UPLOAD_FOLDER}{filename}"
if media_type == 'image':
data = latest.get_image_data()
print("📤 Uploading image...")
response = requests.put(upload_url, headers={
'Authorization': auth_header
}, data=data)
else:
try:
index = videos.index(latest)
metadata = photos.get_metadata(index)
video_path = metadata.get('filepath', None)
except Exception as e:
print(f"❌ Error during video upload: {e}")
exit()
——— Step 3: Check upload ———
if not (200 <= response.status_code < 300):
print(f"❌ Upload failed with status {response.status_code}")
print(response.text)
exit()
print("✅ Upload successful.")
——— Step 4: Generate share link ———
share_response = requests.post(SHARE_API, headers={
'Authorization': auth_header,
'OCS-APIRequest': 'true',
'Content-Type': 'application/x-www-form-urlencoded'
}, data={
'path': f'{UPLOAD_FOLDER}{filename}',
'shareType': 3
})
if share_response.status_code != 200:
print(f"❌ Share creation failed: {share_response.status_code}")
print(share_response.text)
exit()
match = re.search(r'(.*?)', share_response.text)
if match:
link = match.group(1)
clipboard.set(link)
print(f"🔗 Link copied to clipboard:\n{link}")
else:
print("❌ Could not extract share link.")
print(share_response.text)
Beta Was this translation helpful? Give feedback.
All reactions