1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 21:54:17 +01:00

flake8: new version detecting more stuff

This commit is contained in:
Johan Andersson 2018-10-28 23:16:00 +01:00
parent b034d92773
commit ca295d461d
16 changed files with 39 additions and 41 deletions

View File

@ -69,7 +69,7 @@ def templateelemt(element, filename, idnumber, offset_sec, duration_sec):
time = [0] time = [0]
for n in selements: for n in selements:
time.append(int(n.attrib["d"])) time.append(int(n.attrib["d"]))
match = re.search("\$Time\$", name) match = re.search(r"\$Time\$", name)
if rvalue and match and len(selements) < 3: if rvalue and match and len(selements) < 3:
for n in range(start, start + total): for n in range(start, start + total):
new = name.replace("$Time$", str(n * int(rvalue[0].attrib["d"]))) new = name.replace("$Time$", str(n * int(rvalue[0].attrib["d"])))
@ -81,7 +81,7 @@ def templateelemt(element, filename, idnumber, offset_sec, duration_sec):
new = name.replace("$Time$", str(number)) new = name.replace("$Time$", str(number))
files.append(urljoin(filename, new)) files.append(urljoin(filename, new))
if "$Number" in name: if "$Number" in name:
if re.search("\$Number(\%\d+)d\$", name): if re.search(r"\$Number(\%\d+)d\$", name):
vname = name.replace("$Number", "").replace("$", "") vname = name.replace("$Number", "").replace("$", "")
for n in range(start, start + total): for n in range(start, start + total):
files.append(urljoin(filename, vname % n)) files.append(urljoin(filename, vname % n))

View File

@ -423,7 +423,7 @@ class M3U8():
def _get_tag_attribute(line): def _get_tag_attribute(line):
line = line[1:] line = line[1:]
try: try:
search_line = re.search("^([A-Z\-]*):(.*)", line) search_line = re.search(r"^([A-Z\-]*):(.*)", line)
return search_line.group(1), search_line.group(2) return search_line.group(1), search_line.group(2)
except Exception: except Exception:
return line, None return line, None
@ -436,7 +436,7 @@ def _get_tuple_attribute(attribute):
name, value = art_l.split("=", 1) name, value = art_l.split("=", 1)
name = name.strip() name = name.strip()
# Checks for attribute name # Checks for attribute name
if not re.match("^[A-Z0-9\-]*$", name): if not re.match(r"^[A-Z0-9\-]*$", name):
raise ValueError("Not a valid attribute name.") raise ValueError("Not a valid attribute name.")
# Remove extra quotes of string # Remove extra quotes of string

View File

@ -214,7 +214,7 @@ class postprocess(object):
os.rename(tempfile, orig_filename) os.rename(tempfile, orig_filename)
def _checktracks(self, output): def _checktracks(self, output):
allstuff = re.findall("Stream \#\d:(\d)\[[^\[]+\]([\(\)\w]+)?: (Video|Audio): (.*)", output) allstuff = re.findall(r"Stream \#\d:(\d)\[[^\[]+\]([\(\)\w]+)?: (Video|Audio): (.*)", output)
videotrack = 0 videotrack = 0
audiotrack = 1 audiotrack = 1
for stream in allstuff: for stream in allstuff:

View File

@ -73,7 +73,7 @@ class Cmore(Service):
parse = urlparse(self.url[0]) parse = urlparse(self.url[0])
else: else:
parse = urlparse(self.url) parse = urlparse(self.url)
return re.search('\.(\w{2})$', parse.netloc).group(1) return re.search(r'\.(\w{2})$', parse.netloc).group(1)
def _login(self): def _login(self):
tld = self._gettld() tld = self._gettld()

View File

@ -20,13 +20,13 @@ class Mtvnn(Service, OpenGraphThumbMixin):
parse = urlparse(self.url) parse = urlparse(self.url)
if parse.netloc.endswith("se"): if parse.netloc.endswith("se"):
match = re.search('<div class="video-player" (.*)>', data) match = re.search(r'<div class="video-player" (.*)>', data)
if not match: if not match:
yield ServiceError("Can't find video info") yield ServiceError("Can't find video info")
return return
match_id = re.search('data-id="([0-9a-fA-F|\-]+)" ', match.group(1)) match_id = re.search(r'data-id="([0-9a-fA-F|\-]+)" ', match.group(1))
if not match_id: if not match_id:
yield ServiceError("Can't find video info") yield ServiceError("Can't find video info")

View File

