def _formatname(output, config, extension): output["ext"] = extension name = config.get("filename") for key in output: if key == "title" and output[key]: name = name.replace("{title}", filenamify(output[key])) if key == "season" and output[key]: number = "{0:02d}".format(int(output[key])) name = name.replace("{season}", number) if key == "episode" and output[key]: number = "{0:02d}".format(int(output[key])) name = name.replace("{episode}", number) if key == "episodename" and output[key]: name = name.replace("{episodename}", filenamify(output[key])) if key == "id" and output[key]: name = name.replace("{id}", output[key]) if key == "service" and output[key]: name = name.replace("{service}", output[key]) if key == "ext" and output[key]: name = name.replace("{ext}", output[key]) # Remove all {text} we cant replace with something for item in re.findall(r"([\.\-]?(([^\.\-]+\w+)?\{[\w\-]+\}))", name): if "season" in output and output["season"] and re.search(r"(e\{[\w\-]+\})", name): name = name.replace(re.search(r"(e\{[\w\-]+\})", name).group(1), "") else: name = name.replace(item[0], "") return name
def _formatname(output, config, extension): output["ext"] = extension name = config.get("filename") for key in output: if key == "title" and output[key]: name = name.replace("{title}", filenamify(output[key])) if key == "season" and output[key]: number = "{:02d}".format(int(output[key])) name = name.replace("{season}", number) if key == "episode" and output[key]: number = "{:02d}".format(int(output[key])) name = name.replace("{episode}", number) if key == "episodename" and output[key]: name = name.replace("{episodename}", filenamify(output[key])) if key == "id" and output[key]: name = name.replace("{id}", output[key]) if key == "service" and output[key]: name = name.replace("{service}", output[key]) if key == "ext" and output[key]: name = name.replace("{ext}", output[key]) # Remove all {text} we cant replace with something for item in re.findall(r"([\.\-]?(([^\.\-]+\w+)?\{[\w\-]+\}))", name): if "season" in output and output["season"] and re.search( r"(e\{[\w\-]+\})", name): name = name.replace( re.search(r"(e\{[\w\-]+\})", name).group(1), "") else: name = name.replace(item[0], "") return name
def outputfilename(self, data): name = None desc = None pid = data[self.visibleid]["parent"]["id"] name = data[pid]["slug"] other = data[self.visibleid]["slug"] vid = data[self.visibleid]["id"] id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7] if name == other: other = None elif name is None: name = other other = None season, episode = self.seasoninfo(data) if "accessibility" in data[self.visibleid]: if data[self.visibleid]["accessibility"] == "AudioDescribed": desc = "syntolkat" if data[self.visibleid]["accessibility"] == "SignInterpreted": desc = "teckentolkat" if not other: other = desc elif desc: other += "-{}".format(desc) self.output["title"] = filenamify(name) self.output["id"] = id self.output["season"] = season self.output["episode"] = episode self.output["episodename"] = other
def outputfilename(self, data): name = None desc = None name = data["moreDetails"]["heading"] other = data["moreDetails"]["episodeHeading"] vid = data["video"]["svtId"] id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7] if name == other: other = None elif name is None: name = other other = None season, episode = self.seasoninfo(data) if "accessibility" in data: if data["accessibility"] == "AudioDescribed": desc = "syntolkat" if data["accessibility"] == "SignInterpreted": desc = "teckentolkat" if not other: other = desc elif desc: other += f"-{desc}" self.output["title"] = filenamify(name) self.output["id"] = id self.output["season"] = season self.output["episode"] = episode self.output["episodename"] = other
def filename(stream): if stream.output["title"] is None: data = ensure_unicode(stream.get_urldata()) if data is None: return False match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S) if match: stream.config.set("output_auto", True) title_tag = decode_html_entities(match.group(1)) stream.output["title"] = filenamify(title_tag) return True
def filename(stream): if stream.output["title"] is None: data = ensure_unicode(stream.get_urldata()) if data is None: return False match = re.search(r"(?i)<title[^>]*>\s*(.*?)\s*</title>", data, re.S) if match: stream.config.set("output_auto", True) title_tag = decode_html_entities(match.group(1)) stream.output["title"] = filenamify(title_tag) return True
def outputfilename(self, data): name = None desc = None if "programTitle" in data and data["programTitle"]: name = filenamify(data["programTitle"]) elif "titleSlug" in data and data["titleSlug"]: name = filenamify(data["titleSlug"]) other = data["title"] if "programVersionId" in data: vid = str(data["programVersionId"]) else: vid = str(data["id"]) id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7] if name == other: other = None elif name is None: name = other other = None season, episode = self.seasoninfo(data) if "accessService" in data: if data["accessService"] == "audioDescription": desc = "syntolkat" if data["accessService"] == "signInterpretation": desc = "teckentolkat" if not other: other = desc elif desc: other += "-{}".format(desc) self.output["title"] = name self.output["id"] = id self.output["season"] = season self.output["episode"] = episode self.output["episodename"] = other
def outputfilename(self, data): name = None desc = None if "programTitle" in data and data["programTitle"]: name = filenamify(data["programTitle"]) elif "titleSlug" in data and data["titleSlug"]: name = filenamify(data["titleSlug"]) other = data["title"] if "programVersionId" in data: vid = str(data["programVersionId"]) else: vid = str(data["id"]) id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7] if name == other: other = None elif name is None: name = other other = None season, episode = self.seasoninfo(data) if "accessService" in data: if data["accessService"] == "audioDescription": desc = "syntolkat" if data["accessService"] == "signInterpretation": desc = "teckentolkat" if not other: other = desc elif desc: other += "-{}".format(desc) self.output["title"] = name self.output["id"] = id self.output["season"] = season self.output["episode"] = episode self.output["episodename"] = other
def test(self): for inp, ref in self.test_values: assert filenamify(inp) == ref
def test(self): for inp, ref in self.test_values: self.assertEqual(filenamify(inp), ref)
def test(self): for inp, ref in self.test_values: self.assertEqual(filenamify(inp), ref)