From 732044afb2e8ffbaa37fe91310906ff549edd6ad Mon Sep 17 00:00:00 2001 From: pukkandan Date: Tue, 27 Oct 2020 16:07:21 +0530 Subject: Add --write-*-link by h-h-h-h Authored-by: h-h-h-h --- youtube_dlc/utils.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 68b4ca944..d814eb2ac 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -60,6 +60,9 @@ from .compat import ( compat_urllib_parse, compat_urllib_parse_urlencode, compat_urllib_parse_urlparse, + compat_urllib_parse_urlunparse, + compat_urllib_parse_quote, + compat_urllib_parse_quote_plus, compat_urllib_parse_unquote_plus, compat_urllib_request, compat_urlparse, @@ -5714,3 +5717,81 @@ def random_birthday(year_field, month_field, day_field): month_field: str(random_date.month), day_field: str(random_date.day), } + +# Templates for internet shortcut files, which are plain text files. +DOT_URL_LINK_TEMPLATE = ''' +[InternetShortcut] +URL=%(url)s +'''.lstrip() + +DOT_WEBLOC_LINK_TEMPLATE = ''' + + + + +\tURL +\t%(url)s + + +'''.lstrip() + +DOT_DESKTOP_LINK_TEMPLATE = ''' +[Desktop Entry] +Encoding=UTF-8 +Name=%(filename)s +Type=Link +URL=%(url)s +Icon=text-html +'''.lstrip() + + +def iri_to_uri(iri): + """ + Converts an IRI (Internationalized Resource Identifier, allowing Unicode characters) to a URI (Uniform Resource Identifier, ASCII-only). + + The function doesn't add an additional layer of escaping; e.g., it doesn't escape `%3C` as `%253C`. Instead, it percent-escapes characters with an underlying UTF-8 encoding *besides* those already escaped, leaving the URI intact. + """ + + iri_parts = compat_urllib_parse_urlparse(iri) + + if '[' in iri_parts.netloc: + raise ValueError('IPv6 URIs are not, yet, supported.') + # Querying `.netloc`, when there's only one bracket, also raises a ValueError. + + # The `safe` argument values, that the following code uses, contain the characters that should not be percent-encoded. Everything else but letters, digits and '_.-' will be percent-encoded with an underlying UTF-8 encoding. Everything already percent-encoded will be left as is. + + net_location = '' + if iri_parts.username: + net_location += compat_urllib_parse_quote(iri_parts.username, safe=r"!$%&'()*+,~") + if iri_parts.password is not None: + net_location += ':' + compat_urllib_parse_quote(iri_parts.password, safe=r"!$%&'()*+,~") + net_location += '@' + + net_location += iri_parts.hostname.encode('idna').decode('utf-8') # Punycode for Unicode hostnames. + # The 'idna' encoding produces ASCII text. + if iri_parts.port is not None and iri_parts.port != 80: + net_location += ':' + str(iri_parts.port) + + return compat_urllib_parse_urlunparse( + (iri_parts.scheme, + net_location, + + compat_urllib_parse_quote_plus(iri_parts.path, safe=r"!$%&'()*+,/:;=@|~"), + + # Unsure about the `safe` argument, since this is a legacy way of handling parameters. + compat_urllib_parse_quote_plus(iri_parts.params, safe=r"!$%&'()*+,/:;=@|~"), + + # Not totally sure about the `safe` argument, since the source does not explicitly mention the query URI component. + compat_urllib_parse_quote_plus(iri_parts.query, safe=r"!$%&'()*+,/:;=?@{|}~"), + + compat_urllib_parse_quote_plus(iri_parts.fragment, safe=r"!#$%&'()*+,/:;=?@{|}~"))) + + # Source for `safe` arguments: https://url.spec.whatwg.org/#percent-encoded-bytes. + + +def to_high_limit_path(path): + if sys.platform in ['win32', 'cygwin']: + # Work around MAX_PATH limitation on Windows. The maximum allowed length for the individual path segments may still be quite limited. + return r'\\?\ '.rstrip() + os.path.abspath(path) + + return path -- cgit v1.2.3 From 76d321f68f412a5d07a7dfb9ad0c1c9f5513b13a Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 13 Dec 2020 19:59:09 +0530 Subject: Option to present -F output to a more tabular form --- youtube_dlc/utils.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index d814eb2ac..8c2c377af 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -4315,11 +4315,25 @@ def determine_protocol(info_dict): return compat_urllib_parse_urlparse(url).scheme -def render_table(header_row, data): +def render_table(header_row, data, delim=False, extraGap=0, hideEmpty=False): """ Render a list of rows, each as a list of values """ + + def get_max_lens(table): + return [max(len(compat_str(v)) for v in col) for col in zip(*table)] + + def filter_using_list(row, filterArray): + return [col for (take, col) in zip(filterArray, row) if take] + + if hideEmpty: + max_lens = get_max_lens(data) + header_row = filter_using_list(header_row, max_lens) + data = [filter_using_list(row, max_lens) for row in data] + table = [header_row] + data - max_lens = [max(len(compat_str(v)) for v in col) for col in zip(*table)] - format_str = ' '.join('%-' + compat_str(ml + 1) + 's' for ml in max_lens[:-1]) + '%s' + max_lens = get_max_lens(table) + if delim: + table = [header_row] + [['-' * ml for ml in max_lens]] + data + format_str = ' '.join('%-' + compat_str(ml + extraGap) + 's' for ml in max_lens[:-1]) + ' %s' return '\n'.join(format_str % tuple(row) for row in table) @@ -5795,3 +5809,9 @@ def to_high_limit_path(path): return r'\\?\ '.rstrip() + os.path.abspath(path) return path + +def format_field(obj, field, template='%s', ignore=(None, ''), default='', func=None): + val = obj.get(field, default) + if func and val not in ignore: + val = func(val) + return template % val if val not in ignore else default -- cgit v1.2.3 From 29f7c58aafb25a094e267a8a3fb355e102e42792 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Fri, 1 Jan 2021 17:56:37 +0530 Subject: Update to ytdl-2021.01.03 --- youtube_dlc/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 8c2c377af..bc41f5498 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -3650,7 +3650,7 @@ def url_or_none(url): if not url or not isinstance(url, compat_str): return None url = url.strip() - return url if re.match(r'^(?:[a-zA-Z][\da-zA-Z.+-]*:)?//', url) else None + return url if re.match(r'^(?:(?:https?|rt(?:m(?:pt?[es]?|fp)|sp[su]?)|mms|ftps?):)?//', url) else None def parse_duration(s): -- cgit v1.2.3 From 91ebc64068d2957400dbfaadff23e995392b3963 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 4 Jan 2021 22:10:47 +0530 Subject: Change defaults * Enabled --ignore by default * Disabled --video-multistreams and --audio-multistreams by default * Changed default format selection to 'bv*+ba/b' when --audio-multistreams is disabled * Changed default format sort order to 'res,fps,codec,size,br,asr,proto,ext,has_audio,source,format_id' * Changed default output template to '%(title)s [%(id)s].%(ext)s' * Enabled `--list-formats-as-table` by default --- youtube_dlc/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index bc41f5498..7a2ba9ebd 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -4128,7 +4128,7 @@ def qualities(quality_ids): return q -DEFAULT_OUTTMPL = '%(title)s-%(id)s.%(ext)s' +DEFAULT_OUTTMPL = '%(title)s [%(id)s].%(ext)s' def limit_length(s, length): -- cgit v1.2.3 From 735d865ece8801c146e368eef3723b5a3f14e490 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 6 Jan 2021 17:28:30 +0530 Subject: Disable Updates --- youtube_dlc/utils.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 7a2ba9ebd..6ed8629a7 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -4156,6 +4156,8 @@ def is_outdated_version(version, limit, assume_new=True): def ytdl_is_updateable(): """ Returns if youtube-dlc can be updated with -U """ + return False + from zipimport import zipimporter return isinstance(globals().get('__loader__'), zipimporter) or hasattr(sys, 'frozen') -- cgit v1.2.3 From dbbbe555d7a64ff65de5f8a78cc276a848c2e227 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 6 Jan 2021 22:37:55 +0530 Subject: Add `duration_string` to info_dict --- youtube_dlc/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 6ed8629a7..21e3481a0 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -2285,11 +2285,11 @@ def decodeOption(optval): return optval -def formatSeconds(secs): +def formatSeconds(secs, delim=':'): if secs > 3600: - return '%d:%02d:%02d' % (secs // 3600, (secs % 3600) // 60, secs % 60) + return '%d%s%02d%s%02d' % (secs // 3600, delim, (secs % 3600) // 60, delim, secs % 60) elif secs > 60: - return '%d:%02d' % (secs // 60, secs % 60) + return '%d%s%02d' % (secs // 60, delim, secs % 60) else: return '%d' % secs -- cgit v1.2.3 From c76eb41bb9e7e0a106ce44f4afcf74b0c00a3fb2 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 7 Jan 2021 12:11:05 +0530 Subject: Preparing for release --- youtube_dlc/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'youtube_dlc/utils.py') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index 21e3481a0..6a04b710e 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -2323,8 +2323,8 @@ def bug_reports_message(): if ytdl_is_updateable(): update_cmd = 'type youtube-dlc -U to update' else: - update_cmd = 'see https://github.com/blackjack4494/yt-dlc on how to update' - msg = '; please report this issue on https://github.com/blackjack4494/yt-dlc .' + update_cmd = 'see https://github.com/pukkandan/yt-dlc on how to update' + msg = '; please report this issue on https://github.com/pukkandan/yt-dlc .' msg += ' Make sure you are using the latest version; %s.' % update_cmd msg += ' Be sure to call youtube-dlc with the --verbose flag and include its complete output.' return msg @@ -5734,6 +5734,7 @@ def random_birthday(year_field, month_field, day_field): day_field: str(random_date.day), } + # Templates for internet shortcut files, which are plain text files. DOT_URL_LINK_TEMPLATE = ''' [InternetShortcut] @@ -5812,6 +5813,7 @@ def to_high_limit_path(path): return path + def format_field(obj, field, template='%s', ignore=(None, ''), default='', func=None): val = obj.get(field, default) if func and val not in ignore: -- cgit v1.2.3