Esempio n. 1
0
def print_rename_info(src, dst, line=False):
    print("renamed:")
    print(" " * 5, cstr(str(src), Color.Orange))
    print(cstr("--->", "grey"))
    print(" " * 5, cstr(str(dst), Color.LightGreen))
    if line:
        print_line()
Esempio n. 2
0
 def _print_progress(self, event):
     percentage = cstr(event["_percent_str"].lstrip(), Color.LightGreen)
     file_name = cstr(Path(event["filename"]).name, Color.LightBlue)
     if self._first_progress_print:
         self.log(f"Downloading: {file_name} ")
         self._first_progress_print = False
     print(f"\r >> ({percentage}) - {event['_eta_str']})    ", end="")
Esempio n. 3
0
 def show_list(self, one_line: bool = False):
     _missing_str = fcs(f"  o[{self.name} >> MISSING <<]")
     if not one_line:
         _missing_str += "\n     "
     id_str = "id: " + cstr(f"{self.data.get('id', 0)}", Color.LightBlue)
     aired_str = "aired: " + cstr(self.data.get("airdate"), Color.LightBlue)
     name_str = "\"" + cstr(self.data.get("name"), Color.LightBlue) + "\""
     print(f"{_missing_str} {name_str} {id_str} {aired_str}")
Esempio n. 4
0
 def print(self):
     _path_str = cstr(str(self._path.parent.resolve()), Color.Grey)
     _name_str = cstr(self._path.name, Color.LightGreen)
     print(f"{_path_str}/{_name_str}")
     if self._omdb_result.valid:
         self._print_data("title", self._omdb_result.title)
         self._print_data("year", self._omdb_result.year)
         self._print_data("genre", self._omdb_result.genre)
     print_line()
Esempio n. 5
0
 def _prefix_str(self):
     date_str = ""
     prefix2_str = f" {self._log_prefix2}" if self._log_prefix2 else ""
     if self._use_timestamp:
         _fmt = "%H:%M:%S.%f" if self._use_ms else "%H:%M:%S"
         date_str = datetime.now().strftime(_fmt)
         date_str = cstr(f"[{date_str}] ", Color.DarkGrey)
     return date_str + cstr(f"({self.log_prefix})",
                            self._log_prefix_color) + prefix2_str
Esempio n. 6
0
 def print(self):
     print("Title:", cstr(self.title, "lgreen"))
     print("Lang:", cstr(self.language.name, "lgreen"))
     print("URL: ", cstr(self.url, "lgreen"))
     sim_color = "lgreen"
     if self.similarity < 1:
         sim_color = "lyellow"
     elif self.similarity < 0.7:
         sim_color = "orange"
     elif self.similarity < 0.5:
         sim_color = "red"
     print("Similarity:", cstr(self.similarity, sim_color))
Esempio n. 7
0
 def export_latest_added(self):
     _path = ConfigurationManager().path("film",
                                         convert_to_path=True,
                                         assert_path_exists=True)
     if _path is None:
         print(cstr("could not retrieve path to \"film\"", Color.Error))
         return
     _path = _path / "latest.txt"
     last_added = self.last_added(num=1000)
     last_added_text = [_to_text(m, last_added[m]) for m in last_added]
     try:
         with open(_path, "w") as _fp:
             _fp.writelines(last_added_text)
         print(f"wrote to {cstr(str(_path), Color.LightGreen)}")
     except Exception as _:
         print(cstr("could not save latest.txt", Color.Error))
Esempio n. 8
0
 def show_list(self, one_line: bool = False):
     se_str = f"S{self.season:02d}E{self.episode:02d}"
     subs_str = "subs: "
     for sub in SubtitleLang:
         has = sub in self.subs
         if sub == SubtitleLang.Unknown:
             if has:
                 subs_str += cstr(sub.value + " ", Color.LightYellow)
             continue
         subs_str += cstr(sub.value + " ",
                          Color.LightGreen if has else Color.DarkGrey)
     _output = fcs(f"  i[{self.filename: <{self.row_len}}]")
     if not one_line:
         _output += "\n     "
     _output += fcs(f" b[{se_str}] {subs_str}")
     print(_output, end=" " if one_line and self.extras else "\n")
     if self.extras:
         self.print_extras(only_airdate=one_line)
