├── .github └── workflows │ └── generate.yml ├── .gitignore ├── LICENSE ├── README.md ├── anti-ad-adaway.txt └── transfer.py /.github/workflows/generate.yml: -------------------------------------------------------------------------------- 1 | name: Generate AdAway block hosts file 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | jobs: 9 | transfer: 10 | runs-on: ubuntu-latest 11 | 12 | env: 13 | UPSTREAM_REPO_NAME: "privacy-protection-tools/anti-AD" 14 | UPSTREAM_REPO_REF: "master" 15 | UPSTREAM_REPO_PATH: "${{ github.workspace }}/upstream" 16 | OUTPUT_FILE_NAME: "anti-ad-adaway.txt" 17 | 18 | steps: 19 | - name: Checkout self repo 20 | uses: actions/checkout@v3 21 | 22 | - name: Checkout upstream repo 23 | uses: actions/checkout@v3 24 | with: 25 | repository: ${{ env.UPSTREAM_REPO_NAME }} 26 | ref: ${{ env.UPSTREAM_REPO_REF }} 27 | path: ${{ env.UPSTREAM_REPO_PATH }} 28 | 29 | - name: Setup Python 30 | uses: actions/setup-python@v4 31 | 32 | - name: Transfer file 33 | run: | 34 | python transfer.py ${{ env.UPSTREAM_REPO_PATH }}/anti-ad-domains.txt ${{ env.OUTPUT_FILE_NAME }} 35 | 36 | - name: Get head commit sha of upstream repo 37 | id: get-head-sha 38 | run: | 39 | echo "head_sha=$(cd ${{ env.UPSTREAM_REPO_PATH }} && git rev-parse HEAD)" >> $GITHUB_OUTPUT 40 | 41 | - name: Commit files 42 | run: | 43 | git config --local user.email "action@github.com" 44 | git config --local user.name "GitHub Action" 45 | git add ${{ env.OUTPUT_FILE_NAME }} 46 | if ! git diff-index --quiet HEAD; then 47 | git commit -m "Sync with upstream ${{ env.UPSTREAM_REPO_NAME }}@${{ steps.get-head-sha.outputs.head_sha }}" 48 | fi 49 | 50 | - name: Push changes 51 | uses: ad-m/github-push-action@master 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/macos,visualstudiocode,python 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=macos,visualstudiocode,python 3 | 4 | ### macOS ### 5 | # General 6 | .DS_Store 7 | .AppleDouble 8 | .LSOverride 9 | 10 | # Icon must end with two \r 11 | Icon 12 | 13 | 14 | # Thumbnails 15 | ._* 16 | 17 | # Files that might appear in the root of a volume 18 | .DocumentRevisions-V100 19 | .fseventsd 20 | .Spotlight-V100 21 | .TemporaryItems 22 | .Trashes 23 | .VolumeIcon.icns 24 | .com.apple.timemachine.donotpresent 25 | 26 | # Directories potentially created on remote AFP share 27 | .AppleDB 28 | .AppleDesktop 29 | Network Trash Folder 30 | Temporary Items 31 | .apdisk 32 | 33 | ### macOS Patch ### 34 | # iCloud generated files 35 | *.icloud 36 | 37 | ### Python ### 38 | # Byte-compiled / optimized / DLL files 39 | __pycache__/ 40 | *.py[cod] 41 | *$py.class 42 | 43 | # C extensions 44 | *.so 45 | 46 | # Distribution / packaging 47 | .Python 48 | build/ 49 | develop-eggs/ 50 | dist/ 51 | downloads/ 52 | eggs/ 53 | .eggs/ 54 | lib/ 55 | lib64/ 56 | parts/ 57 | sdist/ 58 | var/ 59 | wheels/ 60 | share/python-wheels/ 61 | *.egg-info/ 62 | .installed.cfg 63 | *.egg 64 | MANIFEST 65 | 66 | # PyInstaller 67 | # Usually these files are written by a python script from a template 68 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 69 | *.manifest 70 | *.spec 71 | 72 | # Installer logs 73 | pip-log.txt 74 | pip-delete-this-directory.txt 75 | 76 | # Unit test / coverage reports 77 | htmlcov/ 78 | .tox/ 79 | .nox/ 80 | .coverage 81 | .coverage.* 82 | .cache 83 | nosetests.xml 84 | coverage.xml 85 | *.cover 86 | *.py,cover 87 | .hypothesis/ 88 | .pytest_cache/ 89 | cover/ 90 | 91 | # Translations 92 | *.mo 93 | *.pot 94 | 95 | # Django stuff: 96 | *.log 97 | local_settings.py 98 | db.sqlite3 99 | db.sqlite3-journal 100 | 101 | # Flask stuff: 102 | instance/ 103 | .webassets-cache 104 | 105 | # Scrapy stuff: 106 | .scrapy 107 | 108 | # Sphinx documentation 109 | docs/_build/ 110 | 111 | # PyBuilder 112 | .pybuilder/ 113 | target/ 114 | 115 | # Jupyter Notebook 116 | .ipynb_checkpoints 117 | 118 | # IPython 119 | profile_default/ 120 | ipython_config.py 121 | 122 | # pyenv 123 | # For a library or package, you might want to ignore these files since the code is 124 | # intended to run in multiple environments; otherwise, check them in: 125 | # .python-version 126 | 127 | # pipenv 128 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 129 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 130 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 131 | # install all needed dependencies. 132 | #Pipfile.lock 133 | 134 | # poetry 135 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 136 | # This is especially recommended for binary packages to ensure reproducibility, and is more 137 | # commonly ignored for libraries. 138 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 139 | #poetry.lock 140 | 141 | # pdm 142 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 143 | #pdm.lock 144 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 145 | # in version control. 146 | # https://pdm.fming.dev/#use-with-ide 147 | .pdm.toml 148 | 149 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 150 | __pypackages__/ 151 | 152 | # Celery stuff 153 | celerybeat-schedule 154 | celerybeat.pid 155 | 156 | # SageMath parsed files 157 | *.sage.py 158 | 159 | # Environments 160 | .env 161 | .venv 162 | env/ 163 | venv/ 164 | ENV/ 165 | env.bak/ 166 | venv.bak/ 167 | 168 | # Spyder project settings 169 | .spyderproject 170 | .spyproject 171 | 172 | # Rope project settings 173 | .ropeproject 174 | 175 | # mkdocs documentation 176 | /site 177 | 178 | # mypy 179 | .mypy_cache/ 180 | .dmypy.json 181 | dmypy.json 182 | 183 | # Pyre type checker 184 | .pyre/ 185 | 186 | # pytype static type analyzer 187 | .pytype/ 188 | 189 | # Cython debug symbols 190 | cython_debug/ 191 | 192 | # PyCharm 193 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 194 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 195 | # and can be added to the global gitignore or merged into this file. For a more nuclear 196 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 197 | #.idea/ 198 | 199 | ### Python Patch ### 200 | # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration 201 | poetry.toml 202 | 203 | 204 | ### VisualStudioCode ### 205 | .vscode/* 206 | !.vscode/settings.json 207 | !.vscode/tasks.json 208 | !.vscode/launch.json 209 | !.vscode/extensions.json 210 | !.vscode/*.code-snippets 211 | 212 | # Local History for Visual Studio Code 213 | .history/ 214 | 215 | # Built Visual Studio Code Extensions 216 | *.vsix 217 | 218 | ### VisualStudioCode Patch ### 219 | # Ignore all local history of files 220 | .history 221 | .ionide 222 | 223 | # End of https://www.toptal.com/developers/gitignore/api/macos,visualstudiocode,python 224 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 mrchi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # adaway-hosts 2 | 3 | [![Generate AdAway block hosts file](https://github.com/mrchi/adaway-hosts/actions/workflows/generate.yml/badge.svg)](https://github.com/mrchi/adaway-hosts/actions/workflows/generate.yml) 4 | 5 | 以 [privacy\-protection\-tools/anti\-AD](https://github.com/privacy-protection-tools/anti-AD) 项目为上游,生成 [AdAway](https://adaway.org/) 使用的 block host 列表。 6 | 7 | --- 8 | 9 | - AdAway 是一款面向安卓设备的 FOSS 广告拦截 App,基于 Hosts 规则。 10 | - anti-AD 是一个中文区比较流行的广告过滤列表。 11 | 12 | anti-AD 没有提供对 AdAway 文件格式的支持,后续可能也不会有,见讨论 [请求新增Hosts格式 · Issue \#287 · privacy\-protection\-tools/anti\-AD](https://github.com/privacy-protection-tools/anti-AD/issues/287))。 13 | 14 | 本项目基于 anti-AD 的 `anti-ad-domains.txt`,生成了 AdAway 可用的 block host 列表。由 GitHub actions 每天定时更新。 15 | 16 | 你可以通过以下链接订阅该列表 17 | 18 | [https://raw.githubusercontent.com/mrchi/adaway-hosts/main/anti-ad-adaway.txt](https://raw.githubusercontent.com/mrchi/adaway-hosts/main/anti-ad-adaway.txt) 19 | -------------------------------------------------------------------------------- /transfer.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | import pathlib 4 | import sys 5 | 6 | REDIRECT_HOST = "127.0.0.1" 7 | 8 | 9 | def transfer(input_file: pathlib.Path, output_file: pathlib.Path): 10 | with input_file.open(mode="r") as input_fp, output_file.open(mode="w") as output_fp: 11 | for line in input_fp: 12 | if not line: 13 | continue 14 | elif line.startswith("#"): 15 | output_fp.write(line) 16 | else: 17 | output_fp.write(REDIRECT_HOST + " " + line) 18 | 19 | 20 | if __name__ == "__main__": 21 | transfer( 22 | input_file=pathlib.Path(sys.argv[1]), 23 | output_file=pathlib.Path(sys.argv[2]), 24 | ) 25 | --------------------------------------------------------------------------------