mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-18 12:00:21 +01:00
changes in tests, upgrade to new EXIF module, etc
This commit is contained in:
1395
src/lib/EXIF.py
1395
src/lib/EXIF.py
File diff suppressed because it is too large
Load Diff
@@ -1,32 +1,23 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
#
|
||||
# Author: Roman 'gryf' Dobosz gryf@elysium.pl
|
||||
#
|
||||
# Copyright (C) 2007 by Roman 'gryf' Dobosz
|
||||
#
|
||||
# This file is part of pyGTKtalog.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
"""
|
||||
Project: pyGTKtalog
|
||||
Description: Simple functions for device management.
|
||||
Type: lib
|
||||
Author: Roman 'gryf' Dobosz, gryf73@gmail.com
|
||||
Created: 2008-12-15
|
||||
"""
|
||||
import os
|
||||
import locale
|
||||
import gettext
|
||||
|
||||
from src.lib.globs import APPL_SHORT_NAME
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
gettext.install(APPL_SHORT_NAME, 'locale', unicode=True)
|
||||
|
||||
def volname(mntp):
|
||||
"""read volume name from cd/dvd"""
|
||||
dev = mountpoint_to_dev(mntp)
|
||||
label = None
|
||||
if dev != None:
|
||||
try:
|
||||
disk = open(dev, "rb")
|
||||
@@ -35,17 +26,20 @@ def volname(mntp):
|
||||
disk.close()
|
||||
except IOError:
|
||||
return None
|
||||
return label
|
||||
return None
|
||||
return label
|
||||
|
||||
def volmount(mntp):
|
||||
"""mount device, return 'ok' or error message"""
|
||||
"""
|
||||
Mount device.
|
||||
@param mountpoint
|
||||
@returns tuple with bool status of mount, and string with error message
|
||||
"""
|
||||
_in, _out, _err = os.popen3("mount %s" % mntp)
|
||||
inf = _err.readlines()
|
||||
if len(inf) > 0:
|
||||
return inf[0].strip()
|
||||
return False, inf[0].strip()
|
||||
else:
|
||||
return 'ok'
|
||||
return True, ''
|
||||
|
||||
def volumount(mntp):
|
||||
"""mount device, return 'ok' or error message"""
|
||||
@@ -88,5 +82,5 @@ def eject_cd(eject_app, cdrom):
|
||||
return inf[0].strip()
|
||||
|
||||
return 'ok'
|
||||
return "Eject program not specified"
|
||||
return _("Eject program not specified")
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ TOPDIR = top_dir
|
||||
RESOURCES_DIR = os.path.join(TOPDIR, "resources")
|
||||
GLADE_DIR = os.path.join(RESOURCES_DIR, "glade")
|
||||
STYLES_DIR = os.path.join(RESOURCES_DIR, "styles")
|
||||
APPL_SHORT_NAME = "pygtktalog2"
|
||||
APPL_SHORT_NAME = "pygtktalog"
|
||||
APPL_VERSION = (1, 0, 2)
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import os
|
||||
from datetime import date
|
||||
|
||||
class GthumbCommentParser(object):
|
||||
|
||||
"""Read and return comments created eith gThumb program"""
|
||||
def __init__(self, image_path, image_filename):
|
||||
self.path = image_path
|
||||
self.filename = image_filename
|
||||
@@ -36,16 +36,16 @@ class GthumbCommentParser(object):
|
||||
"""Return dictionary with apropriate fields, or None if no comment
|
||||
available"""
|
||||
try:
|
||||
gf = gzip.open(os.path.join(self.path,
|
||||
'.comments', self.filename + '.xml'))
|
||||
gzf = gzip.open(os.path.join(self.path, '.comments',
|
||||
self.filename + '.xml'))
|
||||
except:
|
||||
return None
|
||||
|
||||
try:
|
||||
xml = gf.read()
|
||||
gf.close()
|
||||
xml = gzf.read()
|
||||
gzf.close()
|
||||
except:
|
||||
gf.close()
|
||||
gzf.close()
|
||||
return None
|
||||
|
||||
if not xml:
|
||||
|
||||
@@ -44,7 +44,6 @@ class Img(object):
|
||||
"""Save image and asociated thumbnail into specific directory structure
|
||||
returns filename for image"""
|
||||
|
||||
|
||||
image_filename = path.join(self.base, self.sha512)
|
||||
thumbnail = path.join(self.base, self.sha512 + "_t")
|
||||
|
||||
|
||||
@@ -1,63 +1,61 @@
|
||||
# This Python file uses the following encoding: utf-8
|
||||
|
||||
"""
|
||||
Project: pyGTKtalog
|
||||
Description: Gather video file information. Uses external tools.
|
||||
Type: lib
|
||||
Author: Roman 'gryf' Dobosz, gryf73@gmail.com
|
||||
Created: 2008-12-15
|
||||
"""
|
||||
from os import popen
|
||||
from sys import argv, exit
|
||||
import sys
|
||||
|
||||
class Midentify(object):
|
||||
"""Class for retrive midentify script output and put it in dict.
|
||||
Usually there is no need for such a detailed movie/clip information.
|
||||
Midentify script belongs to mplayer package.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, filename):
|
||||
"""Init class instance. Filename of a video file is required."""
|
||||
self.filename = filename
|
||||
self.tags = {}
|
||||
|
||||
|
||||
def get_data(self):
|
||||
"""return dict with clip information"""
|
||||
output = popen("midentify \"%s\"" % self.filename).readlines()
|
||||
output = popen('midentify "%s"' % self.filename).readlines()
|
||||
|
||||
attrs = {'ID_VIDEO_WIDTH': ['width', int],
|
||||
'ID_VIDEO_HEIGHT': ['height', int],
|
||||
'ID_LENGTH': ['length', lambda x: int(x.split(".")[0])],
|
||||
# length is in seconds
|
||||
'ID_DEMUXER': ['container', str],
|
||||
'ID_VIDEO_FORMAT': ['video_format', str],
|
||||
'ID_VIDEO_CODEC': ['video_codec', str],
|
||||
'ID_AUDIO_CODEC': ['audio_codec', str],
|
||||
'ID_AUDIO_FORMAT': ['audio_format', str],
|
||||
'ID_AUDIO_NCH': ['audio_no_channels', int],}
|
||||
|
||||
for line in output:
|
||||
line = line.strip()
|
||||
if "ID_VIDEO_WIDTH" in line:
|
||||
self.tags['width'] = line.replace("ID_VIDEO_WIDTH=", "")
|
||||
elif "ID_VIDEO_HEIGHT" in line:
|
||||
self.tags['height'] = line.replace("ID_VIDEO_HEIGHT=", "")
|
||||
elif "ID_LENGTH" in line:
|
||||
length = line.replace("ID_LENGTH=", "")
|
||||
if "." in length:
|
||||
length = length.split(".")[0]
|
||||
seconds = int(length)
|
||||
if seconds > 0:
|
||||
hours = seconds / 3600
|
||||
seconds -= hours * 3600
|
||||
minutes = seconds / 60
|
||||
seconds -= minutes * 60
|
||||
self.tags['length'] = length
|
||||
length_str = "%02d:%02d:%02d" % (hours, minutes, seconds)
|
||||
self.tags['duration'] = length_str
|
||||
elif "ID_DEMUXER" in line:
|
||||
self.tags['container'] = line.replace("ID_DEMUXER=", "")
|
||||
elif "ID_VIDEO_FORMAT" in line:
|
||||
self.tags['video_format'] = line.replace("ID_VIDEO_FORMAT=", "")
|
||||
elif "ID_VIDEO_CODEC" in line:
|
||||
self.tags['video_codec'] = line.replace("ID_VIDEO_CODEC=", "")
|
||||
elif "ID_AUDIO_CODEC" in line:
|
||||
self.tags['audio_codec'] = line.replace("ID_AUDIO_CODEC=", "")
|
||||
elif "ID_AUDIO_FORMAT" in line:
|
||||
self.tags['audio_format'] = line.replace("ID_AUDIO_FORMAT=", "")
|
||||
elif "ID_AUDIO_NCH" in line:
|
||||
self.tags['audio_no_channels'] = line.replace("ID_AUDIO_NCH=",
|
||||
"")
|
||||
for attr in attrs:
|
||||
if attr in line:
|
||||
self.tags[attrs[attr][0]] = \
|
||||
attrs[attr][1](line.replace("%s=" % attr, ""))
|
||||
|
||||
if 'length' in self.tags:
|
||||
if self.tags['length'] > 0:
|
||||
hours = self.tags['length'] / 3600
|
||||
seconds = self.tags['length'] - hours * 3600
|
||||
minutes = seconds / 60
|
||||
seconds -= minutes * 60
|
||||
length_str = "%02d:%02d:%02d" % (hours, minutes, seconds)
|
||||
self.tags['duration'] = length_str
|
||||
return self.tags
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""run as standalone script"""
|
||||
if len(argv) < 2:
|
||||
print "usage: %s filename" % argv[0]
|
||||
exit()
|
||||
|
||||
for arg in argv[1:]:
|
||||
if len(sys.argv) < 2:
|
||||
print "usage: %s filename" % sys.argv[0]
|
||||
sys.exit()
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
mid = Midentify(arg)
|
||||
print mid.get_data()
|
||||
|
||||
Reference in New Issue
Block a user