Re: [python-win32] How to set value with PyIPropertyStore
Ok, I see, thanks a lot for your help though. I probably need to find a different method. Thanks a lot for your patience! On Fri, Nov 15, 2019 at 6:51 AM Tim Roberts wrote: > On Nov 14, 2019, at 4:15 PM, Peng Chen wrote: > > > > Nah, thanks, the stuff I'm trying to do is actually quite simple. > > I try to read the "Encoded date" info from video file, apply a timeshift > and write it back. > > I searched a few different libs, they are either works for image files > only or it's read only and I can't write. > > So I thought of pywin32 and really didn't expect this coming… > > I’m pretty confident that the Windows property system will not be able to > change the file itself. These APIs might have filters that let them READ > items from the media files, but I seriously doubt they will be to MODIFY > media files. > — > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to set value with PyIPropertyStore
Nah, thanks, the stuff I'm trying to do is actually quite simple. I try to read the "Encoded date" info from video file, apply a timeshift and write it back. I searched a few different libs, they are either works for image files only or it's read only and I can't write. So I thought of pywin32 and really didn't expect this coming... Thanks! On Mon, Nov 11, 2019 at 5:24 AM Tim Roberts wrote: > On Nov 10, 2019, at 4:13 PM, Peng Chen wrote: > > > then I tried > riid = "" > ctx = None > properties = propsys.SHGetPropertyStoreFromParsingName( > file_name, ctx, shellcon.GPS_READWRITE, riid) > it reported: > (-2147221005, 'Invalid Class String', None, None) > > > That’s correct. “” is not a valid class string. > SHGetPropertyStoreFromParsingName returns a COM interface, and you have to > tell it what interface you want. It is usually IPropertyStore. > > What are you trying to do here? Are you porting some C++ code you found > into Python? > — > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to set value with PyIPropertyStore
Hi Tim, Thanks, this works! But now the set value part gives access denied. I checked around, it seems the file needs to be opened in GPS_READWRITE mode in order to write info to the file. So I tried: from win32comext.shell import shellcon properties = propsys.SHGetPropertyStoreFromParsingName( file_name, Flags=shellcon.GPS_READWRITE) it reported: SHGetPropertyStoreFromParsingName() takes no keyword arguments then I tried riid = "" ctx = None properties = propsys.SHGetPropertyStoreFromParsingName( file_name, ctx, shellcon.GPS_READWRITE, riid) it reported: (-2147221005, 'Invalid Class String', None, None) sorry for the different issues, possible to take a look on this? Thanks! On Fri, Nov 8, 2019 at 5:22 AM Tim Roberts wrote: > On Nov 7, 2019, at 2:33 PM, Peng Chen wrote: > > > I tried: > dateShifted = propsys.PyPROPVARIANT( > mDate + shift_time.timedelta_obj, pythoncom.VT_DATE) > and it reports: > module 'win32comext.propsys.propsys' has no attribute ‘PyPROPVARIANT' > > > It is embarrassing that I had to figure this out twice today. > dateShifted = propsys.PROPVARIANTType(mDate+shift_time.timedelta_obj, > pythoncom.VT_DATE) > > The PROPVARIANTType function returns a PyPROPVARIANT object. > — > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to set value with PyIPropertyStore
Thanks Tim, I tried: dateShifted = propsys.PyPROPVARIANT( mDate + shift_time.timedelta_obj, pythoncom.VT_DATE) and it reports: module 'win32comext.propsys.propsys' has no attribute 'PyPROPVARIANT' Should I import it from elsewhere? because the import I had is from win32comext.propsys import propsys, pscon On Thu, Nov 7, 2019 at 7:26 PM Tim Roberts wrote: > Peng Chen wrote: > > Hi Tim, > > Thanks for the reply. Sorry for the late. I just found your email > > today. Yes I tried with this code: > > > > from win32comext.propsys import propsys, pscon > > VIDEO_DATE_ENCODED = pscon.PKEY_Media_DateEncoded > > properties = propsys.SHGetPropertyStoreFromParsingName(file_name) > > mDate = properties.GetValue(VIDEO_DATE_ENCODED).GetValue() # got the > > datetime object > > dateShifted = mDate + shift_time.timedelta_obj # shift date > > properties.SetValue(VIDEO_DATE_ENCODED, dateShifted) # set value > > properties.Commit() > > > > and I got error message when executing to > > properties.SetValue(VIDEO_DATE_ENCODED, dateShifted) > > I found it. Try > >dateShifted = propsys.PyPROPVARIANT(mData + shift_time.timedelta_obj, > pythoncom.VT_DATE) > > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to set value with PyIPropertyStore
Hi Tim, Thanks for the reply. Sorry for the late. I just found your email today. Yes I tried with this code: from win32comext.propsys import propsys, pscon VIDEO_DATE_ENCODED = pscon.PKEY_Media_DateEncoded properties = propsys.SHGetPropertyStoreFromParsingName(file_name) mDate = properties.GetValue(VIDEO_DATE_ENCODED).GetValue() # got the datetime object dateShifted = mDate + shift_time.timedelta_obj # shift date properties.SetValue(VIDEO_DATE_ENCODED, dateShifted) # set value properties.Commit() and I got error message when executing to properties.SetValue(VIDEO_DATE_ENCODED, dateShifted) it reports: Object must be a PyPROPVARIANT On Tue, Oct 15, 2019 at 1:25 AM Tim Roberts wrote: > Peng Chen wrote: > > > > I'm working on a script to shift video media creation time. > > > > I can see there is a function > > PyIPropertyStore.SetValue(key, value) and PyIPropertyStore.Commit() > > to write the date back, but I'm not sure how to construct the value > > because it requires PyPROPVARIANT type. > > I can't figure out any where to import this type and doesn't know how > > to construct it. > > PyPROPVARIANT is generally a return type. In a case like this, I would > expect that you would simply pass the datetime value, and the interface > code would convert it into a variant. Have you tried that? Did you get > an error? > > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
[python-win32] How to set value with PyIPropertyStore
Hi, I'm working on a script to shift video media creation time. I used: properties = propsys.SHGetPropertyStoreFromParsingName(file_name) mDate = properties.GetValue(pscon.PKEY_Media_DateEncoded).GetValue() and successfully retrieved media encoded date property. Now I could shift the time and write this value back. I can see there is a function PyIPropertyStore.SetValue(key, value) and PyIPropertyStore.Commit() to write the date back, but I'm not sure how to construct the value because it requires PyPROPVARIANT type. I can't figure out any where to import this type and doesn't know how to construct it. Sorry I'm not familiar with windows programming, would you please help me on this? Thanks! ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32