Update GuessIt
This commit is contained in:
1 parent
5f5f17112a
commit
ad01a3da4d
11 files changed
+179
-50
No files matched your search
@@ -28,7 +28,13 @@ import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def number_list(s):
|
||||
return list(re.sub('[^0-9]+', ' ', s).split())
|
||||
l = [ int(n) for n in re.sub('[^0-9]+', ' ', s).split() ]
|
||||
|
||||
if len(l) == 2:
|
||||
# it is an episode interval, return all numbers in between
|
||||
return range(l[0], l[1]+1)
|
||||
|
||||
return l
|
||||
|
||||
def guess_episodes_rexps(string):
|
||||
for rexp, confidence, span_adjust in episode_rexps:
|
||||
@@ -38,23 +44,23 @@ def guess_episodes_rexps(string):
|
||||
span = (match.start() + span_adjust[0],
|
||||
match.end() + span_adjust[1])
|
||||
|
||||
# episodes which have a season > 25 are most likely errors
|
||||
# episodes which have a season > 30 are most likely errors
|
||||
# (Simpsons is at 24!)
|
||||
if int(guess.get('season', 0)) > 25:
|
||||
if int(guess.get('season', 0)) > 30:
|
||||
continue
|
||||
|
||||
# decide whether we have only a single episode number or an
|
||||
# episode list
|
||||
if guess.get('episodeNumber'):
|
||||
eplist = number_list(guess['episodeNumber'])
|
||||
guess.set('episodeNumber', int(eplist[0]), confidence=confidence)
|
||||
guess.set('episodeNumber', eplist[0], confidence=confidence)
|
||||
|
||||
if len(eplist) > 1:
|
||||
guess.set('episodeList', list(map(int, eplist)), confidence=confidence)
|
||||
guess.set('episodeList', eplist, confidence=confidence)
|
||||
|
||||
if guess.get('bonusNumber'):
|
||||
eplist = number_list(guess['bonusNumber'])
|
||||
guess.set('bonusNumber', int(eplist[0]), confidence=confidence)
|
||||
guess.set('bonusNumber', eplist[0], confidence=confidence)
|
||||
|
||||
return guess, span
|
||||
|
||||
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# GuessIt - A library for guessing information from filenames
|
||||
# Copyright (c) 2013 Nicolas Wack <wackou@gmail.com>
|
||||
#
|
||||
# GuessIt is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the Lesser GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GuessIt 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
|
||||
# Lesser GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the Lesser GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from guessit.transfo import SingleNodeGuesser
|
||||
from guessit.patterns import find_properties
|
||||
import re
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def guess_properties(string):
|
||||
try:
|
||||
prop, value, pos, end = find_properties(string)[0]
|
||||
return { prop: value }, (pos, end)
|
||||
except IndexError:
|
||||
return None, None
|
||||
|
||||
_idnum = re.compile(r'(?P<idNumber>[a-zA-Z0-9-]{10,})') # 1.0, (0, 0))
|
||||
|
||||
def guess_idnumber(string):
|
||||
match = _idnum.search(string)
|
||||
if match is not None:
|
||||
result = match.groupdict()
|
||||
switch_count = 0
|
||||
DIGIT = 0
|
||||
LETTER = 1
|
||||
OTHER = 2
|
||||
last = LETTER
|
||||
for c in result['idNumber']:
|
||||
if c in '0123456789':
|
||||
ci = DIGIT
|
||||
elif c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
|
||||
ci = LETTER
|
||||
else:
|
||||
ci = OTHER
|
||||
|
||||
if ci != last:
|
||||
switch_count += 1
|
||||
|
||||
last = ci
|
||||
|
||||
switch_ratio = float(switch_count) / len(result['idNumber'])
|
||||
|
||||
# only return the result as probable if we alternate often between
|
||||
# char type (more likely for hash values than for common words)
|
||||
if switch_ratio > 0.4:
|
||||
return result, match.span()
|
||||
|
||||
return None, None
|
||||
|
||||
def process(mtree):
|
||||
SingleNodeGuesser(guess_idnumber, 0.4, log).process(mtree)
|
||||
@@ -31,16 +31,22 @@ def get_patterns(property_name):
|
||||
|
||||
CODECS = get_patterns('videoCodec')
|
||||
FORMATS = get_patterns('format')
|
||||
VAPIS = get_patterns('videoApi')
|
||||
|
||||
GROUP_NAMES = [ r'(?P<videoCodec>' + codec + r')-?(?P<releaseGroup>.*?)[ \.]'
|
||||
# RG names following a codec or format, with a potential space or dash inside the name
|
||||
GROUP_NAMES = [ r'(?P<videoCodec>' + codec + r')[ \.-](?P<releaseGroup>.+?([- \.].*?)??)[ \.]'
|
||||
for codec in CODECS ]
|
||||
GROUP_NAMES += [ r'(?P<format>' + fmt + r')-?(?P<releaseGroup>.*?)[ \.]'
|
||||
GROUP_NAMES += [ r'(?P<format>' + fmt + r')[ \.-](?P<releaseGroup>.+?([- \.].*?)??)[ \.]'
|
||||
for fmt in FORMATS ]
|
||||
GROUP_NAMES += [ r'(?P<videoApi>' + api + r')[ \.-](?P<releaseGroup>.+?([- \.].*?)??)[ \.]'
|
||||
for api in VAPIS ]
|
||||
|
||||
GROUP_NAMES2 = [ r'\.(?P<videoCodec>' + codec + r')-(?P<releaseGroup>.*?)(-(.*?))?[ \.]'
|
||||
for codec in CODECS ]
|
||||
GROUP_NAMES2 += [ r'\.(?P<format>' + fmt + r')-(?P<releaseGroup>.*?)(-(.*?))?[ \.]'
|
||||
GROUP_NAMES2 += [ r'\.(?P<format>' + fmt + r')-(?P<releaseGroup>.*?)(-(.*?))?[ \.]'
|
||||
for fmt in FORMATS ]
|
||||
GROUP_NAMES2 += [ r'\.(?P<videoApi>' + vapi + r')-(?P<releaseGroup>.*?)(-(.*?))?[ \.]'
|
||||
for vapi in VAPIS ]
|
||||
|
||||
GROUP_NAMES = [ re.compile(r, re.IGNORECASE) for r in GROUP_NAMES ]
|
||||
GROUP_NAMES2 = [ re.compile(r, re.IGNORECASE) for r in GROUP_NAMES2 ]
|
||||
@@ -54,12 +60,17 @@ def guess_release_group(string):
|
||||
# first try to see whether we have both a known codec and a known release group
|
||||
for rexp in GROUP_NAMES:
|
||||
match = rexp.search(string)
|
||||
if match:
|
||||
while match:
|
||||
metadata = match.groupdict()
|
||||
release_group = compute_canonical_form('releaseGroup', metadata['releaseGroup'])
|
||||
# make sure this is an actual release group we caught
|
||||
release_group = (compute_canonical_form('releaseGroup', metadata['releaseGroup']) or
|
||||
compute_canonical_form('weakReleaseGroup', metadata['releaseGroup']))
|
||||
if release_group:
|
||||
return adjust_metadata(metadata), (match.start(1), match.end(2))
|
||||
|
||||
# we didn't find anything conclusive, keep searching
|
||||
match = rexp.search(string, match.span()[0]+1)
|
||||
|
||||
# pick anything as releaseGroup as long as we have a codec in front
|
||||
# this doesn't include a potential dash ('-') ending the release group
|
||||
# eg: [...].X264-HiS@SiLUHD-English.[...]
|
||||
|
||||
@@ -33,6 +33,18 @@ def guess_year(string):
|
||||
else:
|
||||
return None, None
|
||||
|
||||
def guess_year_skip_first(string):
|
||||
year, span = search_year(string)
|
||||
if year:
|
||||
year2, span2 = guess_year(string[span[1]:])
|
||||
if year2:
|
||||
return year2, (span2[0]+span[1], span2[1]+span[1])
|
||||
|
||||
def process(mtree):
|
||||
SingleNodeGuesser(guess_year, 1.0, log).process(mtree)
|
||||
return None, None
|
||||
|
||||
|
||||
def process(mtree, skip_first_year=False):
|
||||
if skip_first_year:
|
||||
SingleNodeGuesser(guess_year_skip_first, 1.0, log).process(mtree)
|
||||
else:
|
||||
SingleNodeGuesser(guess_year, 1.0, log).process(mtree)
|
||||
Reference in new issue
Block a user