@ -12,7 +12,7 @@ class NHL(Service, OpenGraphThumbMixin):
supported_domains = ['nhl.com'] supported_domains = ['nhl.com']
def get(self): def get(self):
match = re.search("var initialMedia\s+= ({[^;]+);", self.get_urldata()) match = re.search(r"var initialMedia\s+= ({[^;]+);", self.get_urldata())
if not match: if not match:
yield ServiceError("Cant find any media on that page") yield ServiceError("Cant find any media on that page")
return return
@ -29,7 +29,7 @@ class NHL(Service, OpenGraphThumbMixin):
for n in list(streams.keys()): for n in list(streams.keys()):
yield streams[n] yield streams[n]
else: else:
match = re.search("var mediaConfig\s+= ({[^;]+);", self.get_urldata()) match = re.search(r"var mediaConfig\s+= ({[^;]+);", self.get_urldata())
if not match: if not match:
yield ServiceError("Cant find any media on that page") yield ServiceError("Cant find any media on that page")
return return

View File

@ -138,12 +138,12 @@ class OppetArkiv(Service, OpenGraphThumbMixin):
self.seasoninfo(datat) self.seasoninfo(datat)
def seasoninfo(self, data): def seasoninfo(self, data):
match = re.search("S.song (\d+) - Avsnitt (\d+)", data) match = re.search(r"S.song (\d+) - Avsnitt (\d+)", data)
if match: if match:
self.output["season"] = int(match.group(1)) self.output["season"] = int(match.group(1))
self.output["episode"] = int(match.group(2)) self.output["episode"] = int(match.group(2))
else: else:
match = re.search("Avsnitt (\d+)", data) match = re.search(r"Avsnitt (\d+)", data)
if match: if match:
self.output["episode"] = int(match.group(1)) self.output["episode"] = int(match.group(1))

View File

@ -18,7 +18,7 @@ class Sr(Service, OpenGraphThumbMixin):
def get(self): def get(self):
data = self.get_urldata() data = self.get_urldata()
match = re.search('data-audio-type="publication" data-audio-id="(\d+)">', data) # Nyheter match = re.search(r'data-audio-type="publication" data-audio-id="(\d+)">', data) # Nyheter
if match: if match:
dataurl = "https://sverigesradio.se/sida/playerajax/" \ dataurl = "https://sverigesradio.se/sida/playerajax/" \
"getaudiourl?id={0}&type={1}&quality=high&format=iis".format(match.group(1), "publication") "getaudiourl?id={0}&type={1}&quality=high&format=iis".format(match.group(1), "publication")
@ -31,8 +31,8 @@ class Sr(Service, OpenGraphThumbMixin):
yield HTTP(copy.copy(self.config), urljoin("https://sverigesradio.se", match.group(1)), 128) yield HTTP(copy.copy(self.config), urljoin("https://sverigesradio.se", match.group(1)), 128)
return return
else: else:
match = re.search('data-audio-type="episode" data-audio-id="(\d+)"', data) # Ladda ner med musik match = re.search(r'data-audio-type="episode" data-audio-id="(\d+)"', data) # Ladda ner med musik
match2 = re.search('data-audio-type="secondary" data-audio-id="(\d+)"', data) # Ladda ner utan musik match2 = re.search(r'data-audio-type="secondary" data-audio-id="(\d+)"', data) # Ladda ner utan musik
if match: if match:
aid = match.group(1) aid = match.group(1)
type = "episode" type = "episode"

View File

@ -48,7 +48,7 @@ class Svtplay(Service, MetadataThumbMixin):
yield i yield i
return return
match = re.search("__svtplay'] = ({.*});", self.get_urldata()) match = re.search(r"__svtplay'] = ({.*});", self.get_urldata())
if not match: if not match:
yield ServiceError("Can't find video info.") yield ServiceError("Can't find video info.")
return return
@ -274,8 +274,7 @@ class Svtplay(Service, MetadataThumbMixin):
return season, episode return season, episode
def extrametadata(self, data): def extrametadata(self, data):
self.output["tvshow"] = (self.output["season"] is not None and self.output["tvshow"] = (self.output["season"] is not None and self.output["episode"] is not None)
self.output["episode"] is not None)
try: try:
self.output["publishing_datetime"] = data["video"]["broadcastDate"] / 1000 self.output["publishing_datetime"] = data["video"]["broadcastDate"] / 1000
except KeyError: except KeyError:

View File

