diff --git a/ox/file.py b/ox/file.py index 84372a2..fa809f4 100644 --- a/ox/file.py +++ b/ox/file.py @@ -2,18 +2,19 @@ # vi:si:et:sw=4:sts=4:ts=4 # GPL 2008 from __future__ import division, print_function -import os +from distutils.spawn import find_executable +from glob import glob import hashlib +import os import re import shutil +import sqlite3 import struct import subprocess -import sqlite3 -from distutils.spawn import find_executable from .utils import json -__all__ = ['sha1sum', 'oshash', 'avinfo', 'makedirs'] +__all__ = ['sha1sum', 'oshash', 'avinfo', 'makedirs', 'iexists'] EXTENSIONS = { 'audio': [ @@ -229,7 +230,7 @@ def ffprobe(filename): return value info = {} - if not 'format' in ffinfo: + if 'format' not in ffinfo: info['error'] = 'badfile' else: for key in ('duration', 'size', 'bit_rate'): @@ -368,3 +369,14 @@ def write_path(file): path = os.path.split(file)[0] if path and not os.path.exists(path): os.makedirs(path) + +def iexists(path): + parts = path.split(os.sep) + name = parts[-1].lower() + if len(parts) == 1: + folder = '.' + else: + folder = os.path.dirname(path) + files = os.listdir(folder) + files = {os.path.basename(f).lower() for f in files} + return name in files