Add a resolution class to help compare versions avalible

This commit is contained in:
Derek Schmidt 2018-06-08 00:28:07 +00:00
parent cb4eee2cb5
commit e5ddd166b3

View file

@ -5,6 +5,44 @@ import subprocess
import click
import re
class Resolution:
# In decending order of quality, since indexes are used to tell whats "better"
names = [
("8k", "8K", "4320p"),
("5k", "5K", "2880p", "UHD+"),
("4k", "4K", "2160p", "UHD"),
("2k", "2K", "1440p", "QHD", "WQHD"),
("1080p", "FHD"),
("720p", "HD", "HDTV"),
("480p", "SD", "VGA"),
("360p", "nHD"),
("240p", "QVGA")
]
def __init__(self, _name):
self.name = _name
for family in self.names:
if self.name in family:
self.family = family
break
else:
raise ValueError("Did not recongnize resolution name. See Resolution.names")
def __lt__(self, other):
if not isinstance(other, Resolution):
raise TypeError
return self.names.index(self.family) > other.names.index(other.family)
def __eq__(self, other):
if not isinstance(other, Resolution):
raise TypeError
return self.names.index(self.family) == other.names.index(other.family)
def __ne__(self, other):
return not self.__eq__(other)
def __gt__(self, other):
return not self.__lt__(other)
def __le__(self, other):
return self.__lt__(other) or self.__eq__(other)
def __ge__(self, other):
return self.__gt__(other) or self.__eq__(other)
# List of provider RSS feeds to parse, and a regex we use to parse them. Regex should contain at least a "name" group
providers = [
('https://horriblesubs.info/rss.php?res=all', '\[HorribleSubs\]\s(?P<name>.*?)(?:\s-\s(?P<episode>[0-9]+))?\s\[(?P<quality>[0-9]+.)\]\.(?P<encoding>.*)')