2014-03-10 05:18:05 +00:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00:00
|
|
|
# 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
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
import operator
|
2016-09-04 20:00:44 +00:00
|
|
|
import os.path
|
2014-03-10 05:18:05 +00:00
|
|
|
import platform
|
|
|
|
import re
|
2016-02-09 22:43:35 +00:00
|
|
|
import traceback
|
2016-09-04 20:00:44 +00:00
|
|
|
import uuid
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
import logger
|
2016-09-04 20:00:44 +00:00
|
|
|
import sickbeard
|
2014-11-17 09:32:57 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
INSTANCE_ID = str(uuid.uuid1())
|
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
USER_AGENT = ('SickGear/(%s; %s; %s)' % (platform.system(), platform.release(), INSTANCE_ID))
|
|
|
|
|
|
|
|
mediaExtensions = ['avi', 'mkv', 'mpg', 'mpeg', 'wmv', 'ogm', 'mp4', 'iso', 'img', 'divx', 'm2ts', 'm4v', 'ts', 'flv',
|
|
|
|
'f4v', 'mov', 'rmvb', 'vob', 'dvr-ms', 'wtv', 'ogv', '3gp', 'webm']
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
subtitleExtensions = ['srt', 'sub', 'ass', 'idx', 'ssa']
|
|
|
|
|
2016-02-11 16:25:29 +00:00
|
|
|
cpu_presets = {'DISABLED': 0, 'LOW': 0.01, 'NORMAL': 0.05, 'HIGH': 0.1}
|
2014-05-17 11:40:26 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
# Other constants
|
2014-03-10 05:18:05 +00:00
|
|
|
MULTI_EP_RESULT = -1
|
|
|
|
SEASON_RESULT = -2
|
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
# Notification Types
|
2014-03-10 05:18:05 +00:00
|
|
|
NOTIFY_SNATCH = 1
|
|
|
|
NOTIFY_DOWNLOAD = 2
|
|
|
|
NOTIFY_SUBTITLE_DOWNLOAD = 3
|
2014-07-03 21:04:26 +00:00
|
|
|
NOTIFY_GIT_UPDATE = 4
|
|
|
|
NOTIFY_GIT_UPDATE_TEXT = 5
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
notifyStrings = {NOTIFY_SNATCH: 'Started Download',
|
|
|
|
NOTIFY_DOWNLOAD: 'Download Finished',
|
|
|
|
NOTIFY_SUBTITLE_DOWNLOAD: 'Subtitle Download Finished',
|
|
|
|
NOTIFY_GIT_UPDATE: 'SickGear Updated',
|
|
|
|
NOTIFY_GIT_UPDATE_TEXT: 'SickGear Updated To Commit#: '}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
# Episode statuses
|
2014-03-25 05:57:24 +00:00
|
|
|
UNKNOWN = -1 # should never happen
|
|
|
|
UNAIRED = 1 # episodes that haven't aired yet
|
|
|
|
SNATCHED = 2 # qualified with quality
|
|
|
|
WANTED = 3 # episodes we don't have but want to get
|
|
|
|
DOWNLOADED = 4 # qualified with quality
|
|
|
|
SKIPPED = 5 # episodes we don't want
|
|
|
|
ARCHIVED = 6 # episodes that you don't have locally (counts toward download completion stats)
|
|
|
|
IGNORED = 7 # episodes that you don't want included in your download stats
|
|
|
|
SNATCHED_PROPER = 9 # qualified with quality
|
|
|
|
SUBTITLED = 10 # qualified with quality
|
2015-03-01 13:49:08 +00:00
|
|
|
FAILED = 11 # episode downloaded or snatched we don't want
|
2014-03-25 05:57:24 +00:00
|
|
|
SNATCHED_BEST = 12 # episode redownloaded using best quality
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
NAMING_REPEAT = 1
|
|
|
|
NAMING_EXTEND = 2
|
|
|
|
NAMING_DUPLICATE = 4
|
|
|
|
NAMING_LIMITED_EXTEND = 8
|
|
|
|
NAMING_SEPARATED_REPEAT = 16
|
|
|
|
NAMING_LIMITED_EXTEND_E_PREFIXED = 32
|
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
multiEpStrings = {NAMING_REPEAT: 'Repeat',
|
|
|
|
NAMING_SEPARATED_REPEAT: 'Repeat (Separated)',
|
|
|
|
NAMING_DUPLICATE: 'Duplicate',
|
|
|
|
NAMING_EXTEND: 'Extend',
|
|
|
|
NAMING_LIMITED_EXTEND: 'Extend (Limited)',
|
|
|
|
NAMING_LIMITED_EXTEND_E_PREFIXED: 'Extend (Limited, E-prefixed)'}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Quality:
|
2014-03-25 05:57:24 +00:00
|
|
|
NONE = 0 # 0
|
|
|
|
SDTV = 1 # 1
|
|
|
|
SDDVD = 1 << 1 # 2
|
|
|
|
HDTV = 1 << 2 # 4
|
|
|
|
RAWHDTV = 1 << 3 # 8 -- 720p/1080i mpeg2 (trollhd releases)
|
|
|
|
FULLHDTV = 1 << 4 # 16 -- 1080p HDTV (QCF releases)
|
|
|
|
HDWEBDL = 1 << 5 # 32
|
2015-09-18 00:06:34 +00:00
|
|
|
FULLHDWEBDL = 1 << 6 # 64 -- 1080p web-dl
|
2014-03-25 05:57:24 +00:00
|
|
|
HDBLURAY = 1 << 7 # 128
|
|
|
|
FULLHDBLURAY = 1 << 8 # 256
|
2016-03-20 15:59:00 +00:00
|
|
|
# UHD4KTV = 1 << 9 # reserved for the future
|
|
|
|
UHD4KWEB = 1 << 10
|
|
|
|
# UHD4KBLURAY = 1 << 11 # reserved for the future
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
# put these bits at the other end of the spectrum, far enough out that they shouldn't interfere
|
2014-03-25 05:57:24 +00:00
|
|
|
UNKNOWN = 1 << 15 # 32768
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
qualityStrings = {NONE: 'N/A',
|
|
|
|
UNKNOWN: 'Unknown',
|
|
|
|
SDTV: 'SD TV',
|
|
|
|
SDDVD: 'SD DVD',
|
|
|
|
HDTV: 'HD TV',
|
|
|
|
RAWHDTV: 'RawHD TV',
|
|
|
|
FULLHDTV: '1080p HD TV',
|
|
|
|
HDWEBDL: '720p WEB-DL',
|
|
|
|
FULLHDWEBDL: '1080p WEB-DL',
|
|
|
|
HDBLURAY: '720p BluRay',
|
2016-03-20 15:59:00 +00:00
|
|
|
FULLHDBLURAY: '1080p BluRay',
|
|
|
|
UHD4KWEB: '2160p UHD 4K WEB'}
|
2015-03-01 13:49:08 +00:00
|
|
|
|
|
|
|
statusPrefixes = {DOWNLOADED: 'Downloaded',
|
|
|
|
SNATCHED: 'Snatched',
|
|
|
|
SNATCHED_PROPER: 'Snatched (Proper)',
|
|
|
|
FAILED: 'Failed',
|
|
|
|
SNATCHED_BEST: 'Snatched (Best)'}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _getStatusStrings(status):
|
|
|
|
toReturn = {}
|
|
|
|
for x in Quality.qualityStrings.keys():
|
2015-03-01 13:49:08 +00:00
|
|
|
toReturn[Quality.compositeStatus(status, x)] = '%s (%s)' % (
|
|
|
|
Quality.statusPrefixes[status], Quality.qualityStrings[x])
|
2014-03-10 05:18:05 +00:00
|
|
|
return toReturn
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def combineQualities(anyQualities, bestQualities):
|
|
|
|
anyQuality = 0
|
|
|
|
bestQuality = 0
|
|
|
|
if anyQualities:
|
|
|
|
anyQuality = reduce(operator.or_, anyQualities)
|
|
|
|
if bestQualities:
|
|
|
|
bestQuality = reduce(operator.or_, bestQualities)
|
|
|
|
return anyQuality | (bestQuality << 16)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def splitQuality(quality):
|
|
|
|
anyQualities = []
|
|
|
|
bestQualities = []
|
|
|
|
for curQual in Quality.qualityStrings.keys():
|
|
|
|
if curQual & quality:
|
|
|
|
anyQualities.append(curQual)
|
|
|
|
if curQual << 16 & quality:
|
|
|
|
bestQualities.append(curQual)
|
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
return sorted(anyQualities), sorted(bestQualities)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2014-05-26 06:29:22 +00:00
|
|
|
def nameQuality(name, anime=False):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2014-11-12 16:43:14 +00:00
|
|
|
Return The quality from an episode File renamed by SickGear
|
2014-03-10 05:18:05 +00:00
|
|
|
If no quality is achieved it will try sceneQuality regex
|
|
|
|
"""
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
name = os.path.basename(name)
|
|
|
|
|
|
|
|
# if we have our exact text then assume we put it there
|
|
|
|
for x in sorted(Quality.qualityStrings.keys(), reverse=True):
|
|
|
|
if x == Quality.UNKNOWN:
|
|
|
|
continue
|
2014-05-26 06:29:22 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
if x == Quality.NONE: # Last chance
|
2014-05-26 06:29:22 +00:00
|
|
|
return Quality.sceneQuality(name, anime)
|
2014-03-25 05:57:24 +00:00
|
|
|
|
|
|
|
regex = '\W' + Quality.qualityStrings[x].replace(' ', '\W') + '\W'
|
2014-03-10 05:18:05 +00:00
|
|
|
regex_match = re.search(regex, name, re.I)
|
|
|
|
if regex_match:
|
|
|
|
return x
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
@staticmethod
|
2014-05-26 06:29:22 +00:00
|
|
|
def sceneQuality(name, anime=False):
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
2015-09-18 00:06:34 +00:00
|
|
|
Return The quality from the scene episode File
|
2014-03-10 05:18:05 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
name = os.path.basename(name)
|
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
checkName = lambda quality_list, func: func([re.search(x, name, re.I) for x in quality_list])
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-05-26 06:29:22 +00:00
|
|
|
if anime:
|
2015-03-01 13:49:08 +00:00
|
|
|
dvdOptions = checkName(['dvd', 'dvdrip'], any)
|
|
|
|
blueRayOptions = checkName(['bluray', 'blu-ray', 'BD'], any)
|
|
|
|
sdOptions = checkName(['360p', '480p', '848x480', 'XviD'], any)
|
|
|
|
hdOptions = checkName(['720p', '1280x720', '960x720'], any)
|
|
|
|
fullHD = checkName(['1080p', '1920x1080'], any)
|
2014-05-26 06:29:22 +00:00
|
|
|
|
2014-06-10 09:48:07 +00:00
|
|
|
if sdOptions and not blueRayOptions and not dvdOptions:
|
2014-05-26 06:29:22 +00:00
|
|
|
return Quality.SDTV
|
2014-06-10 09:48:07 +00:00
|
|
|
elif dvdOptions:
|
2014-05-26 06:29:22 +00:00
|
|
|
return Quality.SDDVD
|
|
|
|
elif hdOptions and not blueRayOptions and not fullHD:
|
|
|
|
return Quality.HDTV
|
2014-06-10 09:48:07 +00:00
|
|
|
elif fullHD and not blueRayOptions and not hdOptions:
|
|
|
|
return Quality.FULLHDTV
|
2014-05-26 06:29:22 +00:00
|
|
|
elif hdOptions and not blueRayOptions and not fullHD:
|
|
|
|
return Quality.HDWEBDL
|
|
|
|
elif blueRayOptions and hdOptions and not fullHD:
|
|
|
|
return Quality.HDBLURAY
|
2014-06-10 09:48:07 +00:00
|
|
|
elif blueRayOptions and fullHD and not hdOptions:
|
2014-05-26 06:29:22 +00:00
|
|
|
return Quality.FULLHDBLURAY
|
2014-11-17 09:32:57 +00:00
|
|
|
elif sickbeard.ANIME_TREAT_AS_HDTV:
|
2015-03-01 13:49:08 +00:00
|
|
|
logger.log(u'Treating file: %s with "unknown" quality as HDTV per user settings' % name, logger.DEBUG)
|
2014-11-17 09:32:57 +00:00
|
|
|
return Quality.HDTV
|
2014-05-26 06:29:22 +00:00
|
|
|
else:
|
|
|
|
return Quality.UNKNOWN
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
if checkName(['(pdtv|hdtv|dsr|tvrip)([-]|.((aac|ac3|dd).?\d\.?\d.)*(xvid|x264|h.?264))'], all) and not checkName(['(720|1080|2160)[pi]'], all) \
|
2015-04-05 18:12:15 +00:00
|
|
|
and not checkName(['hr.ws.pdtv.(x264|h.?264)'], any):
|
2014-03-10 05:18:05 +00:00
|
|
|
return Quality.SDTV
|
2016-03-20 15:59:00 +00:00
|
|
|
elif checkName(['web.?(dl|rip|.[hx]26[45])', 'xvid|x26[45]|.?26[45]'], all) and not checkName(['(720|1080|2160)[pi]'], all):
|
2014-03-10 05:18:05 +00:00
|
|
|
return Quality.SDTV
|
2015-09-18 00:06:34 +00:00
|
|
|
elif checkName(['(dvd.?rip|b[r|d]rip)(.ws)?(.(xvid|divx|x264|h.?264))?'], any) and not checkName(['(720|1080|2160)[pi]'], all):
|
2014-03-10 05:18:05 +00:00
|
|
|
return Quality.SDDVD
|
Change validate and improve specific Torrent provider connections, IPT, KAT, SCC, TPB, TB, TD, TT.
Change refactor cache for torrent providers to reduce code.
Change improve search category selection BMTV, FSH, FF, TB.
Change identify more SD release qualities.
Change update SpeedCD, MoreThan, TVChaosuk.
Add torrent provider HD4Free.
Remove torrent provider BitSoup.
Change only create threads for providers needing a recent search instead of for all enabled.
Add 4489 as experimental value to "Recent search frequency" to use provider freqs instead of fixed width for all.
Fix searching nzb season packs.
Change remove some logging cruft.
2016-03-24 18:24:14 +00:00
|
|
|
elif checkName(['(xvid|divx|480p)'], any) and not checkName(['(720|1080|2160)[pi]'], all) \
|
|
|
|
and not checkName(['hr.ws.pdtv.(x264|h.?264)'], any):
|
|
|
|
return Quality.SDTV
|
2015-04-05 18:12:15 +00:00
|
|
|
elif checkName(['720p', 'hdtv', 'x264|h.?264'], all) or checkName(['hr.ws.pdtv.(x264|h.?264)'], any) \
|
2015-09-18 00:06:34 +00:00
|
|
|
and not checkName(['(1080|2160)[pi]'], all):
|
2014-03-25 05:57:24 +00:00
|
|
|
return Quality.HDTV
|
2015-03-01 13:49:08 +00:00
|
|
|
elif checkName(['720p|1080i', 'hdtv', 'mpeg-?2'], all) or checkName(['1080[pi].hdtv', 'h.?264'], all):
|
2014-03-25 05:57:24 +00:00
|
|
|
return Quality.RAWHDTV
|
2015-03-01 13:49:08 +00:00
|
|
|
elif checkName(['1080p', 'hdtv', 'x264'], all):
|
2014-03-25 05:57:24 +00:00
|
|
|
return Quality.FULLHDTV
|
2016-03-20 15:59:00 +00:00
|
|
|
elif checkName(['720p', 'web.?(dl|rip|.[hx]26[45])'], all) or checkName(['720p', 'itunes', 'x264|h.?264'], all):
|
2014-03-25 05:57:24 +00:00
|
|
|
return Quality.HDWEBDL
|
2016-03-20 15:59:00 +00:00
|
|
|
elif checkName(['1080p', 'web.?(dl|rip|.[hx]26[45])'], all) or checkName(['1080p', 'itunes', 'x264|h.?264'], all):
|
2014-03-25 05:57:24 +00:00
|
|
|
return Quality.FULLHDWEBDL
|
2015-04-05 18:12:15 +00:00
|
|
|
elif checkName(['720p', 'blu.?ray|hddvd|b[r|d]rip', 'x264|h.?264'], all):
|
2014-03-25 05:57:24 +00:00
|
|
|
return Quality.HDBLURAY
|
2015-04-05 18:12:15 +00:00
|
|
|
elif checkName(['1080p', 'blu.?ray|hddvd|b[r|d]rip', 'x264|h.?264'], all):
|
2014-03-10 05:18:05 +00:00
|
|
|
return Quality.FULLHDBLURAY
|
2016-03-20 15:59:00 +00:00
|
|
|
elif checkName(['2160p', 'web.?(dl|rip|.[hx]26[45])'], all):
|
|
|
|
return Quality.UHD4KWEB
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
|
|
|
return Quality.UNKNOWN
|
|
|
|
|
2015-08-21 02:32:27 +00:00
|
|
|
@staticmethod
|
|
|
|
def fileQuality(filename):
|
|
|
|
|
|
|
|
from sickbeard import encodingKludge as ek
|
2016-02-09 22:43:35 +00:00
|
|
|
from sickbeard.exceptions import ex
|
2015-08-21 02:32:27 +00:00
|
|
|
if ek.ek(os.path.isfile, filename):
|
|
|
|
|
|
|
|
from hachoir_parser import createParser
|
|
|
|
from hachoir_metadata import extractMetadata
|
|
|
|
from hachoir_core.stream import InputStreamError
|
|
|
|
|
|
|
|
parser = height = None
|
2016-02-09 22:43:35 +00:00
|
|
|
msg = u'Hachoir can\'t parse file "%s" content quality because it found error: %s'
|
2015-08-21 02:32:27 +00:00
|
|
|
try:
|
2016-02-09 22:43:35 +00:00
|
|
|
parser = ek.ek(createParser, filename)
|
2015-08-21 02:32:27 +00:00
|
|
|
except InputStreamError as e:
|
2016-02-09 22:43:35 +00:00
|
|
|
logger.log(msg % (filename, e.text), logger.WARNING)
|
|
|
|
except Exception as e:
|
|
|
|
logger.log(msg % (filename, ex(e)), logger.ERROR)
|
|
|
|
logger.log(traceback.format_exc(), logger.DEBUG)
|
2015-08-21 02:32:27 +00:00
|
|
|
|
|
|
|
if parser:
|
2016-10-11 23:52:28 +00:00
|
|
|
if '.avi' == filename[-4::].lower():
|
|
|
|
extract = extractMetadata(parser, scan_index=False)
|
|
|
|
else:
|
|
|
|
extract = extractMetadata(parser)
|
2015-08-21 02:32:27 +00:00
|
|
|
if extract:
|
|
|
|
try:
|
|
|
|
height = extract.get('height')
|
|
|
|
except (AttributeError, ValueError):
|
|
|
|
try:
|
|
|
|
for metadata in extract.iterGroups():
|
|
|
|
if re.search('(?i)video', metadata.header):
|
|
|
|
height = metadata.get('height')
|
|
|
|
break
|
|
|
|
except (AttributeError, ValueError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
parser.stream._input.close()
|
|
|
|
|
|
|
|
tolerance = lambda value, percent: int(round(value - (value * percent / 100.0)))
|
|
|
|
if height >= tolerance(352, 5):
|
|
|
|
if height <= tolerance(720, 2):
|
|
|
|
return Quality.SDTV
|
|
|
|
return (Quality.HDTV, Quality.FULLHDTV)[height >= tolerance(1080, 1)]
|
|
|
|
return Quality.UNKNOWN
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def assumeQuality(name):
|
2016-04-07 18:18:00 +00:00
|
|
|
if name.lower().endswith(('.avi', '.mp4', '.mkv')):
|
2014-03-10 05:18:05 +00:00
|
|
|
return Quality.SDTV
|
2015-03-01 13:49:08 +00:00
|
|
|
elif name.lower().endswith('.ts'):
|
2014-03-10 05:18:05 +00:00
|
|
|
return Quality.RAWHDTV
|
|
|
|
else:
|
|
|
|
return Quality.UNKNOWN
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def compositeStatus(status, quality):
|
|
|
|
return status + 100 * quality
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def qualityDownloaded(status):
|
|
|
|
return (status - DOWNLOADED) / 100
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def splitCompositeStatus(status):
|
|
|
|
"""Returns a tuple containing (status, quality)"""
|
|
|
|
if status == UNKNOWN:
|
2015-03-01 13:49:08 +00:00
|
|
|
return UNKNOWN, Quality.UNKNOWN
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
for x in sorted(Quality.qualityStrings.keys(), reverse=True):
|
|
|
|
if status > x * 100:
|
2015-03-01 13:49:08 +00:00
|
|
|
return status - x * 100, x
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-03-01 13:49:08 +00:00
|
|
|
return status, Quality.NONE
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2014-07-27 10:59:21 +00:00
|
|
|
def statusFromName(name, assume=True, anime=False):
|
|
|
|
quality = Quality.nameQuality(name, anime)
|
2015-08-21 02:32:27 +00:00
|
|
|
if assume and Quality.UNKNOWN == quality:
|
2014-03-10 05:18:05 +00:00
|
|
|
quality = Quality.assumeQuality(name)
|
|
|
|
return Quality.compositeStatus(DOWNLOADED, quality)
|
|
|
|
|
2015-08-21 02:32:27 +00:00
|
|
|
@staticmethod
|
|
|
|
def statusFromNameOrFile(file_path, assume=True, anime=False):
|
|
|
|
quality = Quality.nameQuality(file_path, anime)
|
|
|
|
if Quality.UNKNOWN == quality:
|
|
|
|
quality = Quality.fileQuality(file_path)
|
|
|
|
if assume and Quality.UNKNOWN == quality:
|
|
|
|
quality = Quality.assumeQuality(file_path)
|
|
|
|
return Quality.compositeStatus(DOWNLOADED, quality)
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
DOWNLOADED = None
|
|
|
|
SNATCHED = None
|
|
|
|
SNATCHED_PROPER = None
|
|
|
|
FAILED = None
|
2014-03-19 23:33:49 +00:00
|
|
|
SNATCHED_BEST = None
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
Quality.DOWNLOADED = [Quality.compositeStatus(DOWNLOADED, x) for x in Quality.qualityStrings.keys()]
|
|
|
|
Quality.SNATCHED = [Quality.compositeStatus(SNATCHED, x) for x in Quality.qualityStrings.keys()]
|
|
|
|
Quality.SNATCHED_PROPER = [Quality.compositeStatus(SNATCHED_PROPER, x) for x in Quality.qualityStrings.keys()]
|
|
|
|
Quality.FAILED = [Quality.compositeStatus(FAILED, x) for x in Quality.qualityStrings.keys()]
|
2014-03-19 23:33:49 +00:00
|
|
|
Quality.SNATCHED_BEST = [Quality.compositeStatus(SNATCHED_BEST, x) for x in Quality.qualityStrings.keys()]
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
SD = Quality.combineQualities([Quality.SDTV, Quality.SDDVD], [])
|
|
|
|
HD = Quality.combineQualities(
|
|
|
|
[Quality.HDTV, Quality.FULLHDTV, Quality.HDWEBDL, Quality.FULLHDWEBDL, Quality.HDBLURAY, Quality.FULLHDBLURAY],
|
|
|
|
[]) # HD720p + HD1080p
|
|
|
|
HD720p = Quality.combineQualities([Quality.HDTV, Quality.HDWEBDL, Quality.HDBLURAY], [])
|
|
|
|
HD1080p = Quality.combineQualities([Quality.FULLHDTV, Quality.FULLHDWEBDL, Quality.FULLHDBLURAY], [])
|
2016-03-20 15:59:00 +00:00
|
|
|
UHD2160p = Quality.combineQualities([Quality.UHD4KWEB], [])
|
2014-03-25 05:57:24 +00:00
|
|
|
ANY = Quality.combineQualities(
|
|
|
|
[Quality.SDTV, Quality.SDDVD, Quality.HDTV, Quality.FULLHDTV, Quality.HDWEBDL, Quality.FULLHDWEBDL,
|
|
|
|
Quality.HDBLURAY, Quality.FULLHDBLURAY, Quality.UNKNOWN], []) # SD + HD
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
# legacy template, cant remove due to reference in mainDB upgrade?
|
2014-03-10 05:18:05 +00:00
|
|
|
BEST = Quality.combineQualities([Quality.SDTV, Quality.HDTV, Quality.HDWEBDL], [Quality.HDTV])
|
|
|
|
|
2016-03-20 15:59:00 +00:00
|
|
|
qualityPresets = (SD, HD, HD720p, HD1080p, UHD2160p, ANY)
|
2015-03-01 13:49:08 +00:00
|
|
|
|
|
|
|
qualityPresetStrings = {SD: 'SD',
|
|
|
|
HD: 'HD',
|
|
|
|
HD720p: 'HD720p',
|
|
|
|
HD1080p: 'HD1080p',
|
2016-03-20 15:59:00 +00:00
|
|
|
UHD2160p: 'UHD2160p',
|
2015-03-01 13:49:08 +00:00
|
|
|
ANY: 'Any'}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
class StatusStrings:
|
|
|
|
def __init__(self):
|
2015-03-01 13:49:08 +00:00
|
|
|
self.statusStrings = {UNKNOWN: 'Unknown',
|
|
|
|
UNAIRED: 'Unaired',
|
|
|
|
SNATCHED: 'Snatched',
|
|
|
|
DOWNLOADED: 'Downloaded',
|
|
|
|
SKIPPED: 'Skipped',
|
|
|
|
SNATCHED_PROPER: 'Snatched (Proper)',
|
|
|
|
WANTED: 'Wanted',
|
|
|
|
ARCHIVED: 'Archived',
|
|
|
|
IGNORED: 'Ignored',
|
|
|
|
SUBTITLED: 'Subtitled',
|
|
|
|
FAILED: 'Failed',
|
|
|
|
SNATCHED_BEST: 'Snatched (Best)'}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def __getitem__(self, name):
|
2014-03-19 23:33:49 +00:00
|
|
|
if name in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_PROPER + Quality.SNATCHED_BEST:
|
2014-03-10 05:18:05 +00:00
|
|
|
status, quality = Quality.splitCompositeStatus(name)
|
|
|
|
if quality == Quality.NONE:
|
|
|
|
return self.statusStrings[status]
|
|
|
|
else:
|
2015-03-01 13:49:08 +00:00
|
|
|
return '%s (%s)' % (self.statusStrings[status], Quality.qualityStrings[quality])
|
2014-03-10 05:18:05 +00:00
|
|
|
else:
|
2014-03-20 08:15:22 +00:00
|
|
|
return self.statusStrings[name] if self.statusStrings.has_key(name) else ''
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def has_key(self, name):
|
2015-03-01 13:49:08 +00:00
|
|
|
return name in self.statusStrings or name in Quality.DOWNLOADED or name in Quality.SNATCHED \
|
|
|
|
or name in Quality.SNATCHED_PROPER or name in Quality.SNATCHED_BEST
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
statusStrings = StatusStrings()
|
|
|
|
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
class Overview:
|
2014-03-25 05:57:24 +00:00
|
|
|
UNAIRED = UNAIRED # 1
|
2014-03-10 05:18:05 +00:00
|
|
|
QUAL = 2
|
2014-03-25 05:57:24 +00:00
|
|
|
WANTED = WANTED # 3
|
2014-03-10 05:18:05 +00:00
|
|
|
GOOD = 4
|
2014-03-25 05:57:24 +00:00
|
|
|
SKIPPED = SKIPPED # 5
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
# For both snatched statuses. Note: SNATCHED/QUAL have same value and break dict.
|
2014-03-19 23:33:49 +00:00
|
|
|
SNATCHED = SNATCHED_PROPER = SNATCHED_BEST # 9
|
2014-03-25 05:57:24 +00:00
|
|
|
|
2016-09-04 20:00:44 +00:00
|
|
|
overviewStrings = {UNKNOWN: 'unknown',
|
|
|
|
SKIPPED: 'skipped',
|
2015-03-01 13:49:08 +00:00
|
|
|
WANTED: 'wanted',
|
|
|
|
QUAL: 'qual',
|
|
|
|
GOOD: 'good',
|
|
|
|
UNAIRED: 'unaired',
|
|
|
|
SNATCHED: 'snatched'}
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
countryList = {'Australia': 'AU',
|
|
|
|
'Canada': 'CA',
|
2015-09-18 00:06:34 +00:00
|
|
|
'USA': 'US'}
|