@ -83,7 +83,7 @@ class Tv4play(Service, OpenGraphThumbMixin):
yield streams[n] yield streams[n]
def _getjson(self): def _getjson(self):
match = re.search(".prefetched = (\[.*\]);", self.get_urldata()) match = re.search(r".prefetched = (\[.*\]);", self.get_urldata())
return match return match
def find_all_episodes(self, config): def find_all_episodes(self, config):

View File

@ -152,11 +152,11 @@ class Twitch(Service):
yield streams[n] yield streams[n]
def _get_clips(self): def _get_clips(self):
match = re.search("quality_options: (\[[^\]]+\])", self.get_urldata()) match = re.search(r"quality_options: (\[[^\]]+\])", self.get_urldata())
if not match: if not match:
yield ServiceError("Can't find the video clip") yield ServiceError("Can't find the video clip")
return return
name = re.search('slug: "([^"]+)"', self.get_urldata()).group(1) name = re.search(r'slug: "([^"]+)"', self.get_urldata()).group(1)
brodcaster = re.search('broadcaster_login: "([^"]+)"', self.get_urldata()).group(1) brodcaster = re.search('broadcaster_login: "([^"]+)"', self.get_urldata()).group(1)
self.output["title"] = "twitch-{0}".format(brodcaster) self.output["title"] = "twitch-{0}".format(brodcaster)
self.output["episodename"] = name self.output["episodename"] = name

View File

@ -79,14 +79,14 @@ class Urplay(Service, OpenGraphThumbMixin):
if url not in episodes: if url not in episodes:
episodes.append(url) episodes.append(url)
else: else:
match = re.search("/program/\d+-(\w+)-", parse.path) match = re.search(r"/program/\d+-(\w+)-", parse.path)
if not match: if not match:
log.error("Can't find any videos") log.error("Can't find any videos")
return None return None
keyword = match.group(1) keyword = match.group(1)
all_links = re.findall('card-link" href="([^"]+)"', self.get_urldata()) all_links = re.findall('card-link" href="([^"]+)"', self.get_urldata())
for i in all_links: for i in all_links:
match = re.search("/program/\d+-(\w+)-", i) match = re.search(r"/program/\d+-(\w+)-", i)
if match and match.group(1) == keyword: if match and match.group(1) == keyword:
episodes.append(urljoin("https://urplay.se/", i)) episodes.append(urljoin("https://urplay.se/", i))

View File

@ -53,7 +53,7 @@ class Viaplay(Service, OpenGraphThumbMixin):
jansson = json.loads(match.group(1)) jansson = json.loads(match.group(1))
if "seasonNumberOrVideoId" in jansson: if "seasonNumberOrVideoId" in jansson:
season = jansson["seasonNumberOrVideoId"] season = jansson["seasonNumberOrVideoId"]
match = re.search("\w-(\d+)$", season) match = re.search(r"\w-(\d+)$", season)
if match: if match:
season = match.group(1) season = match.group(1)
else: else:
@ -66,18 +66,18 @@ class Viaplay(Service, OpenGraphThumbMixin):
return None return None
if "videoIdOrEpisodeNumber" in jansson: if "videoIdOrEpisodeNumber" in jansson:
videp = jansson["videoIdOrEpisodeNumber"] videp = jansson["videoIdOrEpisodeNumber"]
match = re.search('(\w+)-(\d+)', videp) match = re.search(r'(\w+)-(\d+)', videp)
if match: if match:
episodenr = match.group(2) episodenr = match.group(2)
else: else:
episodenr = videp episodenr = videp
clips = True clips = True
match = re.search('(s\w+)-(\d+)', season) match = re.search(r'(s\w+)-(\d+)', season)
if match: if match:
season = match.group(2) season = match.group(2)
else: else:
# sometimes videoIdOrEpisodeNumber does not work.. this is a workaround # sometimes videoIdOrEpisodeNumber does not work.. this is a workaround
match = re.search('(episode|avsnitt)-(\d+)', self.url) match = re.search(r'(episode|avsnitt)-(\d+)', self.url)
if match: if match:
episodenr = match.group(2) episodenr = match.group(2)
else: else:
@ -197,7 +197,7 @@ class Viaplay(Service, OpenGraphThumbMixin):
def find_all_episodes(self, config): def find_all_episodes(self, config):
seasons = [] seasons = []
match = re.search("(sasong|sesong)-(\d+)", urlparse(self.url).path) match = re.search(r"(sasong|sesong)-(\d+)", urlparse(self.url).path)
if match: if match:
seasons.append(match.group(2)) seasons.append(match.group(2))
else: else:
@ -215,9 +215,9 @@ class Viaplay(Service, OpenGraphThumbMixin):
def _grab_episodes(self, config, seasons): def _grab_episodes(self, config, seasons):
episodes = [] episodes = []
baseurl = self.url baseurl = self.url
match = re.search("(saeson|sasong|sesong)-\d+", urlparse(self.url).path) match = re.search(r"(saeson|sasong|sesong)-\d+", urlparse(self.url).path)
if match: if match:
if re.search("(avsnitt|episode)", urlparse(baseurl).path): if re.search(r"(avsnitt|episode)", urlparse(baseurl).path):
baseurl = baseurl[:baseurl.rfind("/")] baseurl = baseurl[:baseurl.rfind("/")]
baseurl = baseurl[:baseurl.rfind("/")] baseurl = baseurl[:baseurl.rfind("/")]
@ -238,15 +238,15 @@ class Viaplay(Service, OpenGraphThumbMixin):
return episodes return episodes
def _isswe(self, url): def _isswe(self, url):
if re.search(".se$", urlparse(url).netloc): if re.search(r".se$", urlparse(url).netloc):
return "sasong" return "sasong"
elif re.search(".dk$", urlparse(url).netloc): elif re.search(r".dk$", urlparse(url).netloc):
return "saeson" return "saeson"
else: else:
return "sesong" return "sesong"
def _conentpage(self, data): def _conentpage(self, data):
return re.search('=({"sportsPlayer.*}); window.__config', data) return re.search(r'=({"sportsPlayer.*}); window.__config', data)
def _videos_to_list(self, url, vid, episodes): def _videos_to_list(self, url, vid, episodes):
dataj = json.loads(self._get_video_data(vid).text) dataj = json.loads(self._get_video_data(vid).text)

