update Shared
This commit is contained in:
parent
e7ebbedd38
commit
6881f3471a
184 changed files with 13080 additions and 13691 deletions
|
|
@ -9,6 +9,7 @@ import shutil
|
|||
import struct
|
||||
import subprocess
|
||||
import sqlite3
|
||||
from distutils.spawn import find_executable
|
||||
|
||||
from .utils import json
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ def _get_file_cache():
|
|||
path = path[3:]
|
||||
return os.path.join(path, 'files.sqlite')
|
||||
|
||||
def cache(filename, type='oshash'):
|
||||
def cache(filename, type='oshash', update=False):
|
||||
conn = sqlite3.connect(_get_file_cache(), timeout=10)
|
||||
conn.row_factory = sqlite3.Row
|
||||
|
||||
|
|
@ -67,11 +68,12 @@ def cache(filename, type='oshash'):
|
|||
info = ''
|
||||
for row in c:
|
||||
if stat.st_size == row['size'] and int(stat.st_mtime) == int(row['mtime']):
|
||||
value = row[type]
|
||||
if value:
|
||||
if type == 'info':
|
||||
value = json.loads(value)
|
||||
return value
|
||||
if not update:
|
||||
value = row[type]
|
||||
if value:
|
||||
if type == 'info':
|
||||
value = json.loads(value)
|
||||
return value
|
||||
h = row['oshash']
|
||||
sha1 = row['sha1']
|
||||
info = row['info']
|
||||
|
|
@ -154,6 +156,8 @@ def avinfo(filename, cached=True):
|
|||
if cached:
|
||||
return cache(filename, 'info')
|
||||
if os.path.getsize(filename):
|
||||
if find_executable('ffprobe'):
|
||||
return ffprobe(filename)
|
||||
ffmpeg2theora = cmd('ffmpeg2theora')
|
||||
p = subprocess.Popen([ffmpeg2theora], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
info, error = p.communicate()
|
||||
|
|
@ -219,62 +223,71 @@ def ffprobe(filename):
|
|||
return value
|
||||
|
||||
info = {}
|
||||
for key in ('duration', 'size', 'bit_rate'):
|
||||
info[{
|
||||
'bit_rate': 'bitrate'
|
||||
}.get(key, key)] = fix_value(key, ffinfo['format'][key])
|
||||
info['audio'] = []
|
||||
info['video'] = []
|
||||
info['metadata'] = ffinfo['format'].get('tags', {})
|
||||
for s in ffinfo['streams']:
|
||||
tags = s.pop('tags', {})
|
||||
language = None
|
||||
for t in tags:
|
||||
if t == 'language':
|
||||
language = tags[t]
|
||||
else:
|
||||
info['metadata'][t] = tags[t]
|
||||
if s.get('codec_type') in ('audio', 'video'):
|
||||
stream = {}
|
||||
if language and language != 'und':
|
||||
stream['language'] = language
|
||||
keys = [
|
||||
'codec_name',
|
||||
'width',
|
||||
'height',
|
||||
'bit_rate',
|
||||
'index',
|
||||
'display_aspect_ratio',
|
||||
'sample_rate',
|
||||
'channels',
|
||||
]
|
||||
if s['codec_type'] == 'video':
|
||||
keys += [
|
||||
'sample_aspect_ratio',
|
||||
'r_frame_rate',
|
||||
'pix_fmt',
|
||||
if not 'format' in ffinfo:
|
||||
info['error'] = 'badfile'
|
||||
else:
|
||||
for key in ('duration', 'size', 'bit_rate'):
|
||||
if key in ffinfo['format']:
|
||||
info[{
|
||||
'bit_rate': 'bitrate'
|
||||
}.get(key, key)] = fix_value(key, ffinfo['format'][key])
|
||||
info['audio'] = []
|
||||
info['video'] = []
|
||||
info['metadata'] = ffinfo['format'].get('tags', {})
|
||||
for s in ffinfo['streams']:
|
||||
tags = s.pop('tags', {})
|
||||
language = None
|
||||
for t in tags:
|
||||
if t == 'language':
|
||||
language = tags[t]
|
||||
else:
|
||||
info['metadata'][t] = tags[t]
|
||||
if s.get('codec_type') in ('audio', 'video'):
|
||||
stream = {}
|
||||
if language and language != 'und':
|
||||
stream['language'] = language
|
||||
keys = [
|
||||
'codec_name',
|
||||
'width',
|
||||
'height',
|
||||
'bit_rate',
|
||||
'index',
|
||||
'display_aspect_ratio',
|
||||
'sample_rate',
|
||||
'channels',
|
||||
]
|
||||
if s['codec_type'] == 'video':
|
||||
keys += [
|
||||
'sample_aspect_ratio',
|
||||
'r_frame_rate',
|
||||
'pix_fmt',
|
||||
]
|
||||
|
||||
for key in keys:
|
||||
if key in s:
|
||||
stream[{
|
||||
'codec_name': 'codec',
|
||||
'bit_rate': 'bitrate',
|
||||
'index': 'id',
|
||||
'r_frame_rate': 'framerate',
|
||||
'sample_rate': 'samplerate',
|
||||
'pix_fmt': 'pixel_format',
|
||||
}.get(key, key)] = fix_value(key, s[key])
|
||||
info[s['codec_type']].append(stream)
|
||||
else:
|
||||
pass
|
||||
#print s
|
||||
for v in info['video']:
|
||||
if not 'display_aspect_ratio' in v and 'width' in v:
|
||||
v['display_aspect_ratio'] = '%d:%d' % (v['width'], v['height'])
|
||||
v['pixel_aspect_ratio'] = '1:1'
|
||||
for key in keys:
|
||||
if key in s:
|
||||
stream[{
|
||||
'codec_name': 'codec',
|
||||
'bit_rate': 'bitrate',
|
||||
'index': 'id',
|
||||
'r_frame_rate': 'framerate',
|
||||
'sample_rate': 'samplerate',
|
||||
'pix_fmt': 'pixel_format',
|
||||
'sample_aspect_ratio': 'pixel_aspect_ratio',
|
||||
}.get(key, key)] = fix_value(key, s[key])
|
||||
info[s['codec_type']].append(stream)
|
||||
else:
|
||||
pass
|
||||
#print s
|
||||
for v in info['video']:
|
||||
k = 'display_aspect_ratio'
|
||||
if not k in v and 'width' in v \
|
||||
or (k in v and v[k] == '0:1'):
|
||||
v[k] = '%d:%d' % (v['width'], v['height'])
|
||||
v['pixel_aspect_ratio'] = '1:1'
|
||||
info['oshash'] = oshash(filename)
|
||||
info['path'] = os.path.basename(filename)
|
||||
info['path'] = filename
|
||||
if not 'size' in info:
|
||||
info['size'] = os.path.getsize(filename)
|
||||
return info
|
||||
|
||||
def makedirs(path):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue