diff --git a/.gitignore b/.gitignore index ae1b7a9..bea8fd1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ venv .idea HDRezkaAPI/__pycache__ -*.mp4 \ No newline at end of file +*.mp4 +*.json \ No newline at end of file diff --git a/HDRezkaAPI/NEWdOWN.py b/HDRezkaAPI/NEWdOWN.py new file mode 100644 index 0000000..f30ad68 --- /dev/null +++ b/HDRezkaAPI/NEWdOWN.py @@ -0,0 +1,38 @@ +import sys +import os +import requests +from tqdm import tqdm +# from .history import History +from concurrent.futures import ThreadPoolExecutor + +def download_file(download_data): + if download_data['stream_url']: + print(download_data['file_name']) + fullpath = os.path.join(os.path.curdir, download_data['file_name']) + + # Send HEAD request to get file size + response = requests.head(download_data['stream_url']) + total_size = int(response.headers.get('content-length', 0)) + + # Download the file using GET request + with requests.get(download_data['stream_url'], stream=True) as r: + with open(fullpath, "wb") as f, tqdm( + unit="B", + unit_scale=True, + unit_divisor=1024, + total=total_size, + file=sys.stdout, + desc=download_data['file_name'] + ) as progress: + for chunk in r.iter_content(chunk_size=1024*4): + if chunk: + datasize = f.write(chunk) + progress.update(datasize) + +data = { + "stream_url": "https://stream.voidboost.cc/6fac7ad9ce36bdd25731bbca2a92e3c7:2024042219:QXlQUFEyYnNlVzBZOExha1Z0YVdHYUV3NVVrTXhGU2VYaXY0ZFBtLzhmL2lYcHprMVFJbXJKM0ZhS0VsMGtyMXcrOHJKSkg3Syt2djRsWEhYL1oyS2c9PQ==/1/3/5/0/1/1/7kqf9.mp4", + + 'file_name': 'test.mp4' + + } +download_file(data) diff --git a/HDRezkaAPI/__init__.py b/HDRezkaAPI/__init__.py index 55fffa6..2eaf63d 100644 --- a/HDRezkaAPI/__init__.py +++ b/HDRezkaAPI/__init__.py @@ -1,3 +1,4 @@ from .search import Search from .movie_info import MovieInfo +from .history import History from .download import * diff --git a/HDRezkaAPI/download.py b/HDRezkaAPI/download.py old mode 100644 new mode 100755 index 2669d8a..ffdeb7f --- a/HDRezkaAPI/download.py +++ b/HDRezkaAPI/download.py @@ -1,8 +1,8 @@ import sys -from os import path -from bs4 import BeautifulSoup +import os from .request import Request from .get_stream import GetStream +from .history import History from tqdm import tqdm @@ -22,80 +22,111 @@ class EpisodeNumberIsOutOfRange(Error): class Download: - def __init__(self, download_data): + def __init__(self, download_data, quality): self.data = download_data + self.quality = quality self.url = download_data['url'] - response = Request().get(self.url) - self.soup = BeautifulSoup(response.content, 'html.parser') - self.favs = self.soup.find('input', id='ctrl_favs').get('value') + self.name = download_data['url'].split('/')[-1].split('.')[0] + + if self.data['translations_list']: + self.translator_id = self.__get_translation() + if download_data.get("seasons_episodes_count") == 0: + # If there are no seasons and episodes + print("select again:") + self.translator_id = self.__get_translation() + else: + self.translator_id = self.__detect_translation() + + + def download_all_serial(self): + correct_season = False + seasons_count = self.data['seasons_count'] + while not correct_season: + try: + if History().status == 'run' and History().run_season !="": + season = History().run_season + self.download_seasons(season, seasons_count +1) + else: + for season in range(1, seasons_count + 1): + self.download_season(season) + correct_season = True + except EpisodeNumberIsOutOfRange: + print('Неверный диапазон эпизодов!') + print('Скачивание успешно завершено!') + + def download_seasons(self, start, end): + for season in range(start, end + 1): + if season < 1 or season > self.data['seasons_count']: + continue + self.download_season(season) def download_season(self, season): if season < 1 or season > self.data['seasons_count']: # TODO Make new custom exception for incorrect season number and realize it return - episodes_list = self.soup.find( - 'ul', id=f'simple-episodes-list-{season}') - episodes_count = len(episodes_list.findAll('li')) + episodes_count = self.data['seasons_episodes_count'][season] + History().run_season = season - if self.data['translations_list']: - translator_id = self.__get_translation() + if History().status == 'run' and History().run_episode !="": + start = History( ).run_episode else: - translator_id = self.__detect_translation() + start = 1 - for i in range(1, episodes_count + 1): - self.download_episode(season, i, translator_id, True) + for i in range(start, episodes_count + 1): + self.download_episode(season, i) - def download_episodes(self, season, start, end): + def download_episodes(self, season, start): + print(season) + end = self.data['seasons_episodes_count'][season] if season < 1 or season > self.data['seasons_count']: # TODO Make new custom exception for incorrect season number and realize it return - episodes_list = self.soup.find( - 'ul', id=f'simple-episodes-list-{season}') - episodes_count = len(episodes_list.findAll('li')) + episodes_count = self.data['seasons_episodes_count'][season] + if end > episodes_count or start < 0: raise EpisodeNumberIsOutOfRange - if self.data['translations_list']: - translator_id = self.__get_translation() - else: - translator_id = self.__detect_translation() - for i in range(start, end + 1): - self.download_episode(season, i, translator_id, True) + self.download_episode(season, i) - def download_episode(self, season, episode, translator_id=None, multi_download=False): + def download_episode(self, season, episode): if self.data['type'] == 'movie': return if season > self.data['seasons_count']: return - if not multi_download: - if self.data['translations_list']: - translator_id = self.__get_translation() - else: - translator_id = self.__detect_translation() - if episode < 1 or episode > self.data['seasons_episodes_count'][season]: raise IncorrectEpisodeNumberException data = { 'id': self.data['data-id'], - 'translator_id': translator_id, - 'favs': self.favs, + 'translator_id': self.translator_id, + # 'favs': self.favs, 'season': season, 'episode': episode, - 'action': 'get_stream' + 'action': 'get_stream', + 'quality': self.quality } + + print(episode) + History().run_episode = episode stream_url = GetStream().get_series_stream(data) - file_name = f"{self.data['name']} {season}s{episode}e.mp4" + downloaded_folder = f"../{self.name}" + # downloaded_folder = self.name + os.makedirs(downloaded_folder, exist_ok=True) + + season = str(season).zfill(2) + episode = str(episode).zfill(2) + file_name = f"{downloaded_folder}/s{season}e{episode}-{self.quality}.mp4" download_data = { 'stream_url': stream_url, 'file_name': file_name, + } self.__download(download_data) @@ -105,26 +136,27 @@ def download_movie(self): return data = { - 'url': self.url + 'url': self.url, + 'quality': self.quality } stream_url = GetStream().get_movie_stream(data) - # file_name = f"{self.data['name']}.mp4" # TODO Fix file name bug - file_name = f"test.mp4" download_data = { 'stream_url': stream_url, - 'file_name': file_name, + 'file_name': self.name, } self.__download(download_data) @staticmethod - def __download(download_data): + def __download( download_data): if download_data['stream_url']: - - fullpath = path.join(path.curdir, download_data['file_name']) + print (download_data['file_name']) + print (download_data['stream_url']) + History().status = "run" + fullpath = os.path.join(os.path.curdir, download_data['file_name']) with Request().get(download_data['stream_url'], stream=True) as r, open(fullpath, "wb") as f, tqdm( unit="B", @@ -134,25 +166,47 @@ def __download(download_data): file=sys.stdout, desc=download_data['file_name'] ) as progress: - for chunk in r.iter_content(chunk_size=4096): + for chunk in r.iter_content(chunk_size=1024*4): if chunk: datasize = f.write(chunk) progress.update(datasize) + History().run_episode = History().run_episode + 1 + + + def convert_to_pls(self): + file_name = self.filee.name + self.filee.close() + with open(file_name, 'r') as f: + url_list = [line.strip() for line in f] + with open(f"{self.name}.pls", 'w') as f: + f.write("[playlist]\n") + for i, url in enumerate(url_list): + f.write(f"File{i+1}={url}\n") + f.write(f"Title{i+1}=Track {i+1}\n") + print(f'Pls len: {len(url_list)}') + print(self.download_data['allepisodes']) + f.write(f"NumberOfEntries={len(url_list)}\n") + f.write("Version=2\n") def __get_translation(self) -> int: - for i, translation in zip(range(1, len(self.data['translations_list'])), self.data['translations_list']): - print(f'{i} - {translation["name"]}') - translation_id = self.data['translations_list'][int( - input("Введите номер озвучки: ")) - 1]['id'] + if History().status == 'run': + translation_id = History().translator_id + else: + for i, translation in zip(range(1, len(self.data['translations_list'])), self.data['translations_list']): + print(f'{i} - {translation["name"]}') + translation_id = self.data['translations_list'][int( + input("Введите номер озвучки: ")) - 1]['id'] + History().translator_id = translation_id + return translation_id - def __detect_translation(self): - if self.data['type'] == 'movie': - event_type = 'initCDNMoviesEvents' - else: - event_type = 'initCDNSeriesEvents' + # def __detect_translation(self): + # if self.data['type'] == 'movie': + # event_type = 'initCDNMoviesEvents' + # else: + # event_type = 'initCDNSeriesEvents' - tmp = str(self.soup).split(f"sof.tv.{event_type}")[-1].split("{")[0] - translator_id = tmp.split(",")[1].strip() + # tmp = str(self.soup).split(f"sof.tv.{event_type}")[-1].split("{")[0] + # translator_id = tmp.split(",")[1].strip() - return translator_id + # return translator_id diff --git a/HDRezkaAPI/get_stream.py b/HDRezkaAPI/get_stream.py index 40dfa8a..b2d0b23 100644 --- a/HDRezkaAPI/get_stream.py +++ b/HDRezkaAPI/get_stream.py @@ -27,8 +27,7 @@ def get_series_stream(self, data): 'Попробуйте скачать используя VPN!') exit(0) arr = self.decode_url(r['url'], separator="//_//").split(",") - # TODO Make quality select - stream_url = arr[-1][arr[-1].find("or") + 3:len(arr[-1])] + stream_url = self.quality_select(arr, data['quality']) decoded = True except (UnicodeDecodeError, BinasciiError): print('Decoding error, trying again!') @@ -50,13 +49,36 @@ def get_movie_stream(self, data): try: arr = self.decode_url(encoded_stream_url, separator="\/\/_\/\/").split(",") - # TODO Make quality select - stream_url = arr[-1][arr[-1].find("or") + 3:len(arr[-1])] + # stream_url = arr[-1][arr[-1].find("or") + 3:len(arr[-1])] + stream_url = self.quality_select(arr, data['quality']) decoded = True except (UnicodeDecodeError, BinasciiError): print('Decoding error, trying again!') return stream_url + + @staticmethod + def quality_select(stream_list, quality): + resolutions_and_urls = [] + for item in stream_list: + resolution, url = item.split("]") + if url.endswith(".mp4"): + resolutions_and_urls.append((resolution + "]", url.split(" or ")[1])) + + selected_index = -2 + if len(quality) > 2: + for index, item in enumerate(stream_list): + if quality in item: + selected_index = index + break + + # if selected_index == -1: + # raise ValueError("Quality not found or invalid") + + stream_url = resolutions_and_urls[selected_index][1] + print(resolutions_and_urls[selected_index][0], "\n") + return stream_url + @staticmethod def decode_url(data, separator): diff --git a/HDRezkaAPI/history.py b/HDRezkaAPI/history.py new file mode 100644 index 0000000..96733af --- /dev/null +++ b/HDRezkaAPI/history.py @@ -0,0 +1,115 @@ +import json + +class History: + def __init__(self): + self._load_data() + + def _load_data(self): + try: + with open('history.json', 'r') as json_file: + data = json.load(json_file) + self._movie_data = data.get('movie_data', {}) + self._quality = data.get('quality', '') + self._dorl = data.get('dorl', '') + self._download_type = data.get('download_type', {}) + self._translator_id = data.get('translator_id', '') + self._status = data.get('status', '') + self._run_season = data.get('run_season', '') + self._run_episode = data.get('run_episode', '') + except FileNotFoundError: + self._movie_data = {} + self._quality = '' + self._dorl = '' + self._download_type = {} + self._translator_id = '' + self._status = '' + self._run_season = '' + self._run_episode = '' + + def _save_data(self): + data = { + 'movie_data': self._movie_data, + 'quality': self._quality, + 'dorl': self._dorl, + 'download_type': self._download_type, + 'translator_id': self._translator_id, + 'status': self._status, + 'run_season': self._run_season, + 'run_episode': self._run_episode + } + with open('history.json', 'w') as json_file: + json.dump(data, json_file) + + @property + def movie_data(self): + return self._movie_data + + @movie_data.setter + def movie_data(self, value): + self._movie_data = value + self._save_data() + + @property + def quality(self): + return self._quality + + @quality.setter + def quality(self, value): + self._quality = value + self._save_data() + + @property + def dorl(self): + return self._dorl + + @dorl.setter + def dorl(self, value): + self._dorl = value + self._save_data() + + @property + def download_type(self): + return self._download_type + + @download_type.setter + def download_type(self, value): + self._download_type = value + self._save_data() + + @property + def translator_id(self): + return self._translator_id + + @translator_id.setter + def translator_id(self, value): + self._translator_id = value + self._save_data() + + @property + def status(self): + return self._status + + @status.setter + def status(self, value): + self._status = value + self._save_data() + + @property + def run_season(self): + return self._run_season + + @run_season.setter + def run_season(self, value): + self._run_season = value + self._save_data() + + @property + def run_episode(self): + return self._run_episode + + @run_episode.setter + def run_episode(self, value): + self._run_episode = value + self._save_data() + + diff --git a/HDRezkaAPI/main.ipynb b/HDRezkaAPI/main.ipynb new file mode 100644 index 0000000..8554934 --- /dev/null +++ b/HDRezkaAPI/main.ipynb @@ -0,0 +1,110 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "ImportError", + "evalue": "attempted relative import with no known parent package", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01msys\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrequest\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Request\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mget_stream\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m GetStream\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mhistory\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m History\n", + "\u001b[0;31mImportError\u001b[0m: attempted relative import with no known parent package" + ] + } + ], + "source": [ + "import sys\n", + "import os\n", + "from .request import Request\n", + "from .get_stream import GetStream\n", + "from .history import History\n", + "from tqdm import tqdm\n", + "from concurrent.futures import ThreadPoolExecutor" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def download_chunk(url, chunk_size=4096):\n", + " with Request().get(url, stream=True) as r:\n", + " chunk = r.iter_content(chunk_size=chunk_size)\n", + " return b\"\".join(chunk)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def download_file(url, file_path, num_threads=4):\n", + " with ThreadPoolExecutor(max_workers=num_threads) as executor:\n", + " response = Request().head(url)\n", + " total_size = int(response.headers.get('content-length', 0))\n", + "\n", + " with open(file_path, \"wb\") as f:\n", + " futures = []\n", + " for i in range(0, total_size, chunk_size * num_threads):\n", + " futures.append(executor.submit(download_chunk, url, chunk_size))\n", + " for future in futures:\n", + " f.write(future.result())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def __download( download_data):\n", + " if download_data['stream_url']:\n", + " print (download_data['file_name'])\n", + " History().status = \"run\"\n", + " fullpath = os.path.join(os.path.curdir, download_data['file_name'])\n", + "\n", + " with Request().get(download_data['stream_url'], stream=True) as r, open(fullpath, \"wb\") as f, tqdm(\n", + " unit=\"B\",\n", + " unit_scale=True,\n", + " unit_divisor=1024,\n", + " total=int(r.headers.get('content-length', 0)),\n", + " file=sys.stdout,\n", + " desc=download_data['file_name']\n", + " ) as progress:\n", + " for chunk in r.iter_content(chunk_size=4096):\n", + " if chunk:\n", + " datasize = f.write(chunk)\n", + " progress.update(datasize)\n", + " History().run_episode = History().run_episode + 1" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/HDRezkaAPI/movie_info.py b/HDRezkaAPI/movie_info.py index 13ee114..631c225 100644 --- a/HDRezkaAPI/movie_info.py +++ b/HDRezkaAPI/movie_info.py @@ -16,13 +16,19 @@ def __str__(self): info = self.get_data() if info['type'] == 'movie': s += f'Фильм | {info["name"]}\n' + elif info['type'] == 'Аниме': + s += f'Аниме | {info["name"]}\nКоличество сезонов: {info["seasons_count"]}\n' + s += f'Количество сеp: {info["seasons_episodes_count"]}\n' + s += f'Количество сеp all: {info["allepisodes"]}\n' + else: s += f'Сериал | {info["name"]}\nКоличество сезонов: {info["seasons_count"]}\n' + s += f'Количество сеp: {info["seasons_episodes_count"]}\n' + s += f'Количество сеp all: {info["allepisodes"]}\n' + s += f'Год выпуска: {info["year"]}\n' \ f'Страна:{info["country"]}\n' \ f'Длительность: {info["duration"]}\n' \ - f'Рейтинг IMDb - {info["rating"]["imdb"]}\n' \ - f'Рейтинг Кинопоиск - {info["rating"]["kp"]}\n' \ f'Жанр:' for i in info['genre']: s += f' {i}' @@ -37,6 +43,10 @@ def get_data(self): return self.series_info() elif 'films' in self.url: return self.movie_info() + elif 'cartoons' in self.url: + return self.series_info() + elif 'animation' in self.url: + return self.series_info() else: return 'Wrong link!' @@ -45,6 +55,7 @@ def series_info(self): 'type': 'series', 'name': self.data['name'], 'year': self.data['info']['year'], + 'allepisodes': 0, 'country': self.data['info']['country'], 'seasons_count': len(self.soup.select('#simple-seasons-tabs > li')), 'rating': { @@ -62,13 +73,17 @@ def series_info(self): data.update({'rating': rating}) episodes_count = {} + allepisodes = 0 for i in range(1, data['seasons_count'] + 1): counter = len(self.soup.select(f'#simple-episodes-list-{i} > li')) episodes_count.update({i: counter}) + allepisodes += counter + data.update({'seasons_episodes_count': episodes_count}) + data.update({'allepisodes': allepisodes}) return data def movie_info(self): diff --git a/HDRezkaAPI/search.py b/HDRezkaAPI/search.py index 455bc68..a1cef0c 100644 --- a/HDRezkaAPI/search.py +++ b/HDRezkaAPI/search.py @@ -21,8 +21,7 @@ def __iter__(self): def __str__(self): s = '' for title in self.titles_list: - s += (f'{title["id"]} - [{title["info"]["type"]}] Название: {title["name"]} | Год: {title["info"]["year"]} | ' - f'Страна: {title["info"]["country"]} | Жанр: {title["info"]["genre"]}\n') + s += (f'{title["id"]} - [{title["info"]["type"]}] Название: {title["name"]} | Год: {title["info"]["year"]}\n') return s[:-1] def __get_info(self): diff --git a/README.md b/README.md index a1d5285..4eca25a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,85 @@ -# HDRezkaDownloader +# HDRezkaTool +A powerful Python tool for downloading movies and TV series from HDRezka. This tool provides a convenient command-line interface to search, browse, and download content with various quality options. + +## Features + +- 🔍 Search functionality for movies and TV series +- 🎬 Support for both movies and TV series downloads +- 📺 Multiple download options for TV series: + - Download entire season + - Download specific episodes + - Download multiple seasons + - Download complete series +- 🎥 Quality selection (720p by default) +- 📝 Download history tracking +- 🔄 Resume interrupted downloads +- 🌐 Russian language interface + +## Installation + +1. Clone the repository: +```bash +git clone https://github.com/yourusername/HDRezkaTool.git +cd HDRezkaTool +``` + +2. Install the required dependencies: +```bash +pip install -r requirements.txt +``` + +## Usage + +1. Run the main script: +```bash +python main.py +``` + +2. Follow the interactive prompts: + - Enter search query + - Select content from search results + - Choose download options + - Select quality (default: 720p) + +### Download Options for TV Series + +1. Download a single season: + - Select option 1 + - Enter season number + +2. Download specific episodes: + - Select option 2 + - Enter season number + - Enter starting episode number + +3. Download multiple seasons: + - Select option 3 + - Enter starting season number + - Enter ending season number + +4. Download complete series: + - Select option 4 + +## Project Structure + +``` +HDRezkaTool/ +├── HDRezkaAPI/ # Core API implementation +├── main.py # Main application script +├── history.json # Download history +├── LICENSE # Project license +└── README.md # This file +``` + +## Contributing + +Contributions are welcome! Please feel free to submit a Pull Request. + +## License + +This project is licensed under the terms of the license included in the LICENSE file. + +## Disclaimer + +This tool is for educational purposes only. Please respect copyright laws and the terms of service of the source website. The developers are not responsible for any misuse of this tool. diff --git a/history.json b/history.json new file mode 100644 index 0000000..00ca414 --- /dev/null +++ b/history.json @@ -0,0 +1 @@ +{"movie_data": {"id": 1, "name": "\u0411\u0430\u0448\u043d\u044f \u0411\u043e\u0433\u0430", "info": {"type": "\u0410\u043d\u0438\u043c\u0435", "year": "2020", "country": " \u042f\u043f\u043e\u043d\u0438\u044f", "genre": " \u041f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f"}, "data-id": "35561", "url": "https://rezka.ag/animation/adventures/35561-bashnya-boga-2020.html"}, "quality": "", "dorl": "", "download_type": 4, "translator_id": "19", "status": "run", "run_season": 1, "run_episode": 10} \ No newline at end of file diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 6e3fca8..956ab1f --- a/main.py +++ b/main.py @@ -1,44 +1,86 @@ from HDRezkaAPI import * -search_text = input('Поиск: ') -search_result = Search(search_text) +if History().status == 'run' and input('Continue[yN]?') != "n": + movie_data = History().movie_data +else: + History().status = "end" + + search_text = input('Поиск: ') + search_result = Search(search_text) + + print(search_result) -print(search_result) + title_id = int(input('Введите номер: ')) -title_id = int(input('Введите номер: ')) + movie_data = search_result.get_data(title_id) + +History().movie_data = movie_data -movie_data = search_result.get_data(title_id) movie_info = MovieInfo(movie_data) download_data = movie_info.get_data() +print (f'\n{download_data}\n') + +if 0: + quality = input("Введите качество: ") +else: + quality = "720" -downloader = Download(download_data) +downloader = Download(download_data, quality) print(movie_info) -download_type = int(input('1 - Скачать фильм\n2 - Скачать сезон сериала\n3 - Скачать эпизоды сериала\n' - 'Выберите тип скачивания: ')) -if download_type == 1: +if download_data['type'] == 'movie': downloader.download_movie() print('Скачивание успешно завершено!') -elif download_type == 2: - season = int(input('Введите номер сезона: ')) - downloader.download_season(season) - print('Скачивание успешно завершено!') -elif download_type == 3: - correct_episode = False - season = int(input('Введите номер сезона: ')) - episodes_count = download_data['seasons_episodes_count'][season] - print(f'В данном сезоне количество эпизодов: {episodes_count}') - start = int(input('Введите стартовый эпизод: ')) - end = int(input('Введите конечный эпизод: ')) - while not correct_episode: - try: - downloader.download_episodes(season, start, end) - correct_episode = True - except EpisodeNumberIsOutOfRange: - print('Неверный диапазон!') - episode = int(input('Снова введите диапазон эпизодов: ')) - print('Скачивание успешно завершено!') -else: - print('Неверный тип скачивания!') +else: + + if History().status == 'run': + download_type = History().download_type + else: + download_type = int(input('1 - Скачать сезон сериала\n2 - Скачать эпизоды сериала\n3 - Скачать сезонs сериала\n4 - Скачать сериал\n' + 'Выберите тип скачивания: ')) + History().download_type = download_type + + if download_type == 1: + if History().status == 'run' and History().download_type == 1 and History().run_season !="": + season = History().run_season + else: + season = int(input('Введите номер сезона: ')) + downloader.download_season(season) + print('Скачивание успешно завершено!') + elif download_type == 2: + correct_episode = False + season = int(input('Введите номер сезона: ')) + episodes_count = download_data['seasons_episodes_count'][season] + print(f'В данном сезоне количество эпизодов: {episodes_count}') + start = int(input('Введите стартовый эпизод: ')) + end = episodes_count + while not correct_episode: + try: + downloader.download_episodes(season, start) + correct_episode = True + except EpisodeNumberIsOutOfRange: + print('Неверный диапазон!') + episode = int(input('Снова введите диапазон эпизодов: ')) + print('Скачивание успешно завершено!') + elif download_type == 3: + correct_season = False + start = int(input('Enter the starting season number: ')) + end = int(input('Enter the ending season number: ')) + while not correct_season: + try: + downloader.download_seasons(start, end) + correct_season = True + except SeasonNumberIsOutOfRange: + print('Invalid season range!') + start = int(input('Enter the starting season number again: ')) + end = int(input('Enter the ending season number again: ')) + print('Download successful!') + elif download_type == 4: + downloader.download_all_serial() + print('Скачивание успешно завершено!') + else: + print('Неверный тип скачивания!') + + History().status = "end" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..83853b2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +tqdm>=4.65.0 +beautifulsoup4>=4.12.0 +requests>=2.31.0 \ No newline at end of file