View File

@ -141,7 +141,7 @@ class subtitle(object):
try: try:
number = int(sub.attrib["SpotNumber"]) number = int(sub.attrib["SpotNumber"])
except ValueError: except ValueError:
number = int(re.search("(\d+)", sub.attrib["SpotNumber"]).group(1)) number = int(re.search(r"(\d+)", sub.attrib["SpotNumber"]).group(1))
increase += 1 increase += 1
n = number + increase n = number + increase
@ -365,7 +365,7 @@ def tt_text(node, data):
def strdate(datestring): def strdate(datestring):
match = re.search("^(\d+:\d+:[\.0-9]+) --> (\d+:\d+:[\.0-9]+)", datestring) match = re.search(r"^(\d+:\d+:[\.0-9]+) --> (\d+:\d+:[\.0-9]+)", datestring)
return match return match

View File

@ -116,7 +116,7 @@ def get_one_media(stream):
videos.append(i) videos.append(i)
if isinstance(i, subtitle): if isinstance(i, subtitle):
subs.append(i) subs.append(i)
except Exception as e: except Exception:
if stream.config.get("verbose"): if stream.config.get("verbose"):
raise raise
else: else:

View File

@ -133,8 +133,7 @@ def formatname(output, config, extension="mp4"):
if not output.get("basedir", False): if not output.get("basedir", False):
# If tvshow have not been derived by service do it by if season and episode is set # If tvshow have not been derived by service do it by if season and episode is set
if output.get("tvshow", None) is None: if output.get("tvshow", None) is None:
tvshow = (output.get("season", None) is not None and tvshow = (output.get("season", None) is not None and output.get("episode", None) is not None)
output.get("episode", None) is not None)
else: else:
tvshow = output.get("tvshow", False) tvshow = output.get("tvshow", False)
if config.get("subfolder") and "title" in output and tvshow: if config.get("subfolder") and "title" in output and tvshow:
@ -175,9 +174,9 @@ def _formatname(output, config, extension):
name = name.replace("{ext}", output[key]) name = name.replace("{ext}", output[key])
# Remove all {text} we cant replace with something # Remove all {text} we cant replace with something
for item in re.findall("([\.\-]?(([^\.\-]+\w+)?\{[\w\-]+\}))", name): for item in re.findall(r"([\.\-]?(([^\.\-]+\w+)?\{[\w\-]+\}))", name):
if "season" in output and output["season"] and re.search("(e\{[\w\-]+\})", name): if "season" in output and output["season"] and re.search(r"(e\{[\w\-]+\})", name):
name = name.replace(re.search("(e\{[\w\-]+\})", name).group(1), "") name = name.replace(re.search(r"(e\{[\w\-]+\})", name).group(1), "")
else: else:
name = name.replace(item[0], "") name = name.replace(item[0], "")