Esempio n. 9
0
 def print_extras(self, only_airdate: bool = False):
     from db_tv import EpisodeDatabaseSingleton, ShowDatabaseSingleton
     maze_id = EpisodeDatabaseSingleton().get_id(self.filename)
     show_maze_id = ShowDatabaseSingleton().get_id(self.show_name)
     ep_maze_data = {}
     for entry in TvMazeData().get_json_all_episodes(show_maze_id):
         if entry.get("season", 0) == self.season and entry.get(
                 "number", 0) == self.episode:
             ep_maze_data = entry
             break
     aired_str = "aired: " + cstr(ep_maze_data.get("airdate"),
                                  Color.LightBlue)
     if only_airdate:
         print(aired_str)
         return
     id_str = "id: " + cstr(f"{maze_id}",
                            Color.LightBlue) if maze_id is not None else ""
     name_str = "\"" + cstr(ep_maze_data.get("name"),
                            Color.LightBlue) + "\""
     print(f"      {name_str} {id_str} {aired_str}")
Esempio n. 10
0
 def download_and_unzip(self, file_dest=None):
     if file_dest is None:
         if self.language == Language.Swedish:
             ext = ".sv.zip"
         elif self.language == Language.English:
             ext = ".en.zip"
         else:
             ext = ".zip"
         file_dest = Path(tempfile.gettempdir()) / (self.release + ext)
     res = requests.get(self.url)
     soup = BeautifulSoup(res.text, "html.parser")
     zip_url = soup.find("div", "download").a.get("href")
     if self.url_zip is None:
         self.url_zip = self.BASE_URL + zip_url
     self.log("downloading", info_str_line2=cstr(self.url_zip, "orange"))
     if not run.wget(self.url_zip, file_dest, debug_print=self.verbose):
         self.error("download failed!")
         return None
     self.log("downloaded to", cstr(file_dest, "lgreen"))
     extracted_srts = []
     with zipfile.ZipFile(file_dest) as zf:
         for i in zf.infolist():
             if i.filename.endswith(".srt"):
                 extracted_srts.append(
                     zf.extract(i, path=tempfile.gettempdir()))
     if len(extracted_srts) > 1:
         self.warn("found more than one srt in zip! using first")
     elif not extracted_srts:
         self.warn("could not extract any srt files!")
         return None
     extracted = Path(extracted_srts[0])
     self.log(f"extracted file:", cstr(extracted, "lgreen"))
     dest = file_dest.with_suffix(".srt")
     if not run.rename_file(extracted, dest):
         self.error("failed to rename extracted file!")
     self.log(f"renamed to:", cstr(dest, "lgreen"))
     return dest
Esempio n. 11
0
def wb_list_items(items):
    "Lists items on server"
    len_without_itemname = 45
    item_len = len(items)
    for item in items:
        index = f'#{item["index"]:02d}'
        media_type = determine_release_type(item["name"]).strshort
        item_str_color = "orange"
        if item["downloaded"]:
            item_str_color = "lgreen"
        item_name = cstr(item["name"], item_str_color)
        # Right trim filename strings if to prevent multiple lines in terminal window
        if len_without_itemname + len(
                item["name"]) + 1 > util.terminal_width():
            diff = abs(util.terminal_width() - len_without_itemname -
                       len(item["name"]) - 1)
            trimmed_item_name = util.shorten_string(item["name"],
                                                    len(item["name"]) - diff)
            item_name = cstr(trimmed_item_name, item_str_color)
        print(
            f'[{cstr(index, item_str_color)}] (-{item_len:03d}) {item["date"]} '
            f'{item["size"]:>10} ({media_type}) '
            f"[{item_name}]")
        item_len -= 1
Esempio n. 12
0
def main():
    args = get_cli_args()
    if args.command in ["list", "new"]:
        wb_list_items(ls_remote_items(args.filter, server=args.server))
    elif args.command in ["download", "get"]:
        items = ls_remote_items(args.filter,
                                use_cached_if_new=True,
                                server=args.server)
        wb_download_items(items,
                          args.get,
                          args.extract,
                          server=args.server,
                          limit=args.limit)
    elif args.command == "send":
        wb_scp_torrents()
    else:
        print(cstr("wrong command!", "orange"))
Esempio n. 13
0
 def _print_data(self, title_str, data):
     if not data:
         return
     print(cstr(f" {title_str}:".ljust(10, " "), Color.DarkGrey), data)
Esempio n. 14
0
 def set_log_prefix_2(self, log_prefix: str, color=Color.DarkGrey):
     self._log_prefix2 = cstr(log_prefix, color)
Esempio n. 15
0
def date_to_full_color_str(datetime_obj: datetime):
    date_str = datetime_obj.strftime(r"%Y-%m-%d")
    time_str = datetime_obj.strftime(r"%T")
    return cstr(date_str, 166) + " " + cstr(time_str, 170)