coursera-dl/edx-dl

View on GitHub
edx_dl/edx_dl.py

Summary

Maintainability
F
4 days
Test Coverage

File edx_dl.py has 841 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Main module for the edx-dl downloader.
Severity: Major
Found in edx_dl/edx_dl.py - About 2 days to fix

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

    def extract_urls_from_units(all_units, format_):
        """
        Extract urls from units into a set of strings. Format is specified by
        the user. The original purpose of this function is to export urls into
        a file for external downloader.
    Severity: Minor
    Found in edx_dl/edx_dl.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

    Function remove_repeated_urls has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def remove_repeated_urls(all_units):
        """
        Removes repeated urls from the units, it does not consider subtitles.
        This is done to avoid repeated downloads.
        """
    Severity: Minor
    Found in edx_dl/edx_dl.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 main has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        """
        Main program function
        """
        args = parse_args()
    Severity: Minor
    Found in edx_dl/edx_dl.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

    Function download_url has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def download_url(url, filename, headers, args):
        """
        Downloads the given url in filename.
        """
    
    
    Severity: Minor
    Found in edx_dl/edx_dl.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

    Function parse_args has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def parse_args():
        """
        Parse the arguments/options passed to the program on the command line.
        """
        parser = argparse.ArgumentParser(prog='edx-dl',
    Severity: Minor
    Found in edx_dl/edx_dl.py - About 1 hr to fix

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

      def download(args, selections, all_units, headers):
          """
          Downloads all the resources based on the selections
          """
          logging.info("Output directory: " + args.output_dir)
      Severity: Minor
      Found in edx_dl/edx_dl.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 isinstance(video, Video):
                              for url in video.mp4_urls:
                                  all_urls.add('%s\n' % (format_ % {'url': url}))
                          else:
                              raise TypeError('Unknown unit video type (%s) occured '
      Severity: Major
      Found in edx_dl/edx_dl.py - About 45 mins to fix

        Function _filter_sections has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def _filter_sections(index, sections):
            """
            Get the sections for the given index.
        
            If the index is not valid (that is, None, a non-integer, a negative
        Severity: Minor
        Found in edx_dl/edx_dl.py - About 45 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

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

        def extract_all_units_with_cache(all_urls, headers, file_formats,
        Severity: Minor
        Found in edx_dl/edx_dl.py - About 35 mins to fix

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

          def download_video(video, args, target_dir, filename_prefix, headers):
          Severity: Minor
          Found in edx_dl/edx_dl.py - About 35 mins to fix

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

            def download_unit(unit, args, target_dir, filename_prefix, headers):
            Severity: Minor
            Found in edx_dl/edx_dl.py - About 35 mins to fix

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

              def skip_or_download(downloads, headers, args, f=download_url):
                  """
                  downloads url into filename using download function f,
                  if filename exists it skips
                  """
              Severity: Minor
              Found in edx_dl/edx_dl.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

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

              def get_subtitles_urls(available_subs_url, sub_template_url, headers):
                  """
                  Request the available subs and builds the urls to download subs
                  """
                  if available_subs_url is not None and sub_template_url is not None:
              Severity: Minor
              Found in edx_dl/edx_dl.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

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

              def num_urls_in_units_dict(units_dict):
                  """
                  Counts the number of urls in a all_units dict, it ignores subtitles from
                  its counting.
                  """
              Severity: Minor
              Found in edx_dl/edx_dl.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

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

              def download_video(video, args, target_dir, filename_prefix, headers):
                  if args.prefer_cdn_videos or video.video_youtube_url is None:
                      mp4_downloads = _build_url_downloads(video.mp4_urls, target_dir,
                                                           filename_prefix)
                      skip_or_download(mp4_downloads, headers, args)
              Severity: Minor
              Found in edx_dl/edx_dl.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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                                  if isinstance(video, Video):
                                      for url in video.mp4_urls:
                                          all_urls.add('%s\n' % (format_ % {'url': url}))
              Severity: Minor
              Found in edx_dl/edx_dl.py and 1 other location - About 35 mins to fix
              edx_dl/edx_dl.py on lines 967..968

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 33.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                              for url in unit.resources_urls:
                                  all_urls.add('%s\n' % (format_ % {'url': url}))
              Severity: Minor
              Found in edx_dl/edx_dl.py and 1 other location - About 35 mins to fix
              edx_dl/edx_dl.py on lines 961..963

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 33.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status