Reading metadata with Python

前端 未结 5 1465
囚心锁ツ
囚心锁ツ 2020-12-09 23:54

For the past two days I have been scanning the Internet to try to find the solution to my problem. I have a folder of different files. They run the gambit of file types. I a

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 00:34

    Windows API Code Pack may be used with Python for .NET to read/write file metadata.

    1. Download the NuGet packages for WindowsAPICodePack-Core and WindowsAPICodePack-Shell

    2. Extract the .nupkg files with a compression utility like 7-Zip to the script's path or someplace defined in the system path variable.

    3. Install Python for .NET with pip install pythonnet.

    Example code to get and set the title of an MP4 video:

    import clr
    clr.AddReference("Microsoft.WindowsAPICodePack")
    clr.AddReference("Microsoft.WindowsAPICodePack.Shell")
    from Microsoft.WindowsAPICodePack.Shell import ShellFile
    
    # create shell file object
    f = ShellFile.FromFilePath(r'movie..mp4')
    
    # read video title
    print(f.Properties.System.Title.Value)
    
    # set video title
    f.Properties.System.Title.Value = 'My video'
    

    Hack to check available properties:

    dir(f.Properties.System)
    

提交回复
热议问题