You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
80 lines
2.7 KiB
6 years ago
|
# coding=utf-8
|
||
|
|
||
5 years ago
|
from __future__ import absolute_import
|
||
6 years ago
|
import logging
|
||
|
import os
|
||
|
|
||
|
from enzyme import MKV
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
|
||
|
def refine(video, embedded_subtitles=True, **kwargs):
|
||
|
"""Refine a video by searching its metadata.
|
||
|
|
||
|
patch: remove embedded subtitle detection
|
||
|
|
||
|
Several :class:`~subliminal.video.Video` attributes can be found:
|
||
|
|
||
|
* :attr:`~subliminal.video.Video.resolution`
|
||
|
* :attr:`~subliminal.video.Video.video_codec`
|
||
|
* :attr:`~subliminal.video.Video.audio_codec`
|
||
|
* :attr:`~subliminal.video.Video.subtitle_languages`
|
||
|
|
||
|
:param bool embedded_subtitles: search for embedded subtitles.
|
||
|
|
||
|
"""
|
||
|
# skip non existing videos
|
||
|
if not video.exists:
|
||
|
return
|
||
|
|
||
|
# check extensions
|
||
|
extension = os.path.splitext(video.name)[1]
|
||
|
if extension == '.mkv':
|
||
|
with open(video.name, 'rb') as f:
|
||
|
mkv = MKV(f)
|
||
|
|
||
|
# main video track
|
||
|
if mkv.video_tracks:
|
||
|
video_track = mkv.video_tracks[0]
|
||
|
|
||
|
# resolution
|
||
|
if video_track.height in (480, 720, 1080):
|
||
|
if video_track.interlaced:
|
||
|
video.resolution = '%di' % video_track.height
|
||
|
else:
|
||
|
video.resolution = '%dp' % video_track.height
|
||
|
logger.debug('Found resolution %s', video.resolution)
|
||
|
|
||
|
# video codec
|
||
|
if video_track.codec_id == 'V_MPEG4/ISO/AVC':
|
||
5 years ago
|
video.video_codec = 'H.264'
|
||
6 years ago
|
logger.debug('Found video_codec %s', video.video_codec)
|
||
|
elif video_track.codec_id == 'V_MPEG4/ISO/SP':
|
||
|
video.video_codec = 'DivX'
|
||
|
logger.debug('Found video_codec %s', video.video_codec)
|
||
|
elif video_track.codec_id == 'V_MPEG4/ISO/ASP':
|
||
5 years ago
|
video.video_codec = 'Xvid'
|
||
6 years ago
|
logger.debug('Found video_codec %s', video.video_codec)
|
||
|
else:
|
||
|
logger.warning('MKV has no video track')
|
||
|
|
||
|
# main audio track
|
||
|
if mkv.audio_tracks:
|
||
|
audio_track = mkv.audio_tracks[0]
|
||
|
# audio codec
|
||
|
if audio_track.codec_id == 'A_AC3':
|
||
5 years ago
|
video.audio_codec = 'Dolby Digital'
|
||
6 years ago
|
logger.debug('Found audio_codec %s', video.audio_codec)
|
||
|
elif audio_track.codec_id == 'A_DTS':
|
||
|
video.audio_codec = 'DTS'
|
||
|
logger.debug('Found audio_codec %s', video.audio_codec)
|
||
|
elif audio_track.codec_id == 'A_AAC':
|
||
|
video.audio_codec = 'AAC'
|
||
|
logger.debug('Found audio_codec %s', video.audio_codec)
|
||
|
else:
|
||
|
logger.warning('MKV has no audio track')
|
||
|
|
||
|
else:
|
||
|
logger.debug('Unsupported video extension %s', extension)
|