Example #1
0
def checkMarcKravetz(meta): return (
    checkAttr(meta, 'creation_date', datetime(2007, 7, 19, 9, 3, 57, tzinfo=createTimezone(2))),
    checkAttr(meta, 'sample_rate', 48000),
    checkAttr(meta, 'compr_rate', 12.0),
    checkAttr(meta, 'album', u"France Culture - Le portrait du jour par Marc Kravetz"),
    checkAttr(meta, 'author', u"Marc Kravetz"),
    checkAttr(meta, 'duration', timedelta(0, 2, 400000)),
    checkAttr(meta, 'bit_rate', 128000),
    checkAttr(meta, 'track_number', 32),
    checkAttr(meta, 'bits_per_sample', 16),
    checkAttr(meta, 'copyright', u"Radio France"),
    checkAttr(meta, 'format_version', u"MPEG version 1 layer III"),
)

def checkPentax320(meta): return (
Example #2
0
def checkMarcKravetz(meta):
    return (
        checkAttr(meta, 'creation_date',
                  datetime(2007, 7, 19, 9, 3, 57, tzinfo=createTimezone(2))),
        checkAttr(meta, 'sample_rate', 48000),
        checkAttr(meta, 'compr_rate', 12.0),
        checkAttr(meta, 'album',
                  u"France Culture - Le portrait du jour par Marc Kravetz"),
        checkAttr(meta, 'author', u"Marc Kravetz"),
        checkAttr(meta, 'duration', timedelta(0, 2, 400000)),
        checkAttr(meta, 'bit_rate', 128000),
        checkAttr(meta, 'track_number', 32),
        checkAttr(meta, 'bits_per_sample', 16),
        checkAttr(meta, 'copyright', u"Radio France"),
        checkAttr(meta, 'format_version', u"MPEG version 1 layer III"),
    )
Example #3
0
def parseDatetime(value):
    """
    Year and date:
    >>> parseDatetime("2000")
    (datetime.date(2000, 1, 1), u'2000')
    >>> parseDatetime("2004-01-02")
    datetime.date(2004, 1, 2)

    Timestamp:
    >>> parseDatetime("2004-01-02 18:10:45")
    datetime.datetime(2004, 1, 2, 18, 10, 45)
    >>> parseDatetime("2004-01-02 18:10:45")
    datetime.datetime(2004, 1, 2, 18, 10, 45)

    Timestamp with timezone:
    >>> parseDatetime(u'Thu, 19 Jul 2007 09:03:57 +0000')
    datetime.datetime(2007, 7, 19, 9, 3, 57, tzinfo=<TimezoneUTC delta=0, name=u'UTC'>)
    >>> parseDatetime(u'Thu, 19 Jul 2007 09:03:57 +0200')
    datetime.datetime(2007, 7, 19, 9, 3, 57, tzinfo=<Timezone delta=2:00:00, name='+0200'>)
    """
    value = NORMALIZE_REGEX.sub("~", value.strip())
    regs = YEAR_REGEX1.match(value)
    if regs:
        try:
            year = int(regs.group(1))
            return (date(year, 1, 1), unicode(year))
        except ValueError:
            pass
    regs = DATE_REGEX1.match(value)
    if regs:
        try:
            year = int(regs.group(1))
            month = int(regs.group(2))
            day = int(regs.group(3))
            return date(year, month, day)
        except ValueError:
            pass
    regs = DATETIME_REGEX1.match(value)
    if regs:
        try:
            year = int(regs.group(1))
            month = int(regs.group(2))
            day = int(regs.group(3))
            hour = int(regs.group(4))
            min = int(regs.group(5))
            sec = int(regs.group(6))
            return datetime(year, month, day, hour, min, sec)
        except ValueError:
            pass
    regs = DATETIME_REGEX2.match(value)
    if regs:
        try:
            month = int(regs.group(1))
            day = int(regs.group(2))
            year = int(regs.group(3))
            hour = int(regs.group(4))
            min = int(regs.group(5))
            sec = int(regs.group(6))
            return datetime(year, month, day, hour, min, sec)
        except ValueError:
            pass
    current_locale = setlocale(LC_ALL, "C")
    try:
        match = TIMEZONE_REGEX.match(value)
        if match:
            without_timezone = match.group(1)
            delta = int(match.group(2))
            delta = createTimezone(delta)
        else:
            without_timezone = value
            delta = None
        try:
            timestamp = strptime(without_timezone, ISO_TIMESTAMP)
            arguments = list(timestamp[0:6]) + [0, delta]
            return datetime(*arguments)
        except ValueError:
            pass

        try:
            timestamp = strptime(without_timezone, RIFF_TIMESTAMP)
            arguments = list(timestamp[0:6]) + [0, delta]
            return datetime(*arguments)
        except ValueError:
            pass

        try:
            timestamp = strptime(value, MONTH_YEAR)
            arguments = list(timestamp[0:3])
            return date(*arguments)
        except ValueError:
            pass
    finally:
        setlocale(LC_ALL, current_locale)
    return None