mirror of
https://github.com/coursera-dl/coursera-dl.git
synced 2026-07-17 16:35:35 +00:00
Limit file name and extension length before downloading
This is a quick and dirty solution. We need to come up with something more general. related #488
This commit is contained in:
parent
00c3042b8f
commit
9d29d1d19e
2 changed files with 14 additions and 1 deletions
|
|
@ -70,7 +70,8 @@ from .cookies import (
|
|||
get_cookies_for_class, make_cookie_values, login, TLSAdapter)
|
||||
from .credentials import get_credentials, CredentialsError, keyring
|
||||
from .define import (CLASS_URL, ABOUT_URL, PATH_CACHE,
|
||||
OPENCOURSE_CONTENT_URL, IN_MEMORY_MARKER)
|
||||
OPENCOURSE_CONTENT_URL, IN_MEMORY_MARKER,
|
||||
FORMAT_MAX_LENGTH, TITLE_MAX_LENGTH)
|
||||
from .downloaders import get_downloader
|
||||
from .utils import (clean_filename, get_anchor_format, mkdir_p, fix_url,
|
||||
print_ssl_error_message, normalize_path,
|
||||
|
|
@ -622,6 +623,12 @@ def get_lecture_filename(combined_section_lectures_nums,
|
|||
@return: Lecture file name.
|
||||
@rtype: str
|
||||
"""
|
||||
# FIXME: this is a quick and dirty solution to Filename too long
|
||||
# problem. We need to think of a more general way to solve this
|
||||
# issue.
|
||||
fmt = fmt[:FORMAT_MAX_LENGTH]
|
||||
title = title[:TITLE_MAX_LENGTH]
|
||||
|
||||
# Format lecture file name
|
||||
if combined_section_lectures_nums:
|
||||
lecture_filename = os.path.join(
|
||||
|
|
|
|||
|
|
@ -152,6 +152,12 @@ IN_MEMORY_EXTENSION = 'html'
|
|||
#: field first.
|
||||
IN_MEMORY_MARKER = '#inmemory#'
|
||||
|
||||
#: These are hard limits for format (file extension) and
|
||||
#: title (file name) lengths to avoid too long file names
|
||||
#: (longer than 255 characters)
|
||||
FORMAT_MAX_LENGTH = 20
|
||||
TITLE_MAX_LENGTH = 200
|
||||
|
||||
#: CSS that is usen to prettify instructions
|
||||
INSTRUCTIONS_HTML_INJECTION = '''
|
||||
<style>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue