<commit_before>"""
The photo module contains the :class:`Photo` class, which is used to track
image objects (JPG, DNG, etc.).

.. moduleauthor:: <NAME> <<EMAIL>>
"""

import imghdr
import os
import pyexiv2
import re
import subprocess
import time

from elodie import constants
from media import Media
from elodie import geolocation


class Photo(Media):

    """A photo object.

    :param str source: The fully qualified path to the photo file
    """

    __name__ = 'Photo'

    #: Valid extensions for photo files.
    extensions = ('nef', 'dng', 'gif', 'jpg', 'jpeg')

    def __init__(self, source=None):
        super(Photo, self).__init__(source)

        # We only want to parse EXIF once so we store it here
        self.exif = None

    def get_duration(self):
        """Get the duration of a photo in seconds. Uses ffmpeg/ffprobe.

        :returns: str or None for a non-photo file
        """
        if(not self.is_valid()):
            return None

        source = self.source
        result = subprocess.Popen(
            ['ffprobe', source],
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT<commit_msg>gh-92 Add support for RW2 (RAW) files<commit_after>"""
The photo module contains the :class:`Photo` class, which is used to track
image objects (JPG, DNG, etc.).

.. moduleauthor:: <NAME> <<EMAIL>>
"""

import imghdr
import os
import pyexiv2
import re
import subprocess
import time

from elodie import constants
from media import Media
from elodie import geolocation


class Photo(Media):

    """A photo object.

    :param str source: The fully qualified path to the photo file
    """

    __name__ = 'Photo'

    #: Valid extensions for photo files.
    extensions = ('dng', 'gif', 'jpeg', 'jpg', 'nef', 'rw2')

    def __init__(self, source=None):
        super(Photo, self).__init__(source)

        # We only want to parse EXIF once so we store it here
        self.exif = None

    def get_duration(self):
        """Get the duration of a photo in seconds. Uses ffmpeg/ffprobe.

        :returns: str or None for a non-photo file
        """
        if(not self.is_valid()):
            return None

        source = self.source
        result = subprocess.Popen(
            ['ffprobe', source],
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT
{'fraction_non_alphanumeric': 0.1024537236332329, 'fraction_numerical': 0.002582866982350409, 'mean_word_length': 2.6031007751937985, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5134228', 'n_tokens_mistral': 705, 'n_tokens_neox': 672, 'n_words': 256}