-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 818a6b7
Showing
6 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Metalloriff | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# anime-downloader | ||
A cross-platform CLI python script to download 1080p anime using animension.to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import json | ||
import os | ||
import re | ||
import shutil | ||
import sys | ||
from os import path, system | ||
|
||
import m3u8_To_MP4 | ||
import requests | ||
from alive_progress import alive_bar | ||
|
||
clear = lambda: system("cls" if sys.platform == "win32" else "clear") | ||
|
||
def argument(arg, default = None): | ||
if arg in sys.argv: | ||
return sys.argv[sys.argv.index(arg) + 1] | ||
return default | ||
|
||
api = "https://animension.to/public-api" | ||
|
||
clear() | ||
if not "--name" in sys.argv: | ||
print("Search anime:") | ||
name = argument("--name") or input() | ||
|
||
clear() | ||
dub = "--dub" in sys.argv | ||
sub = "--sub" in sys.argv | ||
|
||
if not dub and not sub: | ||
print("Sub or Dub? (Press enter to skip filtering)") | ||
r = input() | ||
|
||
if "sub" in r.lower(): | ||
sub = True | ||
elif "dub" in r.lower(): | ||
dub = True | ||
|
||
filtering = "" | ||
if sub: | ||
filtering = "&dub=0" | ||
elif dub: | ||
filtering = "&dub=1" | ||
|
||
clear() | ||
results = json.loads(requests.get(f"{api}/search.php?search_text={name}&page=1&sort=az{filtering}").content) | ||
|
||
def select_anime(): | ||
try: | ||
idx = 1 | ||
for name, id, cover_uri, is_sub in results: | ||
print(f"{idx}) {name}") | ||
|
||
idx += 1 | ||
|
||
print() | ||
print("Select anime:") | ||
idx = int(input()) | ||
|
||
if idx < 1 or idx > len(results): | ||
raise | ||
return results[idx - 1] | ||
except: | ||
clear() | ||
|
||
print("Invalid response, please enter a selection number from below.") | ||
print() | ||
|
||
return select_anime() | ||
|
||
anime, id, cover, _ = select_anime() | ||
episodes = json.loads(requests.get(f"{api}/episodes.php?id={id}").content)[::-1] | ||
fp = path.join(os.getcwd(), anime) | ||
|
||
os.makedirs(fp, exist_ok=True) | ||
|
||
def download_cover(): | ||
try: | ||
r = requests.get(cover, stream=True) | ||
|
||
with open(path.join(fp, "cover.jpg"), "wb") as f: | ||
shutil.copyfileobj(r.raw, f) | ||
except Exception as e: | ||
print("FAILED TO DOWNLOAD COVER") | ||
print(e) | ||
|
||
clear() | ||
print("Downloading cover...") | ||
download_cover() | ||
|
||
clear() | ||
def select_episodes(): | ||
e = argument("--episode") or argument("--episodes") | ||
|
||
if e is None: | ||
print(f"Which episodes would you like to download? (1-{len(episodes)})") | ||
print(f"Examples: 1 OR 3-5 OR 1-12 OR press enter to download all.") | ||
|
||
try: | ||
range = list(map(lambda n: int(n.strip()) if len(n) > 0 else "all", e or input().split("-"))) | ||
|
||
if range[0] == "all": | ||
return episodes | ||
|
||
if range[0] < 1 or range[0] > len(episodes) or (len(range) > 1 and (range[1] < 1 or range[1] > len(episodes) or range[1] < range[0])): | ||
raise | ||
|
||
return [episodes[range[0] - 1]] if len(range) == 1 else episodes[range[0] - 1:range[1]] | ||
except: | ||
clear() | ||
print("Invalid response, please enter a single episode number or a range of episodes within the episode count.") | ||
print() | ||
|
||
return select_episodes() | ||
|
||
clear() | ||
episodes = select_episodes() | ||
|
||
for _, id, episode, _ in episodes: | ||
download_id, _, offical_sources, unofficial_sources, _ = json.loads(requests.get(f"{api}/episode.php?id={id}").content) | ||
sources = json.loads(unofficial_sources) | ||
fn = f"Episode {episode}.mp4" | ||
|
||
clear() | ||
print(f"Downloading episode {episode}...") | ||
|
||
def try_download(): | ||
try: | ||
try: | ||
source = sources["Direct-directhls"] | ||
|
||
m3u8_To_MP4.multithread_download(source, mp4_file_dir=fp, mp4_file_name=fn) | ||
except Exception as e: | ||
source = sources["Mp4upload-embed"].replace("embed-", "") | ||
mp4_id = re.search(r"mp4upload\.com\/(\S+)\.html", source)[1] | ||
|
||
headers = { | ||
"authority": "www.mp4upload.com", | ||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||
"accept-language": "en-US,en;q=0.9", | ||
"cache-control": "max-age=0", | ||
"dnt": "1", | ||
"origin": "https://www.mp4upload.com", | ||
"referer": source, | ||
"sec-ch-ua": '"Chromium";v="109", "Not_A Brand";v="99"', | ||
"sec-ch-ua-mobile": "?0", | ||
"sec-ch-ua-platform": '"Windows"', | ||
"sec-fetch-dest": "document", | ||
"sec-fetch-mode": "navigate", | ||
"sec-fetch-site": "same-origin", | ||
"sec-fetch-user": "?1", | ||
"upgrade-insecure-requests": "1", | ||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" | ||
} | ||
|
||
data = { | ||
"op": "download2", | ||
"id": mp4_id, | ||
"rand": "", | ||
"referer": source, | ||
"method_free": " ", | ||
"method_premium": "" | ||
} | ||
|
||
with requests.post(source, verify=False, data=data, headers=headers, stream=True) as r: | ||
clear() | ||
print("Direct server download failed, trying alternate server...") | ||
|
||
r.raise_for_status() | ||
|
||
chunk_size = 32768 | ||
total_size = int(r.headers["content-length"]) | ||
downloaded_size = 0 | ||
|
||
with alive_bar(total_size, title=f"Downloading episode {episode}", ctrl_c=0, unit="B", scale="SI", precision=1) as progress: | ||
with open(path.join(fp, fn), "wb") as f: | ||
for chunk in r.iter_content(chunk_size=chunk_size): | ||
f.write(chunk) | ||
|
||
downloaded_size += chunk_size | ||
progress(chunk_size) | ||
except Exception as e: | ||
print(e) | ||
print() | ||
print("THERE WAS AN ERROR | PRESS ENTER TO RETRY") | ||
|
||
input() | ||
try_download() | ||
try_download() | ||
|
||
print(f"Done! Successfully downloaded {len(episodes)} episode{'s' if len(episodes) > 1 else ''}!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
alive_progress==3.0.1 | ||
m3u8_To_MP4==0.1.11 | ||
requests==2.28.1 |