gpchelkin/scdlbot

View on GitHub
scdlbot/__main__.py

Summary

Maintainability
F
1 wk
Test Coverage

Function download_url_and_send has a Cognitive Complexity of 250 (exceeds 5 allowed). Consider refactoring.
Open

def download_url_and_send(
    bot_options,
    chat_id,
    url,
    flood=False,
Severity: Minor
Found in scdlbot/__main__.py - About 5 days to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File __main__.py has 1161 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python

import asyncio
import concurrent.futures
import datetime
Severity: Major
Found in scdlbot/__main__.py - About 2 days to fix

    Function get_direct_urls_dict has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_direct_urls_dict(message, mode, proxy, source_ip, allow_unknown_sites):
        # If telegram message passed:
        urls = []
        url_entities = message.parse_entities(types=[MessageEntity.URL])
        url_caption_entities = message.parse_caption_entities(types=[MessageEntity.URL])
    Severity: Minor
    Found in scdlbot/__main__.py - About 6 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function ydl_get_direct_urls has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def ydl_get_direct_urls(url, cookies_file=None, source_ip=None, proxy=None):
        # TODO transform into unified ydl function and deduplicate
        logger.debug("Entering: ydl_get_direct_urls: %s", url)
        status = ""
        cmd_name = "ydl_get_direct_urls"
    Severity: Minor
    Found in scdlbot/__main__.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Consider simplifying this complex logical expression.
    Open

            if mode == "link" or unknown_site:
                # We run it if it was explicitly requested as per "link" mode.
                # We run it for links from unknown sites (if they were allowed).
                # If it's known site, we need to check it more thoroughly below.
                urls_dict[url_text] = ydl_get_direct_urls(url_text, COOKIES_FILE, source_ip, proxy)
    Severity: Critical
    Found in scdlbot/__main__.py - About 3 hrs to fix

      Function get_link_text has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_link_text(urls):
          link_text = ""
          for i, url in enumerate(urls):
              link_text += "[Source Link #{}]({}) | `{}`\n".format(str(i + 1), url, URL(url).host)
              # TODO long link message split in many
      Severity: Minor
      Found in scdlbot/__main__.py - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function download_url_and_send has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def download_url_and_send(
      Severity: Major
      Found in scdlbot/__main__.py - About 1 hr to fix

        Function url_valid_and_allowed has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def url_valid_and_allowed(url, allow_unknown_sites=False):
            host = url.host
            if host in BLACKLIST_TELEGRAM_DOMAINS:
                return False
            if WHITELIST_DOMAINS:
        Severity: Minor
        Found in scdlbot/__main__.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Avoid deeply nested control flow statements.
        Open

                            if caption:
                                if caption_part:
                                    caption_full = caption_part + " | " + caption
                                else:
                                    caption_full = caption
        Severity: Major
        Found in scdlbot/__main__.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if "audio" in direct_url:
                                  content_type = "Audio"
                              else:
                                  content_type = "Video"
                          link_text += "• {} #{} [Direct Link]({})\n".format(content_type, str(idx + 1), direct_url)
          Severity: Major
          Found in scdlbot/__main__.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if DOMAIN_YT in host or DOMAIN_YT_BE in host:
                                    source = "YouTube"
                                    file_root, file_ext = os.path.splitext(file_name)
                                    file_title = file_root.replace(file_ext, "")
                                    addition = ": " + file_title
            Severity: Major
            Found in scdlbot/__main__.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  for i in range(retries):
                                      try:
                                          logger.debug(f"Trying {i+1} time to send file part: {file_part}")
                                          if file_part.endswith(".mp3"):
                                              mp3 = MP3(file_part)
              Severity: Major
              Found in scdlbot/__main__.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if direct_urls_status == "failed":
                                        await context.bot.send_message(chat_id=chat_id, reply_to_message_id=reply_to_message_id, text=FAILED_TEXT, parse_mode="Markdown")
                                    elif direct_urls_status == "timeout":
                                        await context.bot.send_message(chat_id=chat_id, reply_to_message_id=reply_to_message_id, text=DL_TIMEOUT_TEXT, parse_mode="Markdown")
                                    elif direct_urls_status == "restrict_direct":
                Severity: Major
                Found in scdlbot/__main__.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          with open(cookies_download_sqlite_path, "wb") as cfile:
                                              cfile.write(r.content)
                                          ydl_opts["cookiesfrombrowser"] = ("firefox", cookies_file_components[1], None, None)
                  Severity: Major
                  Found in scdlbot/__main__.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if len(file_parts) > 1:
                                            caption_part = "Part {} of {}".format(str(index + 1), str(len(file_parts)))
                                        if caption:
                    Severity: Major
                    Found in scdlbot/__main__.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                  for i in range(parts_number):
                                                      file_part = file.replace(file_ext, ".part{}{}".format(str(i + 1), file_ext))
                                                      ffinput = ffmpeg.input(file)
                                                      if i == (parts_number - 1):
                                                          ffmpeg.output(ffinput, file_part, codec="copy", vn=None, ss=cur_position).run()
                      Severity: Major
                      Found in scdlbot/__main__.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                            if add_description:
                                                caption += "\n\n" + add_description
                                            # logger.debug(caption)
                                            reply_to_message_id_send = reply_to_message_id
                        Severity: Major
                        Found in scdlbot/__main__.py - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  if file_size > MAX_CONVERT_FILE_SIZE:
                                                      raise FileTooLargeError(file_size)
                                                  logger.debug("Converting: %s", file)
                          Severity: Major
                          Found in scdlbot/__main__.py - About 45 mins to fix

                            Function get_direct_urls_dict has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            def get_direct_urls_dict(message, mode, proxy, source_ip, allow_unknown_sites):
                            Severity: Minor
                            Found in scdlbot/__main__.py - About 35 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                      return True
                              Severity: Major
                              Found in scdlbot/__main__.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return False
                                Severity: Major
                                Found in scdlbot/__main__.py - About 30 mins to fix

                                  Function chat_allowed has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  def chat_allowed(chat_id):
                                      if WHITELIST_CHATS:
                                          if chat_id not in WHITELIST_CHATS:
                                              return False
                                      if BLACKLIST_CHATS:
                                  Severity: Minor
                                  Found in scdlbot/__main__.py - About 25 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  There are no issues that match your filters.

                                  Category
                                  Status