├── logs └── .gitkeep ├── requirements.txt ├── .github └── ISSUE_TEMPLATE.md ├── config.json ├── .travis.yml ├── qphoto ├── model.py └── __init__.py ├── common ├── __init__.py └── logger.py ├── README.md ├── main.py ├── worker └── __init__.py ├── .gitignore └── LICENSE /logs/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | qqlib==1.1.1 -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Commit Id: 2 | 问题描述: 3 | 操作系统版本: 4 | Python版本: 5 | 6 | 复现步骤: 7 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "account": "10000", 3 | "password": "password", 4 | "target_qq": "100001" 5 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: "python" 2 | 3 | python: 4 | - "2.7" 5 | 6 | install: 7 | - pip install flake8 8 | 9 | script: 10 | - flake8 --ignore=W191,F401,E501,F403 . 11 | 12 | notifications: 13 | email: 14 | on_success: change 15 | on_failure: always -------------------------------------------------------------------------------- /qphoto/model.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | ''' 5 | 实体类 6 | Licensed to MIT 7 | ''' 8 | from collections import namedtuple 9 | 10 | Album = namedtuple('Album', ['uid', 'name', 'count']) 11 | Photo = namedtuple('Photo', ['url', 'name', 'album']) 12 | -------------------------------------------------------------------------------- /common/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | # pylint: disable=W0601 4 | 5 | ''' 6 | 全局变量类 7 | Licensed to MIT 8 | ''' 9 | 10 | 11 | def set_queue(value): 12 | """ 13 | 设置工作队列。 14 | """ 15 | global WORKQUEUE 16 | WORKQUEUE = value 17 | 18 | 19 | def get_queue(): 20 | """ 21 | 获取工作队列。 22 | """ 23 | return WORKQUEUE 24 | 25 | 26 | def set_main_thread_pending(value): 27 | """ 28 | 设置主线程是否已经处于等待状态 29 | """ 30 | global ISPENDING 31 | ISPENDING = value 32 | 33 | 34 | def get_main_thread_pending(): 35 | """ 36 | 获取主线程是否已经处于等待状态 37 | """ 38 | return ISPENDING 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 因为官方登陆的API已经做了变更,加上自己没有太多精力和时间再维护这个库,所以废弃这个库。 3 | 4 | # 简介 5 | [![Platform](https://img.shields.io/badge/Language-Python%202.7-blue.svg)](https://www.python.org/) 6 | 8 | 9 | 批量下载QQ空间相册。 10 | 11 | 目前支持下载的包括: 12 | 1. 对所有人公开的相册; 13 | 2. 好友中好友可见的相册。 14 | 15 | # 使用方法 16 | * 安装[Python 2.7.13](https://www.python.org/downloads/release/python-2713/); 17 | * 安装依赖:pip install -r requirements.txt; 18 | * 修改配置文件`config.json` 19 | * cmd中键入Python main.py运行。 20 | 21 | # 依赖列表 22 | qqlib:https://github.com/gera2ld/qqlib 23 | 24 | # 报告Issue 25 | 欢迎报告Issue,请确保Issue的描述信息的完整,以下Issue可能无法修复: 26 | * Issue信息描述并未按照模板描述; 27 | * 自行修改代码以后导致的Issue。 28 | 29 | # 配置文件参考 30 | | 参数名 | 类型 | 说明 | 31 | |:--------------:|:-------------:|:------------:| 32 | | account | 必须 | 登录的QQ | 33 | | password | 必须 | 登录QQ的密码 | 34 | | target_qq | 必须 | 下载相册的QQ | 35 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | # pylint: disable=C0103 4 | 5 | ''' 6 | 批量下载入口函数 7 | Licensed to MIT 8 | ''' 9 | 10 | import os 11 | import json 12 | import Queue 13 | import qphoto 14 | from worker import Worker 15 | import common 16 | from common import logger 17 | 18 | logger = logger.Logger() 19 | logger.info(u'Logger初始化完成') 20 | logger.info(u'读取配置文件') 21 | confileFileName = 'config.json' 22 | env = os.environ.get('ENV') 23 | if env == "DEV": 24 | confileFileName = 'config.dev.json' 25 | configFile = file(confileFileName) 26 | config = json.load(configFile) 27 | configFile.close() 28 | logger.info(u'读取配置文件完成') 29 | qz = qphoto.QzonePhoto(logger) 30 | logger.info(u'登陆QQ:{}'.format(config['account'])) 31 | qz.login(config['account'], config['password']) 32 | logger.info(u'登陆完成') 33 | common.set_queue(Queue.Queue()) 34 | common.set_main_thread_pending(False) 35 | worker_count = 2 36 | worker_list = [] 37 | while worker_count > 0: 38 | worker = Worker(logger) 39 | worker.setDaemon(False) 40 | worker.start() 41 | worker_count -= 1 42 | worker_list.append(worker) 43 | qz.savephotos(config['target_qq']) 44 | logger.info(u'主线程已经将所有任务放到队列中') 45 | common.set_main_thread_pending(True) 46 | while True: 47 | done = True 48 | for worker in worker_list: 49 | if worker.isAlive(): 50 | done = False 51 | break 52 | if done: 53 | logger.info(u'所有进程已经结束。') 54 | break 55 | -------------------------------------------------------------------------------- /worker/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | # pylint: disable=W0703 4 | 5 | ''' 6 | 任务执行重试模块 7 | Licensed to MIT 8 | ''' 9 | 10 | import time 11 | import traceback 12 | import Queue 13 | import threading 14 | import common 15 | 16 | 17 | class Worker(threading.Thread): 18 | """ 19 | 任务重试和执行的类。 20 | """ 21 | def __init__(self, logger, maxretrycount=3, maxdeleytime=1): 22 | threading.Thread.__init__(self) 23 | self.max_retry_count = maxretrycount 24 | self.max_deley_time = maxdeleytime 25 | self.logger = logger 26 | 27 | def run(self): 28 | while True: 29 | if common.get_queue().empty(): 30 | if common.get_main_thread_pending(): 31 | self.logger.info(u'所有任务已经完成,此线程:{0}将结束'.format(self.getName())) 32 | break 33 | continue 34 | action, arg = common.get_queue().get(block=True) 35 | retry_count = 0 36 | while retry_count <= self.max_retry_count: 37 | try: 38 | action(*arg) 39 | self.logger.info(u'下载队列中剩余的任务个数为{0}'.format(common.get_queue().qsize())) 40 | break 41 | except Exception: 42 | traceback.print_exc() 43 | self.logger.info(u'{0}秒后将重试'.format(self.max_deley_time)) 44 | retry_count += 1 45 | time.sleep(self.max_deley_time) 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # Jupyter Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | .venv/ 83 | venv/ 84 | ENV/ 85 | 86 | # Spyder project settings 87 | .spyderproject 88 | 89 | # Rope project settings 90 | .ropeproject 91 | 92 | # Visual Studio Code settings 93 | .vscode 94 | 95 | # Download Folder 96 | qzonephoto 97 | 98 | # test class 99 | app.py 100 | test.* 101 | config.dev.json 102 | 103 | # log 104 | !logs/.gitkeep -------------------------------------------------------------------------------- /common/logger.py: -------------------------------------------------------------------------------- 1 | # !/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # pylint: disable = C0103 4 | 5 | import logging 6 | from logging.handlers import RotatingFileHandler 7 | from logging import StreamHandler 8 | import os 9 | 10 | 11 | class Logger(object): 12 | """ 13 | 给全局用的logger,输出到文件 14 | """ 15 | LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s' 16 | LOG_DEBUG = 'debug.log' 17 | LOG_INFO = 'info.log' 18 | LOG_WARNING = 'warning.log' 19 | LOG_ERROR = 'error.log' 20 | 21 | logger = None 22 | 23 | def __init__(self): 24 | self.debugLogger = self.initlogger(logging.DEBUG, self.LOG_DEBUG) 25 | self.infoLogger = self.initlogger(logging.INFO, self.LOG_INFO) 26 | self.warningLogger = self.initlogger(logging.WARNING, self.LOG_WARNING) 27 | self.errorLogger = self.initlogger(logging.ERROR, self.LOG_ERROR) 28 | 29 | def debug(self, msg): 30 | """ 31 | 输出debug信息到文件 32 | """ 33 | self.debugLogger.debug(msg) 34 | 35 | def info(self, msg): 36 | """ 37 | 输出info信息到文件 38 | """ 39 | self.infoLogger.info(msg) 40 | 41 | def warning(self, msg): 42 | """ 43 | 输出warning信息到文件 44 | """ 45 | self.warningLogger.warning(msg) 46 | 47 | def error(self, msg): 48 | """ 49 | 输出error信息到文件 50 | """ 51 | self.errorLogger.error(msg) 52 | 53 | def initlogger(self, level, name): 54 | """ 55 | 初始化logger 56 | """ 57 | cwd = os.getcwd() 58 | formatter = logging.Formatter(self.LOG_FORMAT) 59 | logger = logging.getLogger(name) 60 | logger.setLevel(level) 61 | fh = RotatingFileHandler(os.path.join(cwd, 'logs', name), 62 | maxBytes=10 * 1024 * 1024, 63 | backupCount=5) 64 | fh.setFormatter(formatter) 65 | fh.setLevel(level) 66 | logger.addHandler(fh) 67 | if level is not logging.DEBUG: 68 | ch = StreamHandler() 69 | ch.setFormatter(formatter) 70 | ch.setLevel(level) 71 | logger.addHandler(ch) 72 | return logger 73 | -------------------------------------------------------------------------------- /qphoto/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | # pylint: disable=W0703 4 | # pylint: disable=W1401 5 | # pylint: disable=E1101 6 | 7 | ''' 8 | QQ空间相册查询下载模块 9 | Licensed to MIT 10 | ''' 11 | 12 | import json 13 | import traceback 14 | import urllib2 15 | import os 16 | import random 17 | import re 18 | from qqlib import qzone 19 | import qqlib 20 | from qphoto.model import Album, Photo 21 | import common 22 | 23 | 24 | class QzonePhoto(object): 25 | """ 26 | 查询QQ空间相册并下载的类。 27 | """ 28 | 29 | # 地址更新来源:https://github.com/fooofei/py_qzone_photo 30 | albumbase = ('https://h5.qzone.qq.com/proxy/domain/tjalist.photo.qzone.qq.com/fcgi-bin/' 31 | 'fcg_list_album_v3?g_tk={gtk}&t={t}&hostUin={dest_user}&uin={user}&appid=4' 32 | '&inCharset=gbk&outCharset=gbk&source=qzone&plat=qzone&format=jsonp&callbackFun=') 33 | photobase = ('https://h5.qzone.qq.com/proxy/domain/tjplist.photo.qzone.qq.com/fcgi-bin/' 34 | 'cgi_list_photo?g_tk={gtk}&t={t}&mode=0&idcNum=5&hostUin={dest_user}' 35 | '&topicId={album_id}&noTopic=0&uin={user}&pageStart=0&pageNum=9000&inCharset=gbk' 36 | '&outCharset=gbk&source=qzone&plat=qzone&outstyle=json&format=jsonp&json_esc=1') 37 | 38 | def __init__(self, logger): 39 | self.logger = logger 40 | self.cookie = None 41 | self.qzone_g_tk = None 42 | self.number = None 43 | self.session = None 44 | 45 | def login(self, number, password): 46 | """ 47 | 登录QQ。 48 | 如果需要验证码,会保存验证码到本地,需要手动识别输入 49 | """ 50 | request = qzone.QZone(number, password) 51 | try: 52 | request.login() 53 | except qqlib.NeedVerifyCode as exc: 54 | if exc.message: 55 | print('Error:', exc.message) 56 | verifier = exc.verifier 57 | open('verify.jpg', 'wb').write(verifier.fetch_image()) 58 | vcode = input(u'验证码已保存到verify.jpg,请输入验证码(带单引号):') 59 | request.verifier.verify(vcode) 60 | request.login() 61 | self.session = request.session 62 | self.number = number 63 | self.qzone_g_tk = request.g_tk() 64 | 65 | def getablums(self, number): 66 | """ 67 | 获取相册集。 68 | 可能会遇到未登录的错误,或者解码失败的错误。 69 | 查询失败会返回一个空的集合。 70 | """ 71 | ablums = list() 72 | requesturl = self.albumbase.format( 73 | gtk=self.qzone_g_tk, t=random.Random().random(), dest_user=number, user=self.number) 74 | content = None 75 | response = None 76 | try: 77 | response = self.session.get(requesturl, timeout=8) 78 | content = response.content.decode('gbk') 79 | self.logger.debug(u'获取{0}的相册内容:{1}'.format(number, content)) 80 | except Exception: 81 | self.logger.error(u'获取{0}的相册集失败。地址: {1}'.format(number, requesturl)) 82 | traceback.print_exc() 83 | return ablums 84 | finally: 85 | if response: 86 | response.close() 87 | try: 88 | if content: 89 | content = content.replace('_Callback(', '') 90 | content = content.replace(');', '') 91 | content = json.loads(content) 92 | if 'data' in content and 'mode' in content['data']: 93 | mode = content['data']['mode'] 94 | if mode == 2: 95 | ablums = self.getablumssortbylist(number, content) 96 | elif mode == 3: 97 | ablums = self.getablumssortbyclass(number, content) 98 | else: 99 | self.logger.error(u'无法识别{0}的排序模式。'.format(number)) 100 | else: 101 | self.logger.error(u'无法识别{0}的Json格式。'.format(number)) 102 | except Exception: 103 | self.logger.error(u'转换{0}的相册集Json失败。'.format(number)) 104 | traceback.print_exc() 105 | return ablums 106 | 107 | def getablumssortbylist(self, number, content): 108 | """ 109 | 解析普通视图分类 110 | """ 111 | self.logger.debug(u'以普通视图分类方式获取{0}的相册。'.format(number)) 112 | ablums = list() 113 | if 'albumListModeSort' in content['data']: 114 | for item in content['data']['albumListModeSort']: 115 | ablums.append(Album._make([item['id'], item['name'], item['total']])) 116 | return ablums 117 | 118 | def getablumssortbyclass(self, number, content): 119 | """ 120 | 解析分组视图分类 121 | """ 122 | self.logger.debug(u'以分类视图分类方式获取{0}的相册。'.format(number)) 123 | ablums = list() 124 | if 'albumListModeClass' in content['data']: 125 | for item in content['data']['albumListModeClass']: 126 | if 'albumList' in item and item['albumList']: 127 | for album in item['albumList']: 128 | ablums.append(Album._make([album['id'], album['name'], album['total']])) 129 | return ablums 130 | 131 | def getphotosbyalbum(self, album, number): 132 | """ 133 | 获取相册。 134 | 可能会遇到未登录的错误,或者解码失败的错误。 135 | """ 136 | photos = list() 137 | requesturl = self.photobase.format( 138 | gtk=self.qzone_g_tk, t=random.Random().random(), 139 | dest_user=number, user=self.number, album_id=album.uid) 140 | content = None 141 | response = None 142 | try: 143 | response = self.session.get(requesturl, timeout=8) 144 | content = response.content.decode('gbk') 145 | self.logger.debug(u'获取{0}的相册内容:{1}'.format(number, content)) 146 | except Exception: 147 | self.logger.error('获取{0}的相册失败。地址:{1}'.format(number, requesturl)) 148 | traceback.print_exc() 149 | return photos 150 | finally: 151 | if response: 152 | response.close() 153 | content = content.replace('_Callback(', '') 154 | content = content.replace(');', '') 155 | try: 156 | if content: 157 | content = content.replace('_Callback(', '') 158 | content = content.replace(');', '') 159 | content = json.loads(content) 160 | if 'data' in content and 'photoList' in content['data']: 161 | for item in content['data']['photoList']: 162 | url = ('origin_url' in item and item['origin_url'] or item['url']) 163 | photos.append(Photo._make([url, item['name'], album])) 164 | except Exception: 165 | self.logger.error('转换{0}的相册Json失败'.format(number)) 166 | traceback.print_exc() 167 | return photos 168 | 169 | @classmethod 170 | def savephoto(cls, args): 171 | """ 172 | 保存图片 173 | """ 174 | logger, session, photo, number, index, count = args 175 | url = photo.url.replace('\\', '') 176 | fixname = cls.fixinvaildname(photo.album.name, number, index) 177 | folder = cls.getsavepath(number, index, fixname) 178 | fixname = cls.fixinvaildname(photo.name, number, index) 179 | path = os.path.join(folder, u'{0}_{1}.jpeg'.format(count, fixname)) 180 | if os.path.exists(path): 181 | logger.info(u'{0}第{1}个相册的第{2}张照片已经存在。相册名:{3},照片名:{4}'.format( 182 | number, index, count, photo.album.name, photo.name)) 183 | return 184 | logger.info(u'下载{0}第{1}个相册的第{2}张照片。相册名:{3},照片名:{4}'.format( 185 | number, index, count, photo.album.name, photo.name)) 186 | response = session.get(url, timeout=8) 187 | content = response.content 188 | with open(path, "wb") as stream: 189 | stream.write(content) 190 | stream.close() 191 | response.close() 192 | 193 | @classmethod 194 | def getsavepath(cls, number, index, albumname): 195 | """ 196 | 创建并返回保存图片的路径 197 | """ 198 | base = os.path.join(os.getcwd(), u'qzonephoto') 199 | if not os.path.exists(base): 200 | os.mkdir(base) 201 | qqpath = os.path.join(base, u'{0}'.format(number)) 202 | if not os.path.exists(qqpath): 203 | os.mkdir(qqpath) 204 | fixname = cls.fixinvaildname(albumname, number, index) 205 | albumpath = os.path.join(qqpath, u'{0}_{1}'.format(index, fixname)) 206 | if not os.path.exists(albumpath): 207 | os.mkdir(albumpath) 208 | return albumpath 209 | 210 | @classmethod 211 | def fixinvaildname(cls, name, number, index): 212 | """ 213 | 修复空文件名或者不符合命名规范的文件名 214 | """ 215 | fixname = None 216 | if name: 217 | fixname = re.sub('[\\\/:*?"<>|]', '-', name) 218 | else: 219 | fixname = u'renamed_{0}_{1}'.format(number, index) 220 | return fixname 221 | 222 | def savephotos(self, number, maxphotocount=0): 223 | """保存相册。 224 | 查询相册并保存图片 225 | """ 226 | photocount = 0 227 | self.logger.info(u'获取:{0}的相册信息。'.format(number)) 228 | ablums = self.getablums(number) 229 | if len(ablums) > 0: 230 | for index, ablum in enumerate(ablums): 231 | if ablum.count > 0: 232 | photos = self.getphotosbyalbum(ablum, number) 233 | for count, photo in enumerate(photos): 234 | if maxphotocount is not 0 and photocount >= maxphotocount: 235 | self.logger.info(u'已经达到指定的最大下载个数:{0}'.format(photocount)) 236 | return 237 | if common.get_queue().qsize() >= 1000: 238 | self.logger.info(u'队列任务书已经达到1000,等待执行完后再继续') 239 | while True: 240 | if common.get_queue().qsize() <= 500: 241 | break 242 | common.get_queue().put((self.savephoto, 243 | [(self.logger, 244 | self.session, 245 | photo, 246 | number, 247 | index + 1, 248 | count + 1)]), 249 | block=True) 250 | photocount += 1 251 | self.logger.info(u'已经将{0}的照片放到下载队列中。'.format(number)) 252 | else: 253 | self.logger.info(u'获取:{0}的相册信息的个数为0。'.format(number)) 254 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------