Private GIT

Skip to content
Snippets Groups Projects
Commit f6b231c0 authored by miigotu's avatar miigotu
Browse files

Mediainfo (#1394)

* Add ability to use mediainfo when guessing file quality (only used for screen size atm). Must have mediainfo installed

* Fixes https://github.com/SickRage/SickRage/issues/1217#issuecomment-207707947
parent c6f01f19
Branches
No related tags found
No related merge requests found
......@@ -1128,7 +1128,7 @@
<div class="clearfix"></div><br>
<input type="submit" class="btn config_submitter" value="Save Changes')}" /><br>
<input type="submit" class="btn config_submitter" value="${_('Save Changes')}" /><br>
</fieldset>
</div><!-- /component-group3 //-->
......
......@@ -46,7 +46,7 @@
</table>
<br>
<input type="submit" value="Rename Selected" class="btn btn-success"> <a href="/home/displayShow?show=${show.indexerid}" class="btn btn-danger">${_('Cancel Rename')}</a>
<input type="submit" value="Rename Selected" class="btn btn-success"> <a href="${srRoot}/home/displayShow?show=${show.indexerid}" class="btn btn-danger">${_('Cancel Rename')}</a>
<table id="testRenameTable" class="sickbeardTable" cellspacing="1" border="0" cellpadding="0">
......@@ -95,5 +95,5 @@ if len(epList) > 1:
% endfor
</table><br>
<input type="submit" value="${_('Rename Selected')}" class="btn btn-success"> <a href="/home/displayShow?show=${show.indexerid}" class="btn btn-danger">${_('Cancel Rename')}</a>
<input type="submit" value="${_('Rename Selected')}" class="btn btn-success"> <a href=${srRoot}/home/displayShow?show=${show.indexerid}" class="btn btn-danger">${_('Cancel Rename')}</a>
</%block>
File added
......@@ -31,10 +31,11 @@ import platform
import re
import uuid
from fake_useragent import settings as UA_SETTINGS, UserAgent
from sickbeard.numdict import NumDict
from sickrage.helper.encoding import ek
from sickrage.helper.common import try_int, avi_screen_size, mkv_screen_size # pylint: disable=unused-import
from sickrage.helper import video_screen_size
from sickrage.tagger.episode import EpisodeTags
from sickrage.recompiled import tags
......@@ -388,11 +389,7 @@ class Quality(object):
:return: Quality prefix
"""
if filename.endswith('.mkv'):
_, height = mkv_screen_size(filename)
else:
_, height = avi_screen_size(filename)
height = video_screen_size(filename)[1]
if not height:
return Quality.UNKNOWN
......
# coding=utf-8
from common import custom_glob as glob
from media_info import video_screen_size
......@@ -19,12 +19,9 @@
from __future__ import unicode_literals
import io
import os
import re
import glob
import binascii
from enzyme import MKV
from fnmatch import fnmatch
import sickbeard
......@@ -327,48 +324,6 @@ def episode_num(season=None, episode=None, **kwargs):
return '{0:0>3}'.format(season or episode)
def avi_screen_size(filename):
"""
Parses avi file header for width and height
:param filname: the filename to parse
:returns: a tuple in (width, height) format or a tuple of (None, None)
"""
try:
if not filename.endswith('.avi'):
raise
with io.open(filename, 'rb') as f:
header = f.read(72)
x = binascii.hexlify(header[68:72])
height = int(x[6:8] + x[4:6] + x[2:4] + x[0:2], 16)
assert 100 < height < 4320
x = binascii.hexlify(header[64:68])
width = int(x[6:8] + x[4:6] + x[2:4] + x[0:2], 16)
assert 100 < width < 7680
return width, height
except Exception:
return None, None
def mkv_screen_size(filename):
"""
Parses mkv file for width and height
:param filname: the filename to parse
:returns: a tuple in (width, height) format or a tuple of (None, None)
"""
try:
if not filename.endswith('.mkv'):
raise
with io.open(filename, 'rb') as f:
mkv = MKV(f)
return mkv.video_tracks[0].width, mkv.video_tracks[0].height
except Exception:
return None, None
# Backport glob.escape from python 3.4
# https://hg.python.org/cpython/file/3.4/Lib/glob.py#l87
magic_check = re.compile('([*?[])')
......
# coding=utf-8
# This file is part of SickRage.
#
# Author: Dustyn Gibson (miigotu) <miigotu@gmail.com>
# URL: https://sickrage.github.io
# Git: https://github.com/SickRage/SickRage.git
#
# SickRage 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 3 of the License, or
# (at your option) any later version.
#
# SickRage 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 SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals, print_function
import io
import binascii
from enzyme import MKV
from pkg_resources import get_distribution, DistributionNotFound
import sickbeard
try:
get_distribution('pymediainfo')
from pymediainfo import MediaInfo as mediainfo
except (ImportError, DistributionNotFound):
mediainfo = None
def _avi_screen_size(filename):
"""
Parses avi file header for width and height
:param filename: full path and filename to a video file
:type: unicode
:returns tuple: (width, height)
"""
try:
if not filename.endswith('.avi'):
with io.open(filename, 'rb') as f:
header = f.read(72)
x = binascii.hexlify(header[68:72])
height = int(x[6:8] + x[4:6] + x[2:4] + x[0:2], 16)
assert 100 < height < 4320
x = binascii.hexlify(header[64:68])
width = int(x[6:8] + x[4:6] + x[2:4] + x[0:2], 16)
assert 100 < width < 7680
return width, height
except Exception:
pass
return None, None
def _mkv_screen_size(filename):
"""
Parses mkv file for width and height
:param filename: full path and filename to a video file
:type: unicode
:returns tuple: (width, height)
"""
try:
if filename.endswith('.mkv'):
with io.open(filename, 'rb') as f:
mkv = MKV(f)
return mkv.video_tracks[0].width, mkv.video_tracks[0].height
except Exception:
pass
return None, None
def _mediainfo_screen_size(filename):
"""
Attempts to read the width and height of a video file, using mediainfo
:param filename: full path and filename to a video file
:type: unicode
:returns tuple: (width, height)
"""
try:
if mediainfo:
_media_info = mediainfo.parse(filename)
for track in _media_info.tracks:
if track.track_type == 'Video':
return track.width, track.height
except (OSError, TypeError):
pass
return None, None
# Only try to parse processable files once. Resets on restart ofc
bad_files = set()
def video_screen_size(filename):
"""
Attempts to read the width and height of a video file,
first using mediainfo and then enzyme, and then a custom avi reader
:param filename: full path and filename to a video file
:type: unicode
:returns tuple: (width, height)
"""
if filename in bad_files or not sickbeard.helpers.isMediaFile(filename):
return None, None
for method in [_mediainfo_screen_size, _mkv_screen_size, _avi_screen_size]:
screen_size = method(filename)
if screen_size != (None, None):
return screen_size
bad_files.add(filename)
return None, None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment