coursera-dl/edx-dl

View on GitHub

Showing 31 of 31 total issues

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

    File parsing.py has 320 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    # -*- coding: utf-8 -*-
    
    """
    Parsing and extraction functions
    """
    Severity: Minor
    Found in edx_dl/parsing.py - About 3 hrs to fix

      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

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

              sections = [Section(position=i,
                                  name=_get_section_name(section_soup),
                                  url=_make_url(section_soup),
                                  subsections=_make_subsections(section_soup))
                          for i, section_soup in enumerate(sections_soup, 1)]
      Severity: Major
      Found in edx_dl/parsing.py and 2 other locations - About 1 hr to fix
      edx_dl/parsing.py on lines 226..230
      edx_dl/parsing.py on lines 349..353

      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 48.

      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

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

              sections = [Section(position=i,
                                  name=_get_section_name(section_soup),
                                  url=_make_url(section_soup),
                                  subsections=_make_subsections(section_soup))
                          for i, section_soup in enumerate(sections_soup, 1)]
      Severity: Major
      Found in edx_dl/parsing.py and 2 other locations - About 1 hr to fix
      edx_dl/parsing.py on lines 349..353
      edx_dl/parsing.py on lines 399..403

      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 48.

      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

      class Section(object):
          """
          Representation of a section of the course.
          """
          def __init__(self, position, name, url, subsections):
      Severity: Major
      Found in edx_dl/common.py and 1 other location - About 1 hr to fix
      edx_dl/common.py on lines 135..157

      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 48.

      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

      Identical blocks of code found in 3 locations. Consider refactoring.
      Open

              sections = [Section(position=i,
                                  name=_get_section_name(section_soup),
                                  url=_make_url(section_soup),
                                  subsections=_make_subsections(section_soup))
                          for i, section_soup in enumerate(sections_soup, 1)]
      Severity: Major
      Found in edx_dl/parsing.py and 2 other locations - About 1 hr to fix
      edx_dl/parsing.py on lines 226..230
      edx_dl/parsing.py on lines 399..403

      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 48.

      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

      class Video(object):
          """
          Representation of a single video.
          """
          def __init__(self, video_youtube_url, available_subs_url,
      Severity: Major
      Found in edx_dl/common.py and 1 other location - About 1 hr to fix
      edx_dl/common.py on lines 68..91

      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 48.

      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

      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 extract_courses_from_html has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def extract_courses_from_html(self, page, BASE_URL):
                  """
                  Extracts courses (Course) from the html page
                  """
                  soup = BeautifulSoup(page)
          Severity: Minor
          Found in edx_dl/parsing.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 _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 extract_sections_from_html has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def extract_sections_from_html(self, page, BASE_URL):
                        """
                        Extract sections (Section->SubSection) from the html page
                        """
                        def _make_url(section_soup):  # FIXME: Extract from here and test
                Severity: Minor
                Found in edx_dl/parsing.py - About 35 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

                Severity
                Category
                Status
                Source
                Language