├── scaner ├── __init__.py └── scaner.py ├── .gitattributes ├── screenshot.png ├── Letter_R_blue.ico ├── requirements.txt ├── scraper ├── langs │ ├── __init__.py │ ├── zh_cn.py │ ├── zh_tw.py │ ├── ja_jp.py │ ├── ko_kr.py │ └── en_us.py ├── locale.py ├── __init__.py ├── db.py ├── work_metadata.py ├── translation.py ├── cached_scraper.py ├── dlsite.py └── scraper.py ├── wx_log_handler.py ├── .gitignore ├── ostool.py ├── my_frame.py ├── config_file.py ├── README.md ├── main.py ├── renamer.py └── LICENSE /scaner/__init__.py: -------------------------------------------------------------------------------- 1 | from scaner.scaner import Scaner 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto eol=lf -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yodhcn/dlsite-doujin-renamer/HEAD/screenshot.png -------------------------------------------------------------------------------- /Letter_R_blue.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yodhcn/dlsite-doujin-renamer/HEAD/Letter_R_blue.ico -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yodhcn/dlsite-doujin-renamer/HEAD/requirements.txt -------------------------------------------------------------------------------- /scraper/langs/__init__.py: -------------------------------------------------------------------------------- 1 | from scraper.langs.en_us import EN_US 2 | from scraper.langs.ja_jp import JA_JP 3 | from scraper.langs.ko_kr import KO_KR 4 | from scraper.langs.zh_cn import ZH_CN 5 | from scraper.langs.zh_tw import ZH_TW 6 | -------------------------------------------------------------------------------- /scraper/locale.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | 4 | # 枚举类 - scraper 支持的语言 5 | class Locale(Enum): 6 | en_us = 'en_us' 7 | ja_jp = 'ja_jp' 8 | ko_kr = 'ko_kr' 9 | zh_cn = 'zh_cn' 10 | zh_tw = 'zh_tw' 11 | -------------------------------------------------------------------------------- /scraper/__init__.py: -------------------------------------------------------------------------------- 1 | from scraper.cached_scraper import CachedScraper 2 | from scraper.dlsite import Dlsite 3 | from scraper.locale import Locale 4 | from scraper.scraper import Scraper 5 | from scraper.work_metadata import WorkMetadata 6 | -------------------------------------------------------------------------------- /scraper/db.py: -------------------------------------------------------------------------------- 1 | from peewee import * 2 | 3 | db = SqliteDatabase('cache.db') 4 | 5 | 6 | class WorkMetadataCache(Model): 7 | rjcode = CharField(primary_key=True) 8 | metadata = TextField() 9 | 10 | class Meta: 11 | database = db # This model uses the "work_metadata_cache.db" database. 12 | -------------------------------------------------------------------------------- /scraper/langs/zh_cn.py: -------------------------------------------------------------------------------- 1 | ZH_CN = { 2 | "AGE": "年龄指定", 3 | "GENRE": "分类", 4 | "RELEASE_DATE": "贩卖日", 5 | "SERIES_NAME": "系列名", 6 | "PRODUCT_FORMAT": "作品类型", 7 | "EVENT": "活动", 8 | "AUTHOR": "作者", 9 | "SCENARIO": "剧情", 10 | "ILLUSTRATION": "插画", 11 | "MUSIC": "音乐", 12 | "VOICE_ACTOR": "声优" 13 | } 14 | -------------------------------------------------------------------------------- /scraper/langs/zh_tw.py: -------------------------------------------------------------------------------- 1 | ZH_TW = { 2 | "AGE": "年齡指定", 3 | "GENRE": "分類", 4 | "RELEASE_DATE": "販賣日", 5 | "SERIES_NAME": "系列名", 6 | "PRODUCT_FORMAT": "作品形式", 7 | "EVENT": "活動", 8 | "AUTHOR": "作者", 9 | "SCENARIO": "劇本", 10 | "ILLUSTRATION": "插畫", 11 | "MUSIC": "音樂", 12 | "VOICE_ACTOR": "聲優" 13 | } 14 | -------------------------------------------------------------------------------- /scraper/langs/ja_jp.py: -------------------------------------------------------------------------------- 1 | JA_JP = { 2 | "AGE": "年齢指定", 3 | "GENRE": "ジャンル", 4 | "RELEASE_DATE": "販売日", 5 | "SERIES_NAME": "シリーズ名", 6 | "PRODUCT_FORMAT": "作品形式", 7 | "EVENT": "イベント", 8 | "AUTHOR": "作者", 9 | "SCENARIO": "シナリオ", 10 | "ILLUSTRATION": "イラスト", 11 | "MUSIC": "音楽", 12 | "VOICE_ACTOR": "声優" 13 | } 14 | -------------------------------------------------------------------------------- /scraper/langs/ko_kr.py: -------------------------------------------------------------------------------- 1 | KO_KR = { 2 | "AGE": "연령 지정", 3 | "GENRE": "장르", 4 | "RELEASE_DATE": "판매일", 5 | "SERIES_NAME": "시리즈명", 6 | "PRODUCT_FORMAT": "작품 형식", 7 | "EVENT": "이벤트", 8 | "AUTHOR": "저자", 9 | "SCENARIO": "시나리오", 10 | "ILLUSTRATION": "일러스트", 11 | "MUSIC": "음악", 12 | "VOICE_ACTOR": "성우" 13 | } 14 | -------------------------------------------------------------------------------- /scraper/work_metadata.py: -------------------------------------------------------------------------------- 1 | from typing import TypedDict 2 | 3 | 4 | # 同人作品元数据 5 | class WorkMetadata(TypedDict): 6 | rjcode: str 7 | work_name: str 8 | maker_id: str 9 | maker_name: str 10 | release_date: str 11 | series_id: str 12 | series_name: str 13 | age_category: str 14 | tags: list[str] 15 | cvs: list[str] 16 | cover_url: str 17 | -------------------------------------------------------------------------------- /scraper/langs/en_us.py: -------------------------------------------------------------------------------- 1 | EN_US = { 2 | "AGE": "Age", 3 | "GENRE": "Genre", 4 | "RELEASE_DATE": "Release date", 5 | "SERIES_NAME": "Series name", 6 | "PRODUCT_FORMAT": "Product format", 7 | "EVENT": "Event", 8 | "AUTHOR": "Author", 9 | "SCENARIO": "Scenario", 10 | "ILLUSTRATION": "Illustration", 11 | "MUSIC": "Music", 12 | "VOICE_ACTOR": "Voice Actor" 13 | } 14 | -------------------------------------------------------------------------------- /scraper/translation.py: -------------------------------------------------------------------------------- 1 | from typing import TypedDict 2 | 3 | 4 | # 同人作品页面翻译 5 | class Translation(TypedDict): 6 | AGE: str # 年龄指定 7 | GENRE: str # 分类 8 | RELEASE_DATE: str # 贩卖日 9 | SERIES_NAME: str # 系列名 10 | PRODUCT_FORMAT: str # 作品类型 11 | EVENT: str # 活动 12 | AUTHOR: str # 作者 13 | SCENARIO: str # 剧情 14 | ILLUSTRATION: str # 插画 15 | MUSIC: str # 音乐 16 | VOICE_ACTOR: str # 声优 17 | -------------------------------------------------------------------------------- /scaner/scaner.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from scraper import Dlsite 4 | 5 | 6 | class Scaner(object): 7 | def __init__(self, max_depth=5): 8 | self.__max_depth = max_depth 9 | 10 | def scan(self, root_path: str, _depth=0): 11 | """ 12 | 生成器。深层遍历所有含 rjcode 的文件夹 13 | """ 14 | if os.path.isdir(root_path): # 检查是否是文件夹 15 | folder = os.path.basename(root_path) 16 | rjcode = Dlsite.parse_workno(folder) 17 | if rjcode: # 检查文件夹名称中是否含RJ号 18 | yield rjcode, root_path 19 | elif _depth < self.__max_depth: 20 | dir_list = os.listdir(root_path) 21 | for folder in dir_list: 22 | folder_path = os.path.join(root_path, folder) 23 | yield from self.scan(folder_path, _depth + 1) 24 | -------------------------------------------------------------------------------- /wx_log_handler.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | import wx 4 | import wx.lib.newevent 5 | 6 | # create event type 7 | wxLogEvent, EVT_WX_LOG_EVENT = wx.lib.newevent.NewEvent() 8 | 9 | 10 | class WxLogHandler(logging.Handler): 11 | """ 12 | A handler class which sends log strings to a wx object 13 | https://stackoverflow.com/a/2820928 14 | """ 15 | 16 | def __init__(self, wx_dest: wx.Window): 17 | """ 18 | Initialize the handler 19 | @param wx_dest: the destination object to post the event to 20 | """ 21 | logging.Handler.__init__(self) 22 | self.__wxDest = wx_dest 23 | self.level = logging.DEBUG 24 | 25 | def flush(self): 26 | """ 27 | does nothing for this handler 28 | """ 29 | 30 | def emit(self, record): 31 | """ 32 | Emit a record. 33 | """ 34 | try: 35 | msg = self.format(record) 36 | evt = wxLogEvent(message=msg, levelno=record.levelno) 37 | wx.PostEvent(self.__wxDest, evt) 38 | except (KeyboardInterrupt, SystemExit) as err: 39 | raise err 40 | except Exception: 41 | self.handleError(record) 42 | -------------------------------------------------------------------------------- /scraper/cached_scraper.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from scraper.db import db, WorkMetadataCache 4 | from scraper.locale import Locale 5 | from scraper.scraper import Scraper 6 | from scraper.work_metadata import WorkMetadata 7 | 8 | 9 | class CachedScraper(Scraper): 10 | def __init__(self, locale: Locale, proxies=None, connect_timeout: int = 10, read_timeout: int = 10, sleep_interval=3): 11 | super().__init__(locale, proxies, connect_timeout, read_timeout, sleep_interval) 12 | db.connect() 13 | db.create_tables([WorkMetadataCache]) 14 | 15 | def __del__(self): 16 | db.close() 17 | 18 | def scrape_metadata(self, rjcode: str): 19 | # 在数据库中查找 20 | metadata_cache = WorkMetadataCache.get_or_none(WorkMetadataCache.rjcode == rjcode) 21 | if metadata_cache: 22 | # 已缓存,返回数据库中缓存的 metadata 23 | metadata: WorkMetadata = json.loads(metadata_cache.metadata) 24 | return metadata 25 | else: 26 | # 未缓存,从 scraper 抓取 metadata 并缓存到数据库 27 | metadata = super().scrape_metadata(rjcode) 28 | WorkMetadataCache.create(rjcode=rjcode, metadata=json.dumps(metadata, indent=2, ensure_ascii=False)) 29 | return metadata 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .history 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .nox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | 63 | # Flask stuff: 64 | instance/ 65 | .webassets-cache 66 | 67 | # Scrapy stuff: 68 | .scrapy 69 | 70 | # Sphinx documentation 71 | docs/_build/ 72 | 73 | # PyBuilder 74 | target/ 75 | 76 | # Jupyter Notebook 77 | .ipynb_checkpoints 78 | 79 | # IPython 80 | profile_default/ 81 | ipython_config.py 82 | 83 | # pyenv 84 | .python-version 85 | 86 | # celery beat schedule file 87 | celerybeat-schedule 88 | 89 | # SageMath parsed files 90 | *.sage.py 91 | 92 | # Environments 93 | .env 94 | .venv 95 | env/ 96 | venv/ 97 | ENV/ 98 | env.bak/ 99 | venv.bak/ 100 | 101 | # Spyder project settings 102 | .spyderproject 103 | .spyproject 104 | 105 | # Rope project settings 106 | .ropeproject 107 | 108 | # mkdocs documentation 109 | /site 110 | 111 | # mypy 112 | .mypy_cache/ 113 | .dmypy.json 114 | dmypy.json 115 | 116 | # Pyre type checker 117 | .pyre/ 118 | 119 | # IDEA 120 | .idea/ 121 | 122 | cache.db 123 | config.json 124 | RENAMER_MOVE_ROOT 125 | -------------------------------------------------------------------------------- /ostool.py: -------------------------------------------------------------------------------- 1 | import os 2 | import errno 3 | import shutil 4 | from pathlib import Path 5 | 6 | 7 | def force_symlink(src_path: Path, dst_path: Path, target_is_directory: bool = False): 8 | """ 9 | 创建符号链接: 10 | - 如果目标已存在且是符号链接: 11 | - 指向相同 -> 跳过 12 | - 指向不同 -> 删除后重建 13 | - 如果目标已存在且为真实目录/文件 -> 抛异常(不删除,保护数据) 14 | - 否则直接创建 15 | """ 16 | if dst_path.exists() or dst_path.is_symlink(): 17 | if dst_path.is_symlink(): 18 | current_target = dst_path.readlink() 19 | if current_target.resolve() == src_path.resolve(): 20 | # print(f"Skipped (already correct link): {dst_path} -> {current_target}") 21 | return 22 | else: 23 | dst_path.unlink() # 删除旧符号链接 24 | 25 | dst_path.symlink_to(src_path, target_is_directory=target_is_directory) 26 | # print(f"Symlink created: {dst_path} -> {src_path}") 27 | 28 | 29 | def copy_with_symlink(src: str, dst: str): 30 | """ 31 | 在 dst 位置创建 src 文件夹的符号链接副本。 32 | 如果 dst 已存在,会报错。 33 | """ 34 | src_path = Path(src).resolve() 35 | dst_path = Path(dst) 36 | 37 | if not src_path.exists(): 38 | raise FileNotFoundError(f"源路径不存在: {src}") 39 | 40 | dst_path.parent.mkdir(parents=True, exist_ok=True) 41 | 42 | # Windows 下创建符号链接目录需要管理员权限,或启用"系统-开发者选项-开发人员模式" 43 | force_symlink(src_path, dst_path, target_is_directory=True) 44 | 45 | 46 | def move_folder(src: str, dst: str) -> None: 47 | """ 48 | 移动或硬链接复制文件夹 49 | :param src: 源路径 50 | :param dst: 目标路径 51 | """ 52 | if not os.path.exists(src): 53 | raise FileNotFoundError(f"源路径不存在: {src}") 54 | 55 | os.makedirs(os.path.dirname(dst), exist_ok=True) 56 | 57 | if os.path.exists(dst): 58 | err = FileExistsError(errno.EEXIST, "目标路径已存在") 59 | err.filename = src 60 | err.filename2 = dst 61 | raise err 62 | 63 | shutil.move(src, dst) 64 | 65 | 66 | def normalize_path(path: str) -> str: 67 | # 统一分隔符 68 | path = path.replace("\\", "/") 69 | # 切分 -> 去掉空白 -> 去掉空字符串 70 | parts = [p.strip() for p in path.split("/") if p.strip()] 71 | # 拼接 72 | return "/".join(parts) 73 | -------------------------------------------------------------------------------- /scraper/dlsite.py: -------------------------------------------------------------------------------- 1 | import re 2 | from typing import Final 3 | from urllib.parse import unquote 4 | 5 | from scraper.locale import Locale 6 | from scraper.langs import EN_US, JA_JP, KO_KR, ZH_CN, ZH_TW 7 | from scraper.translation import Translation 8 | 9 | 10 | # 读取翻译文件 11 | def _load_translations(): 12 | translations: dict[Locale, Translation] = { 13 | Locale.en_us: EN_US, 14 | Locale.ja_jp: JA_JP, 15 | Locale.ko_kr: KO_KR, 16 | Locale.zh_cn: ZH_CN, 17 | Locale.zh_tw: ZH_TW, 18 | } 19 | return translations 20 | 21 | 22 | class Dlsite(object): 23 | TRANSLATIONS: Final = _load_translations() 24 | WORKNO_PATTERN: Final = re.compile(r'[RBV]J(\d{6}|\d{8})(?!\d+)') 25 | RJCODE_PATTERN: Final = re.compile(r'RJ(\d{6}|\d{8})(?!\d+)') 26 | RGCODE_PATTERN: Final = re.compile(r'RG(\d{5})(?!\d+)') 27 | SRICODE_PATTERN: Final = re.compile(r'SRI(\d{10})(?!\d+)') 28 | 29 | # 提取字符串中的 workno 30 | @staticmethod 31 | def parse_workno(string: str): 32 | match = Dlsite.WORKNO_PATTERN.search(string.upper()) 33 | if match: 34 | return match.group() 35 | else: 36 | return None 37 | 38 | # 根据 rjcode 拼接出同人作品页面的 url 39 | @staticmethod 40 | def compile_work_page_url(rjcode: str): 41 | return f'https://www.dlsite.com/maniax/work/=/product_id/{rjcode}.html' 42 | 43 | @staticmethod 44 | def compile_product_api_url(rjcode: str): 45 | return f'https://www.dlsite.com/maniax/api/=/product.json?workno={rjcode}' 46 | 47 | # 解析 scraper 链接中携带的参数 (dlsite.com 服务端使用 mod_rewrite 优化 SEO) 48 | @staticmethod 49 | def parse_url_params(url: str): 50 | url = unquote(url) 51 | split_url = url.split(r'/=/', 1) 52 | params_str = split_url[1] if len(split_url) == 2 else '' 53 | params_str_1 = re.sub(r'\?.*$', '', params_str, count=1) 54 | params_str_2 = re.sub(r'(\.html)?/?$', '', params_str_1) # 去除 url 的 .html/ 后缀 55 | params_list = params_str_2.split('/') 56 | params = {} 57 | for i in range(0, len(params_list), 2): 58 | params[params_list[i]] = params_list[i + 1] if i + 1 < len(params_list) else '' 59 | return params 60 | -------------------------------------------------------------------------------- /my_frame.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ########################################################################### 4 | ## Python code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) 5 | ## http://www.wxformbuilder.org/ 6 | ## 7 | ## PLEASE DO *NOT* EDIT THIS FILE! 8 | ########################################################################### 9 | 10 | import wx 11 | import wx.xrc 12 | 13 | 14 | ########################################################################### 15 | ## Class MyFrame 16 | ########################################################################### 17 | 18 | class MyFrame(wx.Frame): 19 | 20 | def __init__(self, parent): 21 | wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, 22 | size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) 23 | 24 | self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) 25 | 26 | box_sizer = wx.BoxSizer(wx.VERTICAL) 27 | 28 | self.static_text = wx.StaticText(self, wx.ID_ANY, u"Tip:手动选择文件夹或拖拽文件夹到软件窗口", wx.DefaultPosition, wx.DefaultSize, 29 | 0) 30 | self.static_text.Wrap(-1) 31 | box_sizer.Add(self.static_text, 0, wx.ALL | wx.EXPAND, 5) 32 | 33 | self.text_ctrl = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 34 | wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH | wx.TE_RICH2 | wx.HSCROLL | wx.TE_AUTO_URL) 35 | box_sizer.Add(self.text_ctrl, 1, wx.ALL | wx.EXPAND, 5) 36 | 37 | self.dir_picker = wx.DirPickerCtrl(self, wx.ID_ANY, '', 38 | u"Select a folder", wx.DefaultPosition, wx.DefaultSize, 39 | wx.DIRP_DIR_MUST_EXIST) 40 | box_sizer.Add(self.dir_picker, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5) 41 | 42 | self.SetSizer(box_sizer) 43 | self.Layout() 44 | 45 | self.Centre(wx.BOTH) 46 | 47 | # Connect Events 48 | self.dir_picker.Bind(wx.EVT_DIRPICKER_CHANGED, self.on_dir_changed_event) 49 | 50 | def __del__(self): 51 | pass 52 | 53 | # Virtual event handlers, override them in your derived class 54 | def on_dir_changed_event(self, event): 55 | event.Skip() 56 | -------------------------------------------------------------------------------- /config_file.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import re 4 | from typing import Annotated, Optional, Union, Literal 5 | from pydantic import Field 6 | from typing_extensions import TypedDict 7 | from pydantic import TypeAdapter, ConfigDict, ValidationError 8 | from scraper import Locale 9 | 10 | FilenameStr = Annotated[str, Field(pattern=r'^[^\/:*?"<>|]*$', description="""不能含有系统保留字[^\/:*?`<>|]*""")] 11 | RjcodeStr = Annotated[str, Field(pattern=re.compile(r".*rjcode.*"), description='template 应是一个包含 "rjcode" 的字符串')] 12 | 13 | class Config(TypedDict): 14 | __pydantic_config__ = ConfigDict() 15 | 16 | # scaner 17 | scaner_max_depth: int 18 | # scraper 19 | scraper_locale: Locale 20 | scraper_connect_timeout: int 21 | scraper_read_timeout: int 22 | scraper_sleep_interval: int 23 | scraper_http_proxy: Optional[str] 24 | # renamer 25 | renamer_template: RjcodeStr 26 | renamer_release_date_format: str # https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes 27 | renamer_exclude_square_brackets_in_work_name_flag: bool 28 | renamer_illegal_character_to_full_width_flag: bool 29 | renamer_make_folder_icon: bool 30 | renamer_remove_jpg_file: bool 31 | renamer_delimiter: FilenameStr # 分隔符 32 | renamer_cv_list_left: FilenameStr 33 | renamer_cv_list_right: FilenameStr 34 | renamer_tags_max_number: int # 标签个数上限 35 | renamer_tags_ordered_list: list[Union[str, list[str]]] 36 | renamer_age_cat_map_gen: str 37 | renamer_age_cat_map_r15: str 38 | renamer_age_cat_map_r18: str 39 | renamer_age_cat_left: FilenameStr 40 | renamer_age_cat_right: FilenameStr 41 | renamer_age_cat_ignore_r18: bool 42 | renamer_series_name_left: FilenameStr 43 | renamer_series_name_right: FilenameStr 44 | renamer_mode: Literal["RENAME", "MOVE", "LINK"] 45 | renamer_move_root: str 46 | renamer_move_template: RjcodeStr 47 | 48 | 49 | ta = TypeAdapter(Config) 50 | 51 | 52 | DEFAULT_CONFIG: Config = { 53 | # scaner 54 | 'scaner_max_depth': 5, 55 | # scraper 56 | 'scraper_locale': 'ja_jp', 57 | 'scraper_connect_timeout': 10, 58 | 'scraper_read_timeout': 10, 59 | 'scraper_sleep_interval': 3, 60 | 'scraper_http_proxy': None, 61 | # renamer 62 | 'renamer_template': 'age_cat[maker_name][rjcode] work_name cv_list_str', 63 | 'renamer_release_date_format': '%y%m%d', 64 | 'renamer_exclude_square_brackets_in_work_name_flag': True, 65 | 'renamer_illegal_character_to_full_width_flag': True, 66 | 'renamer_make_folder_icon': True, 67 | 'renamer_remove_jpg_file': True, 68 | 'renamer_delimiter': " ", 69 | 'renamer_cv_list_left': "(CV ", 70 | 'renamer_cv_list_right': ")", 71 | 'renamer_tags_max_number': 5, 72 | 'renamer_tags_ordered_list': ["标签1", ["标签2", "替换2"], "标签3"], # 标签顺序列表,每一项可为字符串或[原标签,替换名] 73 | 'renamer_age_cat_map_gen': "全年龄", 74 | 'renamer_age_cat_map_r15': "R15", 75 | 'renamer_age_cat_map_r18': "R18", 76 | 'renamer_age_cat_left': "(", 77 | 'renamer_age_cat_right': ")", 78 | 'renamer_age_cat_ignore_r18': True, 79 | 'renamer_series_name_left': "", 80 | 'renamer_series_name_right': "", 81 | 'renamer_mode': 'RENAME', 82 | 'renamer_move_root': 'RENAMER_MOVE_ROOT', 83 | 'renamer_move_template': 'maker_name/series_name/age_cat[rjcode] work_name cv_list_str' 84 | } 85 | 86 | 87 | class ConfigFile(object): 88 | def __init__(self, file_path: str): 89 | self.__config: Config = None 90 | self.__config_dict = None 91 | self.__file_path = file_path 92 | if not os.path.isfile(file_path): 93 | self.save_config(DEFAULT_CONFIG) 94 | 95 | def load_config_dict(self): 96 | """ 97 | 从配置文件中读取配置 98 | """ 99 | with open(self.__file_path, encoding='UTF-8') as file: 100 | config_dict = json.load(file) 101 | self.__config_dict = config_dict 102 | 103 | def save_config(self, config: Config): 104 | """ 105 | 保存配置到文件 106 | """ 107 | with open(self.__file_path, 'w', encoding='UTF-8') as file: 108 | json.dump(config, file, indent=2, ensure_ascii=False) 109 | 110 | @property 111 | def file_path(self): 112 | return self.__file_path 113 | 114 | @property 115 | def config(self): 116 | return self.__config 117 | 118 | def verify_config(self) -> list[str]: 119 | """ 120 | 验证配置是否合理 121 | """ 122 | # schema = ta.json_schema() 123 | # validator = Draft202012Validator(schema) 124 | # strerror_list: list[str] = [] 125 | # 126 | # for i, error in enumerate(validator.iter_errors(self.__config_dict), 1): 127 | # description = error.schema.get('description', None) 128 | # if description: 129 | # strerror_list.append( 130 | # "\n".join(["- 错误: " + error.message, 131 | # " 校验器: " + error.validator, 132 | # " 描述:" + description])) 133 | # else: 134 | # strerror_list.append( 135 | # "\n".join(["- 错误: " + error.message, 136 | # " 校验器: " + error.validator])) 137 | # if len(strerror_list) == 0: 138 | # self.__config = Config(**self.__config_dict) 139 | 140 | strerror_list: list[str] = [] 141 | try: 142 | validated = ta.validate_python(self.__config_dict) 143 | self.__config = validated 144 | except ValidationError as e: 145 | for err in e.errors(): 146 | loc = ".".join(map(str, err["loc"])) 147 | strerror_list.append( 148 | "\n".join([ 149 | f"- 错误: {err['msg']}", 150 | f" 校验器: {err['type']}", 151 | f" 字段: {loc}", 152 | ]) 153 | ) 154 | 155 | if len(strerror_list) == 0: 156 | self.__config = Config(**self.__config_dict) 157 | 158 | return strerror_list 159 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dlsite-doujin-renamer 2 | ![软件截图](screenshot.png) 3 | 4 | ## Features 5 | - 支持深度查找带有 RJ 号的文件夹 6 | - 支持手动选择文件夹或拖拽文件夹到软件窗口 7 | - 支持在 `config.json` 中设置软件配置 8 | - 支持在 `cache.db` 中缓存从 [dlsite.com](https://www.dlsite.com/maniax/) 抓取的元数据 9 | - 将文件夹封面修改为作品封面 10 | 11 | ## Config 12 | 默认配置 13 | ```json 14 | { 15 | "scaner_max_depth": 5, 16 | "scraper_locale": "ja_jp", 17 | "scraper_connect_timeout": 10, 18 | "scraper_read_timeout": 10, 19 | "scraper_sleep_interval": 3, 20 | "scraper_http_proxy": null, 21 | "renamer_template": "age_cat[maker_name][rjcode] work_name cv_list_str", 22 | "renamer_release_date_format": "%y%m%d", 23 | "renamer_exclude_square_brackets_in_work_name_flag": true, 24 | "renamer_illegal_character_to_full_width_flag": false, 25 | "renamer_make_folder_icon": true, 26 | "renamer_remove_jpg_file": true, 27 | "renamer_delimiter": " ", 28 | "renamer_cv_list_left": "(CV ", 29 | "renamer_cv_list_right": ")", 30 | "renamer_tags_max_number": 5, 31 | "renamer_tags_ordered_list": [ 32 | "标签1", 33 | ["标签2", "替换2"], 34 | "标签3" 35 | ], 36 | "renamer_age_cat_map_gen": "全年龄", 37 | "renamer_age_cat_map_r15": "R15", 38 | "renamer_age_cat_map_r18": "R18", 39 | "renamer_age_cat_left": "(", 40 | "renamer_age_cat_right": ")", 41 | "renamer_age_cat_ignore_r18": true, 42 | "renamer_series_name_left": "", 43 | "renamer_series_name_right": "", 44 | "renamer_mode": "RENAME", 45 | "renamer_move_root": "RENAMER_MOVE_ROOT", 46 | "renamer_move_template": "maker_name/series_name/age_cat[rjcode] work_name cv_list_str" 47 | } 48 | ``` 49 | - `scaner_max_depth` 扫描器的扫描深度 50 | - `scraper_locale` 刮削器的刮削元数据的语言(`["en_us", "ja_jp", "ko_kr", "zh_cn", "zh_tw"]` 中的一个,默认 `"ja_jp"`)。**注意:修改此项配置后需要删除 `cache.db` 缓存文件,以应用更改** 51 | - `scraper_connect_timeout` 刮削器的 [requests 连接超时](https://docs.python-requests.org/zh_CN/latest/user/advanced.html#timeout)时间(秒) 52 | - `scraper_connect_timeout` 刮削器的 [requests 读取超时](https://docs.python-requests.org/zh_CN/latest/user/advanced.html#timeout)时间(秒) 53 | - `scraper_sleep_interval` 刮削器的请求网页的时间间隔(秒) 54 | - `scraper_http_proxy` 刮削器的使用的代理(http代理),此项设置为 `null` 时,将尝试使用系统代理 55 | - `renamer_template` 命名器的命名模板,命名器将替换模板中的关键字: 56 | - `rjcode` 同人作品的 RJ 号 57 | - `work_name` 同人作品的名称 58 | - `maker_id` 同人作品的社团 RG 号 59 | - `maker_name` 同人作品的社团名称 60 | - `series_name` 系列名。由于作品可能不存在系列名,请配合 `renamer_series_name_left` `renamer_series_name_right` 使用 61 | - `release_date` 同人作品的发售日期,具体的日期格式可在 `renamer_release_date_format` 中设置 62 | - `cv_list_str` 同人作品的声优列表 63 | - `tags_list_str` 同人作品的标签(分类)列表 64 | - `age_cat` 同人作品的年龄分级(全年龄、R15、R18) 65 | 66 | 例如:`"renamer_template": "[maker_name] work_name (rjcode)[tags_list_str]"`
67 | 重命名前:`RJ298293 蓄音レヱル 紅`
68 | 重命名后:`[RaRo] 蓄音レヱル 紅 (RJ298293)[萌 感动 治愈 环绕音]` 69 | - `renamer_release_date_format` 命名器模板中 `release_date` 的日期格式 70 | - `renamer_exclude_square_brackets_in_work_name_flag` 命名器的 `work_name` 中是否排除 `【】` 及其间的内容。例如: 71 | - `"renamer_exclude_square_brackets_in_work_name_flag": true`
72 | `work_name = "道草屋 なつな2 隣の部屋のたぬきさん。"` 73 | - `"renamer_exclude_square_brackets_in_work_name_flag": false`
74 | `work_name = "【お隣り耳噛み】道草屋 なつな2 隣の部屋のたぬきさん。【お隣り耳かき】"` 75 | - `renamer_illegal_character_to_full_width_flag` 命名器的新文件名中的非法字符(windows保留字)如何处理。`true`为全角化,`false`为直接删除。例如: 76 | - `"renamer_illegal_character_to_full_width_flag": true`
77 | `文/件*名` → `文/件*名` 78 | - `"renamer_illegal_character_to_full_width_flag": false`
79 | `文/件*名` → `文件名` 80 | - `make_folder_icon` 是否将文件夹封面改为作品封面,`true` 为修改,`false` 反之 81 | - `remove_jpg_file` 是否保留文件夹中的作品封面图,`true` 为移除,`false` 为保留(不会消除文件夹封面) 82 | - `renamer_delimiter` 命名器将列表转为字符串时的分隔符,作用于 `cv_list_str` 和 `tags_list_str`。不能含有系统保留字 ```[^\/:*?`<>|]*``` 83 | - `cv_list_left` `cv_list_right` 命名器在声优列表左右外括的符号,作用于 `cv_list_str`。不能含有系统保留字 ```[^\/:*?`<>|]*``` 84 | - `renamer_tags_max_number` 命名器向文件名中写入标签的最大个数 85 | - `renamer_tags_ordered_list` 命名器向文件名中写入标签的优先顺序和替换标签。列表。每一项若是字符串,则为匹配的标签。若是二元列表,则为`["匹配的标签","替换的标签"]`。例如: 86 | - ``` 87 | "renamer_delimiter": ",", 88 | "renamer_tags_max_number": 4, 89 | "renamer_tags_ordered_list": [ 90 | "标签1", 91 | ["标签2","替换2"], 92 | "标签3" 93 | ] 94 | ``` 95 | - 作品含有的标签:`标签6` `标签5` `标签4` `标签3` `标签2` `标签1` 96 | - 文件名中的标签:`标签1,替换2,标签3,标签6` 97 | - `renamer_age_cat_map_gen` 自定义`全年龄`作品的年龄分级 98 | - `renamer_age_cat_map_r15` 自定义`R15`作品的年龄分级 99 | - `renamer_age_cat_map_r18` 自定义`R18`作品的年龄分级 100 | - `renamer_age_cat_left` `renamer_age_cat_right` 自定义命名器在 `age_cat`(年龄分级) 左右两侧的符号。不能含有系统保留字 ```[^\/:*?`<>|]*``` 101 | - ``renamer_age_cat_ignore_r18`` 命名器是否忽略 R18 作品的 `age_cat` (年龄分级),R18 作品占大多数时建议开启。例如:`"renamer_template": "age_cat[maker_name] work_name (rjcode)"` 102 | - `"renamer_age_cat_ignore_r18": true`
103 | `work_name = "[桃色CODE] 道草屋 なつな2 隣の部屋のたぬきさん。 (RJ363096)"` 104 | - `"renamer_age_cat_ignore_r18": false`
105 | `work_name = "(R18)[桃色CODE] 道草屋 なつな2 隣の部屋のたぬきさん。 (RJ363096)"` 106 | - `renamer_series_name_left` `renamer_series_name_right` 自定义命名器在 `series_name`(系列名) 左右两侧的符号。不能含有系统保留字 ```[^\/:*?`<>|]*``` 107 | - `renamer_mode` 命名器的工作模式 108 | - `RENAME` 重命名,使用模板 `renamer_template` 109 | - `MOVE` 移动到指定根目录,使用模板 `renamer_move_template` 110 | - `LINK` 复制快捷方式到指定根目录(保持源文件夹不变,适合需要做种的使用场景),使用模板 `renamer_move_template` 111 | - `renamer_move_root` `MOVE`与`LINK`工作模式下的指定根目录,**注意路径配置使用`/`分隔符**,例如 `"renamer_move_root": "D:/音声库"` 112 | - `renamer_move_template` `MOVE`与`LINK`工作模式下的命名模板。
113 | 例如:`"renamer_move_template": "maker_name/[rjcode] work_name"` `"renamer_move_root": "D:/音声库"`
114 | 源路径:`D:/道草屋/RJ363096` → 目标路径:`D:/音声库/桃色CODE/[RJ363096] 道草屋 なつな2 隣の部屋のたぬきさん。` 115 | 116 | 【注】**请不要使用 Windows 系统自带的「记事本」编辑配置文件**,建议使用 [Notepad3](https://www.rizonesoft.com/downloads/notepad3/)、[Notepad++](https://notepad-plus-plus.org/) 或 [Visual Studio Code](https://code.visualstudio.com/) 等专业的文本编辑器。本软件的配置文件 `config.json` 使用不带 BOM 的标准 UTF-8 编码,但在 Windows 记事本的语境中,所谓的「UTF-8」指的是带 BOM 的 UTF-8。因此,用 Windows 系统自带的记事本编辑配置文件后,会导致本软件无法正确读取配置。 117 | 118 | ## 开发者文档 119 | ### 环境 120 | 1. install python 3.9 121 | 2. `pip install -r requirements.txt` 122 | ### 运行 123 | `python main.py` 124 | ### 打包(输出路径 `dist/main.exe`) 125 | `python build.py` 126 | 127 | ## Star History 128 | [![Star History Chart](https://api.star-history.com/svg?repos=yodhcn/dlsite-doujin-renamer&type=Date)](https://www.star-history.com/#yodhcn/dlsite-doujin-renamer&Date) 129 | -------------------------------------------------------------------------------- /scraper/scraper.py: -------------------------------------------------------------------------------- 1 | import os 2 | import contextlib 3 | import time 4 | from pathlib import Path 5 | from urllib.request import getproxies 6 | from typing import Union 7 | 8 | import requests 9 | from pyquery import PyQuery as pq 10 | 11 | from scraper.dlsite import Dlsite 12 | from scraper.locale import Locale 13 | from scraper.work_metadata import WorkMetadata 14 | 15 | from PIL import Image as img 16 | 17 | 18 | def _getproxies(): 19 | """ 20 | 获取系统代理 21 | """ 22 | proxies = getproxies() 23 | # https://github.com/psf/requests/issues/5943 24 | https_proxy = proxies.get('https', None) 25 | http_proxy = proxies.get('http', None) 26 | if https_proxy and https_proxy.startswith(r'https://'): 27 | proxies['https'] = http_proxy 28 | return proxies 29 | 30 | 31 | class Scraper(object): 32 | def __init__(self, locale: Locale, proxies=None, connect_timeout: int = 10, read_timeout: int = 10, sleep_interval=3): 33 | self.__locale = locale 34 | self.__connect_timeout = connect_timeout 35 | self.__read_timeout = read_timeout 36 | self.__sleep_interval = sleep_interval 37 | if not proxies: 38 | # 获取系统代理 39 | proxies = _getproxies() 40 | self.__proxies = proxies 41 | 42 | def __request_work_page(self, rjcode: str): 43 | url = Dlsite.compile_work_page_url(rjcode) 44 | params = {'locale': self.__locale.name} 45 | response = requests.get(url, 46 | params, 47 | timeout=(self.__connect_timeout, self.__read_timeout), 48 | proxies=self.__proxies) 49 | response.raise_for_status() # 如果返回了不成功的状态码,Response.raise_for_status() 会抛出一个 HTTPError 异常 50 | html = response.text 51 | time.sleep(self.__sleep_interval) 52 | return html 53 | 54 | def __request_product_api(self, rjcode: str): 55 | url = Dlsite.compile_product_api_url(rjcode) 56 | params = {'locale': self.__locale.name} 57 | response = requests.get(url, 58 | params, 59 | timeout=(self.__connect_timeout, self.__read_timeout), 60 | proxies=self.__proxies) 61 | if len(response.json()) == 0: 62 | response.status_code = 404 63 | response.reason = 'Not Found' 64 | response.raise_for_status() # 如果返回了不成功的状态码,Response.raise_for_status() 会抛出一个 HTTPError 异常 65 | 66 | product_info = response.json()[0] 67 | time.sleep(self.__sleep_interval) 68 | return product_info 69 | 70 | def scrape_metadata(self, rjcode: str): 71 | rjcode = rjcode.upper() 72 | if not Dlsite.WORKNO_PATTERN.fullmatch(rjcode): 73 | raise ValueError 74 | metadata = self.__scrape_metadata_from_product_api(rjcode) 75 | return metadata 76 | 77 | def __scrape_metadata_from_product_api(self, workno: str): 78 | product_info = self.__request_product_api(workno) 79 | 80 | translation_info = product_info.get('translation_info', None) 81 | original_workno = translation_info.get('original_workno', None) if translation_info else None 82 | original_product_info = self.__request_product_api(original_workno) if original_workno else None 83 | 84 | metadata: WorkMetadata = { 85 | 'rjcode': product_info['workno'], 86 | 'work_name': product_info['work_name'], 87 | 'maker_id': original_product_info['maker_id'] if original_product_info else product_info['maker_id'], 88 | 'maker_name': original_product_info['maker_name'] if original_product_info else product_info['maker_name'], 89 | 'release_date': product_info['regist_date'][0:10], 90 | 'series_name': original_product_info['series_name'] if original_product_info else product_info['series_name'], 91 | 'series_id': original_product_info['series_id'] if original_product_info else product_info['series_id'], 92 | 'age_category': '', 93 | 'tags': [], 94 | 'cvs': [], 95 | 'cover_url': 'https:' + product_info['image_main']['url'] 96 | } 97 | 98 | # tags 99 | for genre in product_info['genres']: 100 | metadata['tags'].append(genre['name']) 101 | # cvs 102 | if isinstance(product_info['creaters'], dict) and 'voice_by' in product_info['creaters']: 103 | for cv in product_info['creaters']['voice_by']: 104 | metadata['cvs'].append(cv['name']) 105 | 106 | # age_category 107 | if product_info['age_category'] == 1: 108 | metadata['age_category'] = 'GEN' 109 | elif product_info['age_category'] == 2: 110 | metadata['age_category'] = 'R15' 111 | else: # product_info['age_category'] == 3 112 | metadata['age_category'] = 'R18' 113 | 114 | return metadata 115 | 116 | # 获取封面图片链接 117 | @staticmethod 118 | def __parse_icon(html: str): 119 | d = pq(html) 120 | # parse icon 121 | work_icon_url_ = str(d('#work_left > div > div > div.product-slider-data > div:nth-child(1)').attr('data-src')) 122 | work_icon_url = "https:" + work_icon_url_ 123 | return work_icon_url 124 | 125 | def urlretrieve(self, url: str, 126 | filename: Union[os.PathLike, str]) -> tuple[str, dict[str, str]]: 127 | """" 128 | https://gist.github.com/xflr6/f29ed682f23fd27b6a0b1241f244e6c9 129 | """ 130 | with contextlib.closing(requests.get(url, stream=True, proxies=self.__proxies)) as r: 131 | r.raise_for_status() 132 | with open(filename, 'wb') as f: 133 | for chunk in r.iter_content(chunk_size=8_192): 134 | f.write(chunk) 135 | 136 | return filename, r.headers 137 | 138 | def scrape_icon(self, rjcode: str, cover_url: str, icon_dir: str): 139 | """ 140 | 下载图片并生成.ico文件 141 | """ 142 | icon_name = f'@folder-icon-{rjcode}.ico' 143 | jpg_name = 'cover.jpg' 144 | icon_path = Path(os.path.join(icon_dir, icon_name)) 145 | jpg_path = Path(os.path.join(icon_dir, jpg_name)) 146 | 147 | if not os.path.exists(icon_path): 148 | self.urlretrieve(cover_url, jpg_path) # 爬取作品图片 149 | 150 | # 用 .jpg 文件生成 .ico 文件 151 | image = img.open(jpg_path) 152 | x, y = image.size 153 | size = max(x, y) 154 | new_im = img.new('RGBA', (size, size), (255, 255, 255, 0)) 155 | new_im.paste(image, ((size - x) // 2, (size - y) // 2)) 156 | new_im.save(icon_path) 157 | 158 | return icon_name, jpg_name # 返回值用于后续删存操作 159 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | import logging 3 | import os 4 | import sys 5 | from json import JSONDecodeError 6 | from threading import Thread 7 | from typing import Optional, Callable 8 | import traceback 9 | 10 | import wx 11 | 12 | from config_file import ConfigFile, Config 13 | from renamer import Renamer 14 | from scaner import Scaner 15 | from scraper import Locale, CachedScraper 16 | from my_frame import MyFrame 17 | from wx_log_handler import EVT_WX_LOG_EVENT, WxLogHandler 18 | 19 | VERSION = '0.3.2' 20 | 21 | 22 | class MyFileDropTarget(wx.FileDropTarget): 23 | def __init__(self, window): 24 | wx.FileDropTarget.__init__(self) 25 | self.window = window 26 | 27 | def OnDropFiles(self, x, y, filenames): 28 | """ 29 | 当接收到用户拖拽的文件时,运行 renamer 30 | """ 31 | dirname_list = [filename for filename in filenames if os.path.isdir(filename)] 32 | self.window.thread_it(self.window.run_renamer, dirname_list) 33 | return True 34 | 35 | 36 | class AppFrame(MyFrame): 37 | def __init__(self, parent): 38 | MyFrame.__init__(self, parent) 39 | 40 | # 使文件能被拖拽到 wx.TextCtrl 组件 41 | drop_target = MyFileDropTarget(self) 42 | self.text_ctrl.SetDropTarget(drop_target) 43 | 44 | # 配置文件 45 | config_file_path = os.path.join('config.json') 46 | self.__config_file = ConfigFile(config_file_path) 47 | 48 | # 工作线程。耗时长的任务应放在工作线程执行,避免阻塞 GUI 线程 49 | self.__worker_thread: Optional[Thread] = None 50 | 51 | # 为 logger 添加 wxLogHandler 52 | self.text_ctrl.Bind(EVT_WX_LOG_EVENT, self.on_log_event) 53 | wx_log_handler = WxLogHandler(self.text_ctrl) 54 | wx_log_handler.setLevel(logging.INFO) 55 | wx_log_handler.setFormatter(logging.Formatter('%(asctime)s - %(message)s')) 56 | Renamer.logger.addHandler(wx_log_handler) 57 | 58 | self.text_ctrl.AppendText('源代码 ' + 'https://github.com/yodhcn/dlsite-doujin-renamer' + '\n') 59 | 60 | def thread_it(self, func: Callable, *args): 61 | """ 62 | 将函数打包进线程执行 63 | """ 64 | if self.__worker_thread and self.__worker_thread.is_alive(): 65 | return 66 | self.__worker_thread = Thread(target=func, args=args) 67 | self.__worker_thread.start() 68 | 69 | def on_log_event(self, event): 70 | """ 71 | 转发日志到 wx.TextCtrl 组件 72 | """ 73 | if event.levelno <= logging.INFO: 74 | text_color = wx.BLACK 75 | elif event.levelno <= logging.WARNING: 76 | text_color = wx.BLUE 77 | else: 78 | text_color = wx.RED 79 | self.text_ctrl.SetDefaultStyle(wx.TextAttr(text_color)) 80 | msg = event.message.strip("\r") + "\n" 81 | self.text_ctrl.AppendText(msg) 82 | event.Skip() 83 | 84 | def on_dir_changed_event(self, event): 85 | """ 86 | 当 wx.DirPickerCtrl 组件接收到用户选择的文件夹时,运行 renamer 87 | """ 88 | root_path = self.dir_picker.GetPath() 89 | self.thread_it(self.run_renamer, [root_path]) 90 | 91 | def __print_info(self, message: str): 92 | self.text_ctrl.SetDefaultStyle(wx.TextAttr(wx.BLACK)) 93 | self.text_ctrl.AppendText(message + '\n') 94 | 95 | def __print_warning(self, message: str): 96 | self.text_ctrl.SetDefaultStyle(wx.TextAttr(wx.BLUE)) 97 | self.text_ctrl.AppendText(message + '\n') 98 | 99 | def __print_error(self, message: str): 100 | self.text_ctrl.SetDefaultStyle(wx.TextAttr(wx.RED)) 101 | self.text_ctrl.AppendText(message + '\n') 102 | 103 | def __before_worker_thread_start(self): 104 | thread_id = self.__worker_thread.native_id # 线程 ID 105 | self.__print_info(f'******************************运行开始({thread_id})******************************') 106 | self.dir_picker.Disable() # 禁用【浏览】按钮 107 | self.text_ctrl.SetDropTarget(None) # 禁用文件拖拽 108 | 109 | def __before_worker_thread_end(self): 110 | self.dir_picker.Enable() # 恢复【浏览】按钮 111 | self.text_ctrl.SetDropTarget(MyFileDropTarget(self)) # 恢复文件拖拽 112 | thread_id = self.__worker_thread.native_id # 线程 ID 113 | self.__print_info(f'******************************运行结束({thread_id})******************************\n\n') 114 | 115 | def run_renamer(self, root_path_list: list[str]): 116 | self.__before_worker_thread_start() 117 | 118 | try: 119 | self.__config_file.load_config_dict() # 从配置文件中读取配置 120 | except JSONDecodeError as err: 121 | self.__print_error(f'配置文件解析失败:"{os.path.normpath(self.__config_file.file_path)}"') 122 | self.__print_error(f'JSONDecodeError: {str(err)}') 123 | self.__before_worker_thread_end() 124 | return 125 | except FileNotFoundError as err: 126 | self.__print_error(f'配置文件加载失败:"{os.path.normpath(self.__config_file.file_path)}"') 127 | self.__print_error(f'FileNotFoundError: {err.strerror}') 128 | self.__before_worker_thread_end() 129 | return 130 | 131 | # 检查配置是否合法 132 | strerror_list = self.__config_file.verify_config() 133 | if len(strerror_list) > 0: 134 | self.__print_error(f'配置文件验证失败:"{os.path.normpath(self.__config_file.file_path)}"' 135 | + "\n" 136 | + "\n\n".join(strerror_list)) 137 | self.__before_worker_thread_end() 138 | return 139 | 140 | config: Config = self.__config_file.config 141 | 142 | # 配置 scaner 143 | scaner = Scaner(max_depth=config['scaner_max_depth']) 144 | 145 | # 配置 scraper 146 | scraper_locale = config['scraper_locale'] 147 | scraper_http_proxy = config['scraper_http_proxy'] 148 | if scraper_http_proxy: 149 | proxies = { 150 | 'http': scraper_http_proxy, 151 | 'https': scraper_http_proxy 152 | } 153 | else: 154 | proxies = None 155 | scraper_connect_timeout = config['scraper_connect_timeout'] 156 | scraper_read_timeout = config['scraper_read_timeout'] 157 | scraper_sleep_interval = config['scraper_sleep_interval'] 158 | cached_scraper = CachedScraper( 159 | locale=Locale[scraper_locale], 160 | connect_timeout=scraper_connect_timeout, 161 | read_timeout=scraper_read_timeout, 162 | sleep_interval=scraper_sleep_interval, 163 | proxies=proxies) 164 | tags_option = { 165 | 'ordered_list': config['renamer_tags_ordered_list'], 166 | 'max_number': 999999 if config['renamer_tags_max_number'] == 0 else config['renamer_tags_max_number'], 167 | } 168 | 169 | # 配置 renamer 170 | renamer = Renamer( 171 | scaner=scaner, 172 | scraper=cached_scraper, 173 | template=config['renamer_template'], 174 | release_date_format=config['renamer_release_date_format'], 175 | delimiter=config['renamer_delimiter'], 176 | cv_list_left=config['renamer_cv_list_left'], 177 | cv_list_right=config['renamer_cv_list_right'], 178 | exclude_square_brackets_in_work_name_flag=config['renamer_exclude_square_brackets_in_work_name_flag'], 179 | renamer_illegal_character_to_full_width_flag=config['renamer_illegal_character_to_full_width_flag'], 180 | make_folder_icon=config['renamer_make_folder_icon'], 181 | remove_jpg_file=config['renamer_remove_jpg_file'], 182 | tags_option=tags_option, 183 | age_cat_map_gen=config['renamer_age_cat_map_gen'], 184 | age_cat_map_r15=config['renamer_age_cat_map_r15'], 185 | age_cat_map_r18=config['renamer_age_cat_map_r18'], 186 | age_cat_left=config['renamer_age_cat_left'], 187 | age_cat_right=config['renamer_age_cat_right'], 188 | age_cat_ignore_r18=config['renamer_age_cat_ignore_r18'], 189 | mode=config['renamer_mode'], 190 | move_root=config['renamer_move_root'], 191 | move_template=config['renamer_move_template'], 192 | series_name_left=config['renamer_series_name_left'], 193 | series_name_right=config['renamer_series_name_right'] 194 | ) 195 | 196 | # 执行重命名 197 | for root_path in root_path_list: 198 | try: 199 | renamer.rename(root_path) 200 | except Exception as err: 201 | Renamer.logger.error(f'[Unexpected exception] {str(err)}\n') 202 | traceback.print_exc() 203 | break 204 | 205 | self.__before_worker_thread_end() 206 | 207 | 208 | def get_application_path(): 209 | """ 210 | https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#run-time-information 211 | """ 212 | if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): 213 | # running in a PyInstaller bundle 214 | application_path = sys._MEIPASS 215 | else: 216 | # running in a normal Python process 217 | application_path = os.path.dirname(__file__) 218 | return application_path 219 | 220 | 221 | if __name__ == '__main__': 222 | app_path = get_application_path() 223 | icon_path = os.path.join(app_path, 'Letter_R_blue.ico') 224 | 225 | app = wx.App(False) 226 | frame = AppFrame(None) 227 | frame.SetIcon(wx.Icon(icon_path)) 228 | frame.SetTitle(f'DLSite 同人作品重命名工具 v{VERSION}') 229 | frame.Show(True) 230 | # start the applications 231 | app.MainLoop() 232 | -------------------------------------------------------------------------------- /renamer.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | import re 4 | from pathlib import Path 5 | from datetime import datetime 6 | 7 | from requests.exceptions import RequestException, ConnectionError, HTTPError, Timeout 8 | 9 | from scaner import Scaner 10 | from scraper import WorkMetadata, Scraper 11 | from ostool import move_folder, copy_with_symlink, normalize_path 12 | 13 | import stat 14 | 15 | import win32api 16 | # Windows 系统的保留字符 17 | # https://docs.microsoft.com/zh-cn/windows/win32/fileio/naming-a-file 18 | # <(小于) 19 | # >(大于) 20 | # : (冒号) 21 | # "(双引号) 22 | # /(正斜杠) 23 | # \ (反反) 24 | # | (竖线或竖线) 25 | # ? (问号) 26 | # * (星号) 27 | WINDOWS_RESERVED_CHARACTER_PATTERN = re.compile(r'[\\/*?:"<>|]') 28 | WINDOWS_RESERVED_CHARACTER_PATTERN_str = r'\/:*?"<>|' # 半角字符,原 29 | WINDOWS_RESERVED_CHARACTER_PATTERN_replace_str = '\/:*?"<>|' # 全角字符,替 30 | WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN = re.compile(r'[*?:"<>|]') 31 | WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN_str = r':*?"<>|' # 半角字符,原 32 | WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN_replace_str = ':*?"<>|' # 全角字符,替 33 | 34 | 35 | def _get_logger(): 36 | # create logger 37 | logger = logging.getLogger('Renamer') 38 | logger.setLevel(logging.DEBUG) 39 | 40 | # create console handler and set level to debug 41 | ch = logging.StreamHandler() 42 | ch.setLevel(logging.DEBUG) 43 | # create formatter 44 | formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 45 | # add formatter to ch 46 | ch.setFormatter(formatter) 47 | 48 | # add ch to logger 49 | logger.addHandler(ch) 50 | 51 | return logger 52 | 53 | 54 | class Renamer(object): 55 | logger = _get_logger() 56 | 57 | def __init__( 58 | self, 59 | scaner: Scaner, 60 | scraper: Scraper, 61 | template: str, # 模板 62 | # https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes 63 | release_date_format: str, # 日期格式 64 | delimiter, # 列表转字符串的分隔符 65 | cv_list_left, # CV列表的左侧分隔符 66 | cv_list_right, # CV列表的右侧分隔符 67 | exclude_square_brackets_in_work_name_flag, # 设为 True 时,移除 work_name 中【】及其间的内容 68 | renamer_illegal_character_to_full_width_flag, # 设为 True 时,新文件名将非法字符转为全角;为 False 时直接移除. 69 | make_folder_icon, # 设为 True 时,将会下载作品封面并将其设为文件夹封面 70 | remove_jpg_file, # 设为 True 时,将会保留下载的作品封面 71 | tags_option, # 标签相关设置 72 | # 年龄分级相关配置 73 | age_cat_map_gen: str, 74 | age_cat_map_r15: str, 75 | age_cat_map_r18: str, 76 | age_cat_left: str, 77 | age_cat_right: str, 78 | age_cat_ignore_r18: bool, 79 | series_name_left: str, 80 | series_name_right: str, 81 | mode: str, # RENAME/MOVE/LINK 82 | move_root: str, 83 | move_template: str 84 | ): 85 | if 'rjcode' not in template: 86 | raise ValueError # 重命名不能丢失 rjcode 87 | self.__scaner = scaner 88 | self.__scraper = scraper 89 | self.__template = template 90 | self.__release_date_format = release_date_format 91 | self.__delimiter = delimiter 92 | self.__cv_list_left = cv_list_left 93 | self.__cv_list_right = cv_list_right 94 | self.__exclude_square_brackets_in_work_name_flag = exclude_square_brackets_in_work_name_flag 95 | self.__renamer_illegal_character_to_full_width_flag = renamer_illegal_character_to_full_width_flag 96 | self.__make_folder_icon = make_folder_icon 97 | self.__remove_jpg_file = remove_jpg_file 98 | self.__tags_option = tags_option 99 | self.__age_cat_map_gen = age_cat_map_gen 100 | self.__age_cat_map_r15 = age_cat_map_r15 101 | self.__age_cat_map_r18 = age_cat_map_r18 102 | self.__age_cat_left = age_cat_left 103 | self.__age_cat_right = age_cat_right 104 | self.__age_cat_ignore_r18 = age_cat_ignore_r18 105 | self.__series_name_left = series_name_left 106 | self.__series_name_right = series_name_right 107 | self.__mode = mode 108 | self.__move_root = move_root 109 | self.__move_template = move_template 110 | 111 | def __format_filename_str(self, name: str): 112 | if name: 113 | if self.__renamer_illegal_character_to_full_width_flag: # 半角转全角 114 | name = name.translate(name.maketrans( 115 | WINDOWS_RESERVED_CHARACTER_PATTERN_str, WINDOWS_RESERVED_CHARACTER_PATTERN_replace_str)) 116 | else: # 直接移除 117 | name = WINDOWS_RESERVED_CHARACTER_PATTERN.sub('', name) 118 | return name.strip() 119 | else: 120 | return name 121 | 122 | 123 | def __compile_new_name(self, metadata: WorkMetadata): 124 | """ 125 | 根据作品的元数据编写出新的文件名 126 | """ 127 | if self.__mode == 'RENAME': 128 | template = self.__template 129 | template = self.__format_filename_str(template) 130 | else: 131 | template = self.__move_template 132 | if self.__renamer_illegal_character_to_full_width_flag: # 半角转全角 133 | template = template.translate(template.maketrans( 134 | WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN_str, WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN_replace_str)) 135 | else: # 直接移除 136 | template = WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN.sub('', template) 137 | template = template.strip() 138 | 139 | work_name = self.__format_filename_str(metadata['work_name']) 140 | if self.__exclude_square_brackets_in_work_name_flag: 141 | work_name = re.sub(r'【.*?】', '', work_name).strip() 142 | maker_name = self.__format_filename_str(metadata['maker_name']) 143 | series_name = self.__format_filename_str(metadata['series_name']) 144 | 145 | new_name = template.replace('rjcode', metadata['rjcode']) 146 | new_name = new_name.replace('work_name', work_name) 147 | new_name = new_name.replace('maker_id', metadata['maker_id']) 148 | new_name = new_name.replace('maker_name', maker_name) 149 | if 'age_cat' in template: 150 | if self.__age_cat_ignore_r18 and metadata['age_category'] == 'R18': 151 | new_name = new_name.replace('age_cat', "") 152 | else: 153 | if metadata['age_category'] == 'GEN': 154 | age_cat = self.__age_cat_map_gen 155 | elif metadata['age_category'] == 'R15': 156 | age_cat = self.__age_cat_map_r15 157 | else: 158 | age_cat = self.__age_cat_map_r18 159 | new_name = new_name.replace('age_cat', self.__age_cat_left + age_cat + self.__age_cat_right) 160 | if 'series_name' in template: 161 | if series_name: 162 | new_name = new_name.replace('series_name', self.__series_name_left + series_name + self.__series_name_right) 163 | else: 164 | new_name = new_name.replace('series_name', '') 165 | if 'release_date' in template: 166 | release_date_obj = datetime.strptime(metadata['release_date'], '%Y-%m-%d').date() 167 | new_name = new_name.replace('release_date', release_date_obj.strftime(self.__release_date_format)) 168 | 169 | cv_list = list(map(self.__format_filename_str, metadata['cvs'])) # cv列表 170 | cv_list_str = self.__cv_list_left + self.__delimiter.join(cv_list) + self.__cv_list_right if len(cv_list) > 0 else '' 171 | new_name = new_name.replace('cv_list_str', cv_list_str) 172 | 173 | if "tags_list_str" in template: # 标签列表 174 | tags_list = [] 175 | tags_list_flag = [] 176 | for i in self.__tags_option['ordered_list']: # ordered_list中存在的标签 177 | if isinstance(i, str) and i in metadata['tags']: 178 | tags_list.append(i) 179 | tags_list_flag.append(i) 180 | elif isinstance(i, list) and i[0] in metadata['tags']: 181 | tags_list.append(i[1]) # 替换新标签 182 | tags_list_flag.append(i[0]) 183 | for i in metadata['tags']: # 剩余的标签 184 | if not i in tags_list_flag: 185 | tags_list.append(i) 186 | tags_list = tags_list[: self.__tags_option['max_number']] # 数量限制 187 | tags_list = list(map(self.__format_filename_str, tags_list)) 188 | tags_list_str = self.__delimiter.join(tags_list) # 转字符串,加分隔符 189 | new_name = new_name.replace('tags_list_str', tags_list_str) 190 | 191 | # 文件名中不能包含 Windows 系统的保留字符 192 | if self.__mode == 'RENAME': 193 | if self.__renamer_illegal_character_to_full_width_flag: # 半角转全角 194 | new_name = new_name.translate(new_name.maketrans( 195 | WINDOWS_RESERVED_CHARACTER_PATTERN_str, WINDOWS_RESERVED_CHARACTER_PATTERN_replace_str)) 196 | else: # 直接移除 197 | new_name = WINDOWS_RESERVED_CHARACTER_PATTERN.sub('', new_name) 198 | new_name = new_name.strip() 199 | else: 200 | if self.__renamer_illegal_character_to_full_width_flag: # 半角转全角 201 | new_name = new_name.translate(new_name.maketrans( 202 | WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN_str, WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN_replace_str)) 203 | else: # 直接移除 204 | new_name = WINDOWS_RESERVED_CHARACTER_IGNORE_SLASH_PATTERN.sub('', new_name) 205 | new_name = normalize_path(new_name) 206 | 207 | return new_name 208 | 209 | @staticmethod 210 | def __handle_request_exception(rjcode: str, task: str, err: RequestException): 211 | if isinstance(err, Timeout): 212 | # 请求超时 213 | Renamer.logger.warning(f'[{rjcode}] -> {task}失败[Timeout]:dlsite.com 请求超时!\n') 214 | elif isinstance(err, ConnectionError): 215 | # 遇到其它网络问题(如:DNS 查询失败、拒绝连接等) 216 | Renamer.logger.warning(f'[{rjcode}] -> {task}失败[ConnectionError]:{str(err)}\n') 217 | elif isinstance(err, HTTPError): 218 | # HTTP 请求返回了不成功的状态码 219 | Renamer.logger.warning(f'[{rjcode}] -> {task}失败[HTTPError]:{err.response.status_code} {err.response.reason}\n') 220 | elif isinstance(err, RequestException): 221 | # requests 引发的其它异常 222 | Renamer.logger.error(f'[{rjcode}] -> {task}失败[RequestException]:{str(err)}\n') 223 | 224 | def rename(self, root_path: str): 225 | work_folders = self.__scaner.scan(root_path) 226 | for rjcode, folder_path in work_folders: 227 | Renamer.logger.info(f'[{rjcode}] -> 发现 RJ 文件夹:"{os.path.normpath(folder_path)}"') 228 | dirname, basename = os.path.split(folder_path) 229 | 230 | # 爬取元数据 231 | try: 232 | metadata = self.__scraper.scrape_metadata(rjcode) 233 | except RequestException as err: 234 | Renamer.__handle_request_exception(rjcode, '爬取元数据', err) # 爬取元数据失败 235 | continue 236 | 237 | # 重命名文件夹 238 | new_basename = self.__compile_new_name(metadata) 239 | new_folder_path = os.path.join(dirname, new_basename) if self.__mode == 'RENAME' else os.path.join(self.__move_root, new_basename) 240 | try: 241 | if self.__mode == 'MOVE': 242 | # print('MOVE', folder_path, new_folder_path) 243 | move_folder(folder_path, new_folder_path) 244 | elif self.__mode == 'LINK': 245 | # print('LINK', folder_path, new_folder_path) 246 | copy_with_symlink(folder_path, os.path.join(new_folder_path, basename)) 247 | else: 248 | os.rename(folder_path, new_folder_path) 249 | Renamer.logger.info(f'[{rjcode}] -> 重命名({self.__mode})成功:"{os.path.normpath(new_folder_path)}"') 250 | except FileExistsError as err: 251 | filename2 = os.path.normpath(err.filename2) 252 | Renamer.logger.warning(f'[{rjcode}] -> 重命名({self.__mode})失败[FileExistsError]:{err.strerror}目标路径:"{filename2}"\n') 253 | continue 254 | except OSError as err: 255 | err_msg = f'[{rjcode}] -> 重命名失败[OSError]:{str(err)}' 256 | if err.winerror == 1314: 257 | err_msg = err_msg + "\n" + "Windows 下创建符号链接目录需要管理员权限,或启用 设置-系统-开发者选项-开发人员模式" 258 | Renamer.logger.error(err_msg + "\n") 259 | break 260 | 261 | # 修改封面 262 | if self.__make_folder_icon: 263 | try: 264 | icon_name, _ = Renamer.changeIcon(self, rjcode, metadata['cover_url'], new_folder_path) # 修改封面 265 | except RequestException as err: 266 | Renamer.__handle_request_exception(rjcode, '下载封面图', err) # 下载封面图失败 267 | continue 268 | except OSError as err: 269 | Renamer.logger.error(f'[{rjcode}] -> 修改封面失败[OSError]:{str(err)}') 270 | continue 271 | 272 | Renamer.logger.info(f'[{rjcode}] -> 处理结束\n') 273 | 274 | # 修改文件夹封面 275 | def changeIcon(self, rjcode: str, cover_url: str, icon_dir: str): 276 | os.chmod(icon_dir, stat.S_IREAD) 277 | icon_name, jpg_name = self.__scraper.scrape_icon(rjcode, cover_url, icon_dir) 278 | 279 | ini_file_path = Path(os.path.join(icon_dir, "desktop.ini")) 280 | if not os.path.exists(ini_file_path): 281 | # 编写 desktop.ini 282 | iniline1 = "[.ShellClassInfo]" 283 | iniline2 = "IconResource=" + "\"" + icon_name + "\"" + ",0" 284 | iniline3 = "[ViewState]" + "\n" + "Mode=" + "\n" + "Vid=" + "\n" + "FolderType=StorageProviderGeneric" 285 | iniline = iniline1 + "\n" + iniline2 + "\n" + iniline3 286 | 287 | # 写入 desktop.ini 288 | with open(ini_file_path, "w", encoding='utf-8') as inifile: 289 | inifile.write(iniline) 290 | inifile.close() 291 | 292 | # 隐藏 desktop.ini 文件 & .ico 文件 293 | win32api.SetFileAttributes(str(ini_file_path), 38) 294 | win32api.SetFileAttributes(os.path.join(icon_dir, icon_name), 38) 295 | # cmd1 = icon_dir[0:2] 296 | # cmd2 = "cd " + '\"' + icon_dir + '\"' 297 | # cmd3 = "attrib +h +s " + 'desktop.ini' 298 | # cmd4 = "attrib +h +s " + icon_name 299 | # cmd = cmd1 + " & " + cmd2 + " & " + cmd3 + " & " + cmd4 300 | # os.system(cmd) # 运行 cmd 301 | Renamer.logger.info(f'[{rjcode}] -> 修改封面成功:"{icon_name}"') 302 | 303 | if self.__remove_jpg_file: 304 | # 删除 .jpg 文件 305 | jpg_path = Path(os.path.join(icon_dir, jpg_name)) 306 | jpg_path.unlink(missing_ok=True) 307 | 308 | return icon_name, jpg_name 309 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------