### nndownload CLI usage and options Source: https://github.com/alexaplin/nndownload/blob/master/README.md Shows the command-line usage and all available options for nndownload. Includes deprecated authentication flags and download options. ```text usage: nndownload.py [options] input positional arguments: input URLs or files options: -h, --help show this help message and exit -u EMAIL/TEL, --username EMAIL/TEL account email address or telephone number (deprecated; use --cookies-from-browser or --session-cookie) -p PASSWORD, --password PASSWORD account password (deprecated; use --cookies-from-browser or --session-cookie) --session-cookie COOKIE user_session cookie value (string or filepath) --cookies-from-browser BROWSER[+KEYRING][:PROFILE][::CONTAINER] browser session to load a user_session cookie from -n, --netrc use .netrc authentication (deprecated; use --cookies-from-browser or --session-cookie) -q, --quiet suppress output to console -l [PATH], --log [PATH] log output to file -v, --version show program's version number and exit download options: -y PROXY, --proxy PROXY HTTP or SOCKS proxy -o TEMPLATE, --output-path TEMPLATE custom output path (see template options) -r N, --threads N download videos using a specified number of threads -g, --no-login create a download session without logging in -f, --force-high-quality only download if the high quality video source is available -a, --add-metadata add metadata to video file (MP4 only) -m, --dump-metadata dump metadata to file -t, --download-thumbnail download video thumbnail -c, --download-comments download video comments --comments-limit N number of comments to download per thread (default: 1000) --comments-from DATETIME_OR_TIMESTAMP only download comments posted before a specified time: - Unix timestamp (e.g., 1686787200) - ISO 8601 date (e.g., '2023-06-15' → sets to 23:59:59) - ISO 8601 datetime (e.g., '2023-06-15T14:30:00' or '2023-06-15 14:30:00') --all-comments request all comments (ignores --comments-limit) -e, --english request video on english site --chinese request video on traditional chinese (taiwan) site -aq AUDIO_QUALITY, --audio-quality AUDIO_QUALITY specify audio quality -vq VIDEO_QUALITY, --video-quality VIDEO_QUALITY specify video quality -an, --no-audio don't download audio -vn, --no-video don't download video -Q, --list-qualities list video and audio qualities with availability status -s, --skip-media skip downloading media --break-on-existing break after encountering an existing download --playlist-start N specify the index to start a list of items from (begins at 0) --user-agent USER_AGENT specify a custom user agent for the download session ``` -------------------------------- ### 使用 nndownload 模块 Source: https://github.com/alexaplin/nndownload/blob/master/README_ZH-CN.md 在 Python 中导入 nndownload 并调用 execute 函数,传入命令行参数。示例中指定了 -g(不登录)和自定义输出路径。 ```python import nndownload url = "https://www.nicovideo.jp/watch/sm35249846" output_path = "/tmp/{id}.{ext}" nndownload.execute("-g", "-o", output_path, url) ``` -------------------------------- ### 使用流链接播放 Source: https://github.com/alexaplin/nndownload/blob/master/README_ZH-CN.md 生成流 URL 后,使用 mpv 或 streamlink 播放。程序必须保持运行以保持流活跃。 ```bash mpv https://... ``` ```bash streamlink https://... best ``` -------------------------------- ### Module: nndownload.execute() Source: https://github.com/alexaplin/nndownload/blob/master/README.md Python function to execute downloads programmatically. Accepts command-line arguments as a list and returns the result of the download operation. ```APIDOC ## [Python] nndownload.execute() ### Description Python function to execute downloads programmatically. Accepts command-line arguments as a list and returns the result of the download operation. ### Method `execute(*args)` ### Parameters - **args** (list of strings) - Required - Command-line arguments to pass to the downloader (e.g., `"-g", "-o", output_path, url`) ### Example ```python import nndownload url = "https://www.nicovideo.jp/watch/sm35249846" output_path = "/tmp/{id}.{ext}" nndownload.execute("-g", "-o", output_path, url) ``` ``` -------------------------------- ### CLI: nndownload.py Source: https://github.com/alexaplin/nndownload/blob/master/README.md Command-line interface for downloading videos, images, manga, and articles from NicoNico. Supports various options for authentication, download quality, metadata, and output customization. ```APIDOC ## [CLI] nndownload.py ### Description Command-line interface for downloading videos, images, manga, and articles from NicoNico. Supports various options for authentication, download quality, metadata, and output customization. ### Usage ``` usage: nndownload.py [options] input ``` ### Positional Arguments - **input** (string) - Required - URLs or files ### Options - `-h, --help` - Show this help message and exit - `-u EMAIL/TEL, --username EMAIL/TEL` - Account email address or telephone number (deprecated; use --cookies-from-browser or --session-cookie) - `-p PASSWORD, --password PASSWORD` - Account password (deprecated; use --cookies-from-browser or --session-cookie) - `--session-cookie COOKIE` - user_session cookie value (string or filepath) - `--cookies-from-browser BROWSER[+KEYRING][:PROFILE][::CONTAINER]` - Browser session to load a user_session cookie from - `-n, --netrc` - Use .netrc authentication (deprecated; use --cookies-from-browser or --session-cookie) - `-q, --quiet` - Suppress output to console - `-l [PATH], --log [PATH]` - Log output to file - `-v, --version` - Show program's version number and exit ### Download Options - `-y PROXY, --proxy PROXY` - HTTP or SOCKS proxy - `-o TEMPLATE, --output-path TEMPLATE` - Custom output path (see template options) - `-r N, --threads N` - Download videos using a specified number of threads - `-g, --no-login` - Create a download session without logging in - `-f, --force-high-quality` - Only download if the high quality video source is available - `-a, --add-metadata` - Add metadata to video file (MP4 only) - `-m, --dump-metadata` - Dump metadata to file - `-t, --download-thumbnail` - Download video thumbnail - `-c, --download-comments` - Download video comments - `--comments-limit N` - Number of comments to download per thread (default: 1000) - `--comments-from DATETIME_OR_TIMESTAMP` - Only download comments posted before a specified time: Unix timestamp (e.g., 1686787200), ISO 8601 date (e.g., '2023-06-15' → sets to 23:59:59), ISO 8601 datetime (e.g., '2023-06-15T14:30:00' or '2023-06-15 14:30:00') - `--all-comments` - Request all comments (ignores --comments-limit) - `-e, --english` - Request video on english site - `--chinese` - Request video on traditional chinese (taiwan) site - `-aq AUDIO_QUALITY, --audio-quality AUDIO_QUALITY` - Specify audio quality - `-vq VIDEO_QUALITY, --video-quality VIDEO_QUALITY` - Specify video quality - `-an, --no-audio` - Don't download audio - `-vn, --no-video` - Don't download video - `-Q, --list-qualities` - List video and audio qualities with availability status - `-s, --skip-media` - Skip downloading media - `--break-on-existing` - Break after encountering an existing download - `--playlist-start N` - Specify the index to start a list of items from (begins at 0) - `--user-agent USER_AGENT` - Specify a custom user agent for the download session ### Example ```bash nndownload.py -g -o "/tmp/{id}.{ext}" https://www.nicovideo.jp/watch/sm35249846 ``` ``` -------------------------------- ### 命令行接口(CLI)用法 Source: https://github.com/alexaplin/nndownload/blob/master/README_ZH-CN.md 显示 nndownload 的命令行选项。输入可以是 URL 或文件。 ```text 用法: nndownload.py [选项] 输入 位置参数: 输入 URLs 或文件 选项: -h, --help 显示此帮助信息并退出 -u EMAIL/TEL, --username EMAIL/TEL 账户电子邮件地址或电话号码 -p PASSWORD, --password PASSWORD 账户密码 --session-cookie COOKIE 用户会话 cookie 值(字符串或文件路径) -n, --netrc 使用.netrc 身份验证 -q, --quiet 抑制控制台输出 -l [PATH], --log [PATH] 将输出日志记录到文件 -v, --version 显示程序的版本号并退出 下载选项: -y PROXY, --proxy PROXY http 或 socks 代理 -o TEMPLATE, --output-path TEMPLATE 自定义输出路径(请参见模板选项) -r N, --threads N 使用指定数量的线程下载视频 -g, --no-login 创建不登录的下载会话 -f, --force-high-quality 仅在高质量视频源可用时下载 -a, --add-metadata 向视频文件添加元数据(仅限 MP4) -m, --dump-metadata 将元数据输出到文件 -t, --download-thumbnail 下载视频缩略图 -c, --download-comments 下载视频评论 --comments-limit N 每个线程下载的评论数(默认值:1000) --comments-from DATETIME_OR_TIMESTAMP 仅下载在指定时间之前发布的评论: - Unix 时间戳(例如 1686787200) - ISO 8601 日期(例如 '2023-06-15' → 设置为 23:59:59) - ISO 8601 日期时间(例如 '2023-06-15T14:30:00' 或 '2023-06-15 14:30:00') --all-comments 请求所有评论(忽略 --comments-limit) -e, --english 请求英语网站上的视频 --chinese 请求繁体中文(台湾)网站上的视频 -aq AUDIO_QUALITY, --audio-quality AUDIO_QUALITY 指定音频质量 -vq VIDEO_QUALITY, --video-quality VIDEO_QUALITY 指定视频质量 -an, --no-audio 不下载音频 -vn, --no-video 不下载视频 -Q, --list-qualities 列出视频和音频质量及可用状态 -s, --skip-media 跳过下载媒体 --break-on-existing 在遇到已存在下载后停止 --playlist-start N 指定从列表中开始的项的索引(从 0 开始) --user-agent USER_AGENT 为下载会话指定自定义用户代理 ``` -------------------------------- ### Userscript constants and key handling Source: https://github.com/alexaplin/nndownload/wiki/Browser-helper-scripts Defines a regex for Nicovideo URLs and a key code alias map, then tracks key states and clears a download queue when a shortcut is pressed. ```javascript // Constants const regex = new RegExp("https?://(((ch|sp|www|seiga|live|cas)\.)((nicovideo\.jp/)(watch|mylist|user\/illust|user\/manga|user|comic|seiga|gate|article|channel|manga|illust))/|(nico\.ms)/)([a-zA-Z0-9-]+?)"); const alias = { "": 0, "": 1, "": 2, "CANCEL": 3, "": 4, "": 5, "HELP": 6, "": 7, "BACK_SPACE": 8, "TAB": 9, "": 10, "": 11, "CLEAR": 12, "ENTER": 13, "ENTER_SPECIAL": 14, "": 15, "SHIFT": 16, "CONTROL": 17, "ALT": 18, "PAUSE": 19, "CAPS_LOCK": 20, "KANA": 21, "EISU": 22, "JUNJA": 23, "FINAL": 24, "HANJA": 25, "": 26, "ESCAPE": 27, "CONVERT": 28, "NONCONVERT": 29, "ACCEPT": 30, "MODECHANGE": 31, "SPACE": 32, "PAGE_UP": 33, "PAGE_DOWN": 34, "END": 35, "HOME": 36, "LEFT": 37, "UP": 38, "RIGHT": 39, "DOWN": 40, "SELECT": 41, "PRINT": 42, "EXECUTE": 43, "PRINTSCREEN": 44, "INSERT": 45, "DELETE": 46, "": 47, "0": 48, "1": 49, "2": 50, "3": 51, "4": 52, "5": 53, "6": 54, "7": 55, "8": 56, "9": 57, "COLON": 58, "SEMICOLON": 59, "LESS_THAN": 60, "EQUALS": 61, "GREATER_THAN": 62, "QUESTION_MARK": 63, "AT": 64, "A": 65, "B": 66, "C": 67, "D": 68, "E": 69, "F": 70, "G": 71, "H": 72, "I": 73, "J": 74, "K": 75, "L": 76, "M": 77, "N": 78, "O": 79, "P": 80, "Q": 81, "R": 82, "S": 83, "T": 84, "U": 85, "V": 86, "W": 87, "X": 88, "Y": 89, "Z": 90, "OS_KEY": 91, "": 92, "CONTEXT_MENU": 93, "": 94, "SLEEP": 95, "NUMPAD0": 96, "NUMPAD1": 97, "NUMPAD2": 98, "NUMPAD3": 99, "NUMPAD4": 100, "NUMPAD5": 101, "NUMPAD6": 102, "NUMPAD7": 103, "NUMPAD8": 104, "NUMPAD9": 105, "MULTIPLY": 106, "ADD": 107, "SEPARATOR": 108, "SUBTRACT": 109, "DECIMAL": 110, "DIVIDE": 111, "F1": 112, "F2": 113, "F3": 114, "F4": 115, "F5": 116, "F6": 117, "F7": 118, "F8": 119, "F9": 120, "F10": 121, "F11": 122, "F12": 123, "F13": 124, "F14": 125, "F15": 126, "F16": 127, "F17": 128, "F18": 129, "F19": 130, "F20": 131, "F21": 132, "F22": 133, "F23": 134, "F24": 135, "": 136, "": 137, "": 138, "": 139, "": 140, "": 141, "": 142, "": 143, "NUM_LOCK": 144, "SCROLL_LOCK": 145, "WIN_OEM_FJ_JISHO": 146, "WIN_OEM_FJ_MASSHOU": 147, "WIN_OEM_FJ_TOUROKU": 148, "WIN_OEM_FJ_LOYA": 149, "WIN_OEM_FJ_ROYA": 150, "": 151, "": 152, "": 153, "": 154, "": 155, "": 156, "": 157, "": 158, "": 159, "CIRCUMFLEX": 160, "EXCLAMATION": 161, "DOUBLE_QUOTE": 162, "HASH": 163, "DOLLAR": 164, "PERCENT": 165, "AMPERSAND": 166, "UNDERSCORE": 167, "OPEN_PAREN": 168, "CLOSE_PAREN": 169, "ASTERISK": 170, "PLUS": 171, "PIPE": 172, "HYPHEN_MINUS": 173, "OPEN_CURLY_BRACKET": 174, "CLOSE_CURLY_BRACKET": 175, "TILDE": 176, "": 177, "": 178, "": 179, "": 180, "VOLUME_MUTE": 181, "VOLUME_DOWN": 182, "VOLUME_UP": 183, "": 184, "": 185, "SEMICOLON": 186, "EQUALS": 187, "COMMA": 188, "MINUS": 189, "PERIOD": 190, "SLASH": 191, "BACK_QUOTE": 192, "": 193, "": 194, "": 195, "": 196, "": 197, "": 198, "": 199, "": 200, "": 201, "": 202, "": 203, "": 204, "": 205, "": 206, "": 207, "": 208, "": 209, "": 210, "": 211, "": 212, "": 213, "": 214, "": 215, "": 216, "": 217, "": 218, "OPEN_BRACKET": 219, "BACK_SLASH": 220, "CLOSE_BRACKET": 221, "QUOTE": 222, "": 223, "META": 224, "ALTGR": 225, "": 226, "WIN_ICO_HELP": 227, "WIN_ICO_00": 228, "": 229, "WIN_ICO_CLEAR": 230, "": 231, "": 232, "WIN_OEM_RESET": 233, "WIN_OEM_JUMP": 234, "WIN_OEM_PA1": 235, "WIN_OEM_PA2": 236, "WIN_OEM_PA3": 237, "WIN_OEM_WSCTRL": 238, "WIN_OEM_CUSEL": 239, "WIN_OEM_ATTN": 240, "WIN_OEM_FINISH": 241, "WIN_OEM_COPY": 242, "WIN_OEM_AUTO": 243, "WIN_OEM_ENLW": 244, "WIN_OEM_BACKTAB": 245, "ATTN": 246, "CRSEL": 247, "EXSEL": 248, "EREOF": 249, "PLAY": 250, "ZOOM": 251, "": 252, "PA1": 253, "WIN_OEM_CLEAR": 254, "": 255 }; ``` ```javascript //functions var keys = {} function handleKeyPress(evt) { let { keyCode, type } = evt || Event; // to deal with IE let isKeyDown = (type == 'keydown'); keys[keyCode] = isKeyDown; if(isKeyDown && type == "D" && shortcut_delete_queue.map(i => keys[i]).every(Boolean)){ localStorage.setItem("nndownload-queue", Array()); } } ``` -------------------------------- ### 安装 nndownload Source: https://github.com/alexaplin/nndownload/blob/master/README_ZH-CN.md 使用 pip 安装 nndownload。需要 Python >=3.5.3,并且 ffmpeg 必须在 PATH 中可用。 ```bash pip install nndownload ``` -------------------------------- ### Batch file: Run download automatically Source: https://github.com/alexaplin/nndownload/wiki/Browser-helper-scripts Batch script that runs nndownload with the provided links. Modify the python command to suit your needs; %string:,= % expands to the links passed as arguments. ```batch @echo off set string=%* REM Modify the following commands according to your needs REM %string:,= % are the links to download python nndownload.py %string:,= % -u email@domain.com ``` -------------------------------- ### Userscript: nndownload helper Source: https://github.com/alexaplin/nndownload/wiki/Browser-helper-scripts Userscript that creates a list of links to download via nndownload. Requires the External Application Button extension and native-client. Includes configurable parameters for shortcuts and file name. ```javascript // ==UserScript== // @name nndownload helper // @namespace https://github.com/AlexAplin/nndownload // @description Create list of link to download via nndownload // @include * // @version 0.1 // @grant window.close // @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js // ==/UserScript== // Parameters const close_tab = true var shortcut_in_use = [67, 'A', 't'] /* same as ['C', 'A', 'T']*/ const type = "C"; var shortcut_delete_queue = ['a', 65, 'C'] /* same as ['A', 'B', 'C'], valid only if type == "C"*/ const name_file_to_download = "nicovideo links.txt"; const clear_queue = true; var shortcut_download_queue = ['a', 's', 'd'] /* same as ['A', 'B', 'C'], valid only if type == "C"*/ ``` -------------------------------- ### Userscript: Handle key press and queue management Source: https://github.com/alexaplin/nndownload/wiki/Browser-helper-scripts This snippet is part of a userscript that manages a download queue via keyboard shortcuts. It checks if the download queue shortcut is pressed and all required keys are held, then creates a Blob from the queue data and saves it using saveAs. It also handles adding the current URL to the queue when the in-use shortcut is pressed and the URL matches a regex, storing the queue in localStorage. The code includes key mapping for aliases and initializes the queue from localStorage. ```javascript if(isKeyDown && shortcut_download_queue.map(i => keys[i]).every(Boolean)){ console.log(Object.values(vis["data"]).join('\n')); var blob = new Blob([Object.values(vis["data"]).join('\n')], {type: "text/plain;charset=utf-8"}); saveAs(blob, name_file_to_download); Object.values(keys).map(x => false) if(clear_queue){localStorage.setItem("nndownload-queue", Array());} } if(isKeyDown && shortcut_in_use.map(i => keys[i]).every(Boolean) && regex.test(window.location.href)){ vis["data"][Object.keys(vis["data"]).length] = window.location.href; localStorage.setItem("nndownload-queue", JSON.stringify(vis)); console.log(vis["data"]); console.log(JSON.stringify(vis)); if(close_tab){window.close();} } }; ``` ```javascript //main shortcut_in_use = shortcut_in_use.map(function(e) { return Number.isInteger(e) ? e : alias[e.toUpperCase()]; }); shortcut_delete_queue = shortcut_delete_queue.map(function(e) { return Number.isInteger(e) ? e : alias[e.toUpperCase()]; }); shortcut_download_queue = shortcut_download_queue.map(function(e) { return Number.isInteger(e) ? e : alias[e.toUpperCase()]; }); var sto = localStorage.getItem("nndownload-queue") ? localStorage.getItem("nndownload-queue") : '{"data":{}}'; var vis = JSON.parse(sto); vis["data"] = !vis["data"] ? Array() : vis["data"]; window.addEventListener("keyup", handleKeyPress); window.addEventListener("keydown", handleKeyPress); ``` -------------------------------- ### Batch file: Save links to file Source: https://github.com/alexaplin/nndownload/wiki/Browser-helper-scripts Batch script that appends the first argument to a text file. Replace links.txt with your desired file name; %~dp0 is the path of the bat file folder. ```batch @echo off REM Replace links.txt with your desired file name REM %~dp0 is the path of the bat file folder change as needed if not exist "%~dp0links.txt" (copy NUL "%~dp0links.txt") echo %1 >> "%~dp0links.txt" exit ```