Comments (10)
Looks like the problem is that 'modData.encode()' RETURNS an encoded string - it doesn't modify modDate - so you are still passing in a str.
from pyexiftool.
Looks like the problem is that 'modData.encode()' RETURNS an encoded string - it doesn't modify modDate - so you are still passing in a str.
Thank you for pointing this out.
Seems that no matter what i do to it it stays a string... Do you have any suggestions?
from pyexiftool.
from pyexiftool.
modDataBytes = modData.encode() should work fine
Same issue.
def buildEXIFcommand(self):
for filelist in self.dateFile:
date = filelist['date']
for picfile in filelist['pictures']:
modDate = '"' + '-FileCreateDate=' + date + '"'
modDateBytes = modDate.encode()
picfile = exiftool.fsencode(picfile)
self.exifChange(modDateBytes, picfile)
def exifChange(self, modDateBytes, picfile):
with exiftool.ExifTool(self.exifTool) as et:
et.execute(modDateBytes, picfile)
from pyexiftool.
Goodpoint - looking closer - it is failing at the call to 'start' (which is run as part of the 'with' context manager) - so not even looking at your parameters yet.
Looking at the error in subprocess - (which is windows specific alas) - it appears that it (error message not withstanding) it wants a string - not bytes. And as I said before - this is on the start - not your 'execute' command - so that means it must be an issue with your executable. So I would try creating your path WITHOUT .encode() e.g. :
os.path.join(self.curDir, 'exiftool.exe')
lets see what that brings.
from pyexiftool.
Goodpoint - looking closer - it is failing at the call to 'start' (which is run as part of the 'with' context manager) - so not even looking at your parameters yet.
Looking at the error in subprocess - (which is windows specific alas) - it appears that it (error message not withstanding) it wants a string - not bytes. And as I said before - this is on the start - not your 'execute' command - so that means it must be an issue with your executable. So I would try creating your path WITHOUT .encode() e.g. :
os.path.join(self.curDir, 'exiftool.exe')
lets see what that brings.
I get the same traceback
I can confirm all three variables passed to exiftool are bytes objects
when printed:
b'C:\\Users\\trevo\\OneDrive\\Desktop\\pics\\exiftool.exe'
b'-FileCreateDate=2018:06:01 00:01:01'
b'C:\\Users\\trevo\\OneDrive\\Desktop\\pics\\2018\\06\\MVIMG_20190719_185858.jpg'
Thanks for the help!
from pyexiftool.
That is my point. Your path to exiftool executable should NOT BE BYTES.
When you use the 'with' stmt - it ends up calling:
self._process = subprocess.Popen( [self.executable, "-stay_open", "True", "-@", "-", "-common_args", "-G", "-n"],
Where self.executable is what you called exifTool's constructor with. Popen takes strings.
However - when you call 'execute(...)' - it is writing to a pipe - and that required bytes - so your date and filename need to be bytes.
from pyexiftool.
That is my point. Your path to exiftool executable should NOT BE BYTES.
When you use the 'with' stmt - it ends up calling:
self._process = subprocess.Popen( [self.executable, "-stay_open", "True", "-@", "-", "-common_args", "-G", "-n"],
Where self.executable is what you called exifTool's constructor with. Popen takes strings.
However - when you call 'execute(...)' - it is writing to a pipe - and that required bytes - so your date and filename need to be bytes.
lol you're right i was being an idiot. I was thinking that was being passed to exiftool so I was doing :
self.exifTool = os.path.join(self.curDir.encode(), 'exiftool.exe'.encode())
AND for some reason:
self.exifTool = exiftool.fsencode(collection.exifTool)
So i changed both of those and ended up getting "OSError: [WinError 10038] An operation was attempted on something that is not a socket" I changed the exiftool.py to be from the commit recommended in that issue and all works now!
Thank you for the help! Much appreciated.
from pyexiftool.
working code:
"""
Used to take pictures seperated into folders based on date like year/month/photo.jpg, and
change the create date of photo to the year and month from the folder names.
The script assumes that exiftool.exe and script are in the same directory. year folders are
in same dir as well.
"""
import os
from glob import glob
import exiftool
class collection:
def __init__(self):
self.dateFile = []
self.fileList = {}
self.paths = glob('**/**')
self.curDir = os.getcwd()
self.exifTool = os.path.join(self.curDir, 'exiftool.exe')
self.overwriteOG = b'-overwrite_original'
def setVariables(self):
for path in self.paths:
globPath = os.path.join(path, '*.*')
picturPath = glob(globPath)
pictures = []
for pic in picturPath:
pictures.append(os.path.join(self.curDir, pic))
date = str.replace(path, '\\', ':') + ':01 00:01:01'
self.fileList = {'date':date, 'pictures':pictures}
self.dateFile.append(self.fileList)
class changeDate:
def __init__(self, collection):
self.dateFile = collection.dateFile
self.exifTool = collection.exifTool
self.overwriteOG = collection.overwriteOG
def buildEXIFcommand(self):
for filelist in self.dateFile:
date = filelist['date']
for picfile in filelist['pictures']:
modAllDate = b'-AllDates=' + date.encode()
modCreateDate = b'-FileCreateDate=' + date.encode()
picfile = exiftool.fsencode(picfile)
self.exifChange(modAllDate, modCreateDate, picfile)
def exifChange(self, modAllDate, modCreateDate, picfile):
with exiftool.ExifTool(self.exifTool) as et:
et.execute(self.overwriteOG, modAllDate, modCreateDate, picfile)
if __name__ == "__main__":
Collection = collection()
print('Collecting Files To change')
Collection.setVariables()
ChangeDate = changeDate(Collection)
print('Changing date on collected files')
ChangeDate.buildEXIFcommand()
print('Completed')
from pyexiftool.
Old thread but this helped me understand how to pass arguments to execute. Can be confusing. Thanks.
from pyexiftool.
Related Issues (20)
- decoding to utf-8 issues HOT 3
- IIS error
- writing to to Exif header using the execute() method HOT 1
- Inconsistent use of tab and space broke test on project relying on Sweepatic-PyExifTool-0.2 HOT 1
- How to write yaw,pitch,roll information to an image? HOT 3
- OSError: [WinError 10038] An operation was attempted on something that is not a socket HOT 9
- Getting help to install and run pyexiftool? HOT 5
- Generic exiftool parameters -G and -n are hidden HOT 1
- ... HOT 1
- Read from BytesIO image? HOT 1
- ExifTool process continues to run after parent python process tskill is sent on windows. HOT 3
- WINERROR 10038 HOT 2
- documentation url HOT 4
- pyexiftool resulting in OSError: [Errno 8] Exec format error HOT 1
- execute() runs but doesn't write tags HOT 4
- Broken link to docs in README HOT 2
- Writing custom metadata tags HOT 1
- '-CreateDate<filename' doesn't appear to work via et.execute HOT 1
- Date Formating (-d) Appears to Be Ignored HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyexiftool.