add mp4 support
This commit is contained in:
44
__main__.py
44
__main__.py
@@ -2,12 +2,35 @@ import sys
|
||||
from pathlib import Path
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import piexif
|
||||
from PIL import Image
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def mp4_add_date(input_path: Path, output_path: Path, epoch):
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(input_path, output_path)
|
||||
exif_date = datetime.utcfromtimestamp(epoch).strftime("%Y:%m:%d %H:%M:%S")
|
||||
print(f"{output_path} @ {exif_date}")
|
||||
subprocess.run(
|
||||
["exiftool", f'-CreateDate="{exif_date}"', output_path]
|
||||
).check_returncode()
|
||||
|
||||
|
||||
def jpg_add_date(input_path: Path, output_path: Path, epoch):
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(input_path, output_path)
|
||||
exif_date = datetime.utcfromtimestamp(epoch).strftime("%Y:%m:%d %H:%M:%S")
|
||||
exif_dict = {
|
||||
"0th": {},
|
||||
"Exif": {piexif.ExifIFD.DateTimeOriginal: exif_date},
|
||||
}
|
||||
print(f"{output_path} @ {exif_date}")
|
||||
piexif.insert(piexif.dump(exif_dict), str(output_path))
|
||||
|
||||
|
||||
def assign(input_dir: Path, output_dir: Path):
|
||||
|
||||
album = input_dir / "your_facebook_activity" / "posts" / "album"
|
||||
@@ -18,8 +41,6 @@ def assign(input_dir: Path, output_dir: Path):
|
||||
data = json.load(f)
|
||||
for e in data["photos"]:
|
||||
uri = e["uri"]
|
||||
if not uri.endswith(".jpg"):
|
||||
continue
|
||||
taken_timestamp = (
|
||||
e.get("media_metadata", {})
|
||||
.get("photo_metadata", {})
|
||||
@@ -34,21 +55,14 @@ def assign(input_dir: Path, output_dir: Path):
|
||||
epoch = creation_timestamp
|
||||
else:
|
||||
assert False
|
||||
exif_date = datetime.utcfromtimestamp(epoch).strftime("%Y:%m:%d %H:%M:%S")
|
||||
|
||||
# print(uri, taken_timestamp, creation_timestamp)
|
||||
|
||||
output_path = output_dir / Path("/".join(Path(uri).parts[-2:]))
|
||||
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(input_dir / uri, output_path)
|
||||
|
||||
exif_dict = {
|
||||
"0th": {},
|
||||
"Exif": {piexif.ExifIFD.DateTimeOriginal: exif_date},
|
||||
}
|
||||
print(f"{output_path} @ {exif_date}")
|
||||
piexif.insert(piexif.dump(exif_dict), str(output_path))
|
||||
if uri.endswith(".jpg"):
|
||||
jpg_add_date(input_dir / uri, output_path, epoch)
|
||||
elif uri.endswith(".mp4"):
|
||||
mp4_add_date(input_dir / uri, output_path, epoch)
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user