Coder Social home page Coder Social logo

pyexifinfo's Introduction

PyExifInfo

Yet Another python wrapper for Phil Harvey' Exiftool ExifTool is the corner stone library to look for when you need to extract Exif or other types of metadata whithin a picture or many other files type.

(French) ExifTool est la package de référence quand il s'agit d'analyser l'Exif ou les métadonnées d'une photo

Installation

	[sudo] pip install -U pyexifinfo
	#sudo is optionnal

Requirements

ExifTool by Phil Harvey. Read, Write and Edit Image Metadata Information!

Usage

import pyexifinfo as p

p.ver() #retrieve your ExifTool version
filename = 'python-logo.png'
p.get_json(filename) #retrieve a json representation of this file exif
=>
[{u'File:FilePermissions': u'rw-rw-r--', u'PNG:Interlace': u'Noninterlaced', u'S
ourceFile': u'/home/laptop/python-logo.png', u'PNG:ColorType': u'RGB with Alpha', u'File:MIMEType': u'image/png',u'File:FileAccessDate': u'2015:07:20 16:37:22-04:00', u'File:FileModifyDate': u'2014:12:12 20:55:59-05:00', u'File:FileSize': u'9.9 kB', u'PNG:ImageWidth': 290, u'File:FileType': u'PNG', u'File:FileName': u'python-logo.png', u'PNG:Compression': u'Deflate/Inflate', u'PNG:PixelsPerUnitY': 2835, u'PNG:PixelsPerUnitX': 2835, u'PNG:ImageHeight': 82, u'PNG:PixelUnits': u'Meters', u'File:Directory': u'/home/laptop', u'File:FileInodeChangDate': u'2015:07:20 16:37:22-04:00', u'PNG:Filter': u'Adaptive', u'PNG:BitDepth': 8, u'Composite:ImageSize': u'290x82', u'ExifTool:ExifToolVersion': 9.46}]

or with style

import pyexifinfo as p
import json

data = p.get_json(filename)
print( json.dumps(data, sort_keys=True,
                  indent=4, separators=(',', ': ')) )

[
    {
        "Composite:ImageSize": "601x203",
        "ExifTool:ExifToolVersion": 9.46,
        "File:Directory": "/home/laptop/Documents/",
        "File:FileAccessDate": "2016:02:10 00:28:11-05:00",
        "File:FileInodeChangeDate": "2016:02:10 00:27:30-05:00",
        "File:FileModifyDate": "2016:02:10 00:27:30-05:00",
        "File:FileName": "python-logo.png",
        "File:FilePermissions": "rw-rw-r--",
        "File:FileSize": "82 kB",
        "File:FileType": "PNG",
        "File:MIMEType": "image/png",
        "PNG:BitDepth": 8,
        "PNG:ColorType": "RGB with Alpha",
        "PNG:Compression": "Deflate/Inflate",
        "PNG:CreationTime": "06/05/04",
        "PNG:Filter": "Adaptive",
        "PNG:ImageHeight": 203,
        "PNG:ImageWidth": 601,
        "PNG:Interlace": "Noninterlaced",
        "PNG:PixelUnits": "Meters",
        "PNG:PixelsPerUnitX": 2800,
        "PNG:PixelsPerUnitY": 2800,
        "PNG:SignificantBits": "8 8 8 8",
        "PNG:Software": "Macromedia Fireworks MX 2004",
        "SourceFile": "/home/laptop/Documents/python-logo.png"
    }
]

With XML (rdf)

data = p.get_xml(filename)
print(data)
=>

<?xml version='1.0' encoding='UTF-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about='/home/laptop/Documents/python-logo.png'
  xmlns:et='http://ns.exiftool.ca/1.0/' et:toolkit='Image::ExifTool 9.46'
  xmlns:ExifTool='http://ns.exiftool.ca/ExifTool/1.0/'
  xmlns:System='http://ns.exiftool.ca/File/System/1.0/'
  xmlns:File='http://ns.exiftool.ca/File/1.0/'
  xmlns:PNG='http://ns.exiftool.ca/PNG/PNG/1.0/'
  xmlns:Composite='http://ns.exiftool.ca/Composite/1.0/'>
 <ExifTool:ExifToolVersion>9.46</ExifTool:ExifToolVersion>
 <System:Directory>/home/guinsly/totrash/pyexif/pyexifinfo/pyexifinfo</System:Directory>
 <System:FileAccessDate>2016:02:10 00:28:11-05:00</System:FileAccessDate>
 <System:FileInodeChangeDate>2016:02:10 00:27:30-05:00</System:FileInodeChangeDate>
 <System:FileModifyDate>2016:02:10 00:27:30-05:00</System:FileModifyDate>
 <System:FileName>python-logo.png</System:FileName>
 <System:FilePermissions>rw-rw-r--</System:FilePermissions>
 <System:FileSize>82 kB</System:FileSize>
 <File:FileType>PNG</File:FileType>
 <File:MIMEType>image/png</File:MIMEType>
 <PNG:BitDepth>8</PNG:BitDepth>
 <PNG:ColorType>RGB with Alpha</PNG:ColorType>
 <PNG:Compression>Deflate/Inflate</PNG:Compression>
 <PNG:CreationTime>06/05/04</PNG:CreationTime>
 <PNG:Filter>Adaptive</PNG:Filter>
 <PNG:ImageHeight>203</PNG:ImageHeight>
 <PNG:ImageWidth>601</PNG:ImageWidth>
 <PNG:Interlace>Noninterlaced</PNG:Interlace>
 <PNG:PixelUnits>Meters</PNG:PixelUnits>
 <PNG:PixelsPerUnitX>2800</PNG:PixelsPerUnitX>
 <PNG:PixelsPerUnitY>2800</PNG:PixelsPerUnitY>
 <PNG:SignificantBits>8 8 8 8</PNG:SignificantBits>
 <PNG:Software>Macromedia Fireworks MX 2004</PNG:Software>
 <Composite:ImageSize>601x203</Composite:ImageSize>
</rdf:Description>
</rdf:RDF>

functions
from pyexifinfo get_json
from pyexifinfo get_csv
from pyexifinfo get_xml
from pyexifinfo fileType
from pyexifinfo mimeType

filename = 'python-logo.png'

result = get_json(filename)
result = get_csv(filename)
result = get_xml(filename)
result = fileType(filename)
result = mimeType(filename)

Supported fileType (read only)

  File Types
  ------------+-------------+-------------+-------------+------------
  3FR   | DVB   | KEY   | ORF   | RWL   
  3G2   | DYLIB | LA    | OTF   | RWZ   
  3GP   | EIP   | LFP   | PAC   | RM    
  AA    | EPS   | LNK   | PAGES | SEQ   
  AAX   | EPUB  | M2TS  | PBM   | SO    
  ACR   | ERF   | M4A/V | PCD   | SR2   
  AFM   | EXE   |g MEF  | PDB   | SRF   
  AI    | EXIF  | MIE   | PDF   | SRW   
  AIFF  | EXR   | MIFF  | PEF   | SVG   
  APE   | EXV   | MKA   | PFA   | SWF   
  ARW   | F4A/V | MKS   | PFB   | THM   
  ASF   | FFF   | MKV   | PFM   | TIFF  
  AVI   | FLA   | MNG   | PGF   | TORRENT
  AZW   | FLAC  | MOBI  | PGM   | TTC   
  BMP   | FLV   | MODD  | PLIST | TTF   
  BTF   | FPF   | MOI   | PICT  | VCF   
  CHM   | FPX   | MOS   | PMP   | VRD   
  COS   | GIF   | MOV   | PNG   | VSD   
  CR2   | GZ    | MP3   | PPM   | WAV   
  CRW   | HDP   | MP4   | PPT   | WDP   
  CS1   | HDR   | MPC   | PPTX  | WEBP  
  DCM   | HTML  | MPG   | PS    | WEBM  
  DCP   | ICC   | MPO   | PSB   | WMA   
  DCR   | ICS   | MQV   | PSD   | WMV   
  DFONT | IDML  | MRW   | PSP   | WV    
  DIVX  | IIQ   | MXF   | QTIF  | X3F   
  DJVU  | IND   | NEF   | RA    | XCF   
  DLL   | INX   | NRW   | RAF   | XLS   
  DNG   | ITC   | NUMBERS  RAM  | XLSX  
  DOC   | J2C   | ODP   | RAR   | XMP   
  DOCX  | JNG   | ODS   | RAW   | ZIP   
  DPX   | JP2   | ODT   | RIFF  |
  DR4   | JPEG  | OFR   | RSRC  |
  DSS   | K25   | OGG   | RTF   |
  DV    | KDC   | OGV   | RW2   |

Contributors

pyexifinfo's People

Contributors

andyyy60 avatar guinslym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyexifinfo's Issues

RUnning on directories

When I run pyexiftool on directories, it gives an unexpected output:

In [75]: pyexifinfo.get_json('.')
    1 directories scanned
    0 image files read
Out[75]: '/home/ajk/Documents/'

So, it prints 1 directories scanned to stdout and returns back the directory name

Installation problem?

When I try to install this using pip, the installation appears to go smoothly, but the pyexifinfo library is not actually installed in the site-packages directory. The dist-info file is created, but not the actually python package. FWIW, this is on FreeBSD 10.3, Python 2.7.11, and PIP 8.1.1 in a virtual environment.

Custom Exception for exiftool not installed

Hi !

I am making a tool for wikipedia-commons and wanted to use exiftool in python and came across this awesome library.
I found that it worked well, but there is no good exception handling is exiftool is not installed.

Possible improvements:

  • Custom Exception being thrown if exiftool is not in PATH (Currently it gives an OSError)
  • Making a function to check if exiftool is installed pyexifinfo.check_deps() ?

Exiftool location

Presumably, since it is called a 'wrapper' the library is not included.

Is there a way to specify the path to the library?

Installation problem of pyexifinfo

Hi, I saw previous post had mentioned about pyexifinfo problem and I had tried the solution which is "pip install -i https://testpypi.python.org/pypi pyexifinfo"
However, there is still an error of FileNotFoundError: [WinError 2] The system cannot find the file specified.
And there is a red line of Command "python setup.py egg_info" failed with error code 1 in C:\Users\USER~1\AppData\Local\Temp\pip-install-jhx_uai0\pyexifinfo
Can I know why does it happen? How should I solve it?
(PS: I am using python 3.7)

pyexifinfo not working in docker

When I create a docker container and run the command pip install exiftool, I get the following error:

Collecting pyexifinfo
  Using cached pyexifinfo-0.4.0.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/pyexifinfo.egg-info
    writing pip-egg-info/pyexifinfo.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/pyexifinfo.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/pyexifinfo.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/pyexifinfo.egg-info/SOURCES.txt'
    reading manifest file 'pip-egg-info/pyexifinfo.egg-info/SOURCES.txt'
    writing manifest file 'pip-egg-info/pyexifinfo.egg-info/SOURCES.txt'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-JBBdJL/pyexifinfo/setup.py", line 95, in <module>
        result = check_if_exiftool_is_already_installed()
      File "/tmp/pip-build-JBBdJL/pyexifinfo/setup.py", line 51, in check_if_exiftool_is_already_installed
        stderr = fnull
      File "/usr/lib/python2.7/subprocess.py", line 168, in call
        return Popen(*popenargs, **kwargs).wait()
      File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
        errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
        raise child_exception
    OSError: [Errno 2] No such file or directory
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JBBdJL/pyexifinfo/

Steps to reproduce:

  • docker run --rm -ti debian:stretch-slim
  • Inside the docker container, execute the following:
    • apt-get update
    • apt-get install python python-pip
    • pip install --upgrade pip
    • pip install pyexifinfo

get_csv function invalid start byte

i use the get_csv function ,in python3.7, but some time will devodeError,
error code on :
https://github.com/guinslym/pyexifinfo/blob/master/pyexifinfo/pyexifinfo.py#L141

I local fix it use this function ,replace s = s.decode('utf-8'), can fix it ,please update

def byte_to_str(byte_str):
if isinstance(byte_str, str):
return byte_str
chard = chardet.detect(byte_str)
if chard.get('encoding'):
byte_str = byte_str.decode(chard['encoding'], 'ignore')
else:
byte_str = byte_str.decode('utf8', 'ignore')
return byte_str

error info:

File "/opt/venv3/lib/python3.7/site-packages/pyexifinfo/pyexifinfo.py", line 143, in get_csv
s = s.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb9 in position 1313: invalid start byte

Not working on FreeBSD

Hello, I am trying to install this module on FreeBSD 11.1 but I can't seem to get this working.
I've tried through pip and through this source code from github.

root@server:~/pyexifinfo # python ./setup.py install
running install
running bdist_egg
running egg_info
writing pyexifinfo.egg-info/PKG-INFO
writing top-level names to pyexifinfo.egg-info/top_level.txt
writing dependency_links to pyexifinfo.egg-info/dependency_links.txt
reading manifest file 'pyexifinfo.egg-info/SOURCES.txt'
writing manifest file 'pyexifinfo.egg-info/SOURCES.txt'
installing library code to build/bdist.freebsd-11.1-RELEASE-amd64/egg
running install_lib
running build_py
creating build/bdist.freebsd-11.1-RELEASE-amd64/egg
creating build/bdist.freebsd-11.1-RELEASE-amd64/egg/pyexifinfo
copying build/lib/pyexifinfo/pyexifinfo.py -> build/bdist.freebsd-11.1-RELEASE-amd64/egg/pyexifinfo
copying build/lib/pyexifinfo/__init__.py -> build/bdist.freebsd-11.1-RELEASE-amd64/egg/pyexifinfo
byte-compiling build/bdist.freebsd-11.1-RELEASE-amd64/egg/pyexifinfo/pyexifinfo.py to pyexifinfo.pyc
byte-compiling build/bdist.freebsd-11.1-RELEASE-amd64/egg/pyexifinfo/__init__.py to __init__.pyc
creating build/bdist.freebsd-11.1-RELEASE-amd64/egg/EGG-INFO
copying pyexifinfo.egg-info/PKG-INFO -> build/bdist.freebsd-11.1-RELEASE-amd64/egg/EGG-INFO
copying pyexifinfo.egg-info/SOURCES.txt -> build/bdist.freebsd-11.1-RELEASE-amd64/egg/EGG-INFO
copying pyexifinfo.egg-info/dependency_links.txt -> build/bdist.freebsd-11.1-RELEASE-amd64/egg/EGG-INFO
copying pyexifinfo.egg-info/top_level.txt -> build/bdist.freebsd-11.1-RELEASE-amd64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/pyexifinfo-0.4.0-py2.7.egg' and adding 'build/bdist.freebsd-11.1-RELEASE-amd64/egg' to it
removing 'build/bdist.freebsd-11.1-RELEASE-amd64/egg' (and everything under it)
Processing pyexifinfo-0.4.0-py2.7.egg
Removing /usr/local/lib/python2.7/site-packages/pyexifinfo-0.4.0-py2.7.egg
Copying pyexifinfo-0.4.0-py2.7.egg to /usr/local/lib/python2.7/site-packages
pyexifinfo 0.4.0 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/site-packages/pyexifinfo-0.4.0-py2.7.egg
Processing dependencies for pyexifinfo==0.4.0
Finished processing dependencies for pyexifinfo==0.4.0
Traceback (most recent call last):
  File "./setup.py", line 95, in <module>
    result = check_if_exiftool_is_already_installed()
  File "./setup.py", line 51, in check_if_exiftool_is_already_installed
    stderr = fnull
  File "/usr/local/lib/python2.7/subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1025, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Return value for some files

For some files which have the "error" value, the output is unexpected. Running exiftool gives:

$ exiftool -G -j -sort ./LICENSE 
[{
  "SourceFile": "./LICENSE",
  "ExifTool:Error": "Unknown file type",
  "ExifTool:ExifToolVersion": 9.46,
  "File:Directory": ".",
  "File:FileAccessDate": "2016:05:04 14:03:29+05:30",
  "File:FileInodeChangeDate": "2016:03:18 08:41:17+05:30",
  "File:FileModifyDate": "2016:03:18 08:41:17+05:30",
  "File:FileName": "LICENSE",
  "File:FilePermissions": "rw-rw-r--",
  "File:FileSize": "1076 bytes"
}]

But pyexifinfo gives:

In [76]: pyexifinfo.get_json('./LICENSE')
Out[76]: '/home/ajk/Documents/wiki/LICENSE'

It makes a lot of sense to show the output given by exiftool in such cases because it has meaningful data and an error message !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.