mirror of
https://github.com/glomatico/gamdl.git
synced 2026-06-13 20:25:13 +03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f97b3dba14 | |||
| 2da824ecbc | |||
| 24810da4b6 | |||
| f16a30549c |
+1
-1
@@ -1 +1 @@
|
||||
__version__ = "2.4"
|
||||
__version__ = "2.4.1"
|
||||
|
||||
@@ -9,6 +9,8 @@ from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
from .utils import raise_response_exception
|
||||
|
||||
|
||||
class AppleMusicApi:
|
||||
APPLE_MUSIC_HOMEPAGE_URL = "https://beta.music.apple.com"
|
||||
@@ -69,12 +71,6 @@ class AppleMusicApi:
|
||||
self.session.headers.update({"authorization": f"Bearer {token}"})
|
||||
self.session.params = {"l": self.language}
|
||||
|
||||
@staticmethod
|
||||
def _raise_response_exception(response: requests.Response):
|
||||
raise Exception(
|
||||
f"Request failed with status code {response.status_code}: {response.text}"
|
||||
)
|
||||
|
||||
def _check_amp_api_response(self, response: requests.Response):
|
||||
try:
|
||||
response.raise_for_status()
|
||||
@@ -85,7 +81,7 @@ class AppleMusicApi:
|
||||
requests.exceptions.JSONDecodeError,
|
||||
AssertionError,
|
||||
):
|
||||
self._raise_response_exception(response)
|
||||
raise_response_exception(response)
|
||||
|
||||
def get_artist(
|
||||
self,
|
||||
@@ -254,7 +250,7 @@ class AppleMusicApi:
|
||||
requests.exceptions.JSONDecodeError,
|
||||
AssertionError,
|
||||
):
|
||||
self._raise_response_exception(response)
|
||||
raise_response_exception(response)
|
||||
return webplayback[0]
|
||||
|
||||
def get_widevine_license(
|
||||
@@ -284,5 +280,5 @@ class AppleMusicApi:
|
||||
requests.exceptions.JSONDecodeError,
|
||||
AssertionError,
|
||||
):
|
||||
self._raise_response_exception(response)
|
||||
raise_response_exception(response)
|
||||
return widevine_license
|
||||
|
||||
+6
-4
@@ -7,7 +7,7 @@ from enum import Enum
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
from termcolor import colored
|
||||
import colorama
|
||||
|
||||
from . import __version__
|
||||
from .apple_music_api import AppleMusicApi
|
||||
@@ -20,6 +20,7 @@ from .downloader_song import DownloaderSong
|
||||
from .downloader_song_legacy import DownloaderSongLegacy
|
||||
from .enums import CoverFormat, DownloadMode, MusicVideoCodec, PostQuality, RemuxMode
|
||||
from .itunes_api import ItunesApi
|
||||
from .utils import color_text
|
||||
|
||||
apple_music_api_sig = inspect.signature(AppleMusicApi.__init__)
|
||||
downloader_sig = inspect.signature(Downloader.__init__)
|
||||
@@ -350,6 +351,7 @@ def main(
|
||||
quality_post: PostQuality,
|
||||
no_config_file: bool,
|
||||
):
|
||||
colorama.just_fix_windows_console()
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(log_level)
|
||||
stream_handler = logging.StreamHandler()
|
||||
@@ -466,7 +468,7 @@ def main(
|
||||
_urls.extend(Path(url).read_text(encoding="utf-8").splitlines())
|
||||
urls = _urls
|
||||
for url_index, url in enumerate(urls, start=1):
|
||||
url_progress = colored(f"URL {url_index}/{len(urls)}", "grey")
|
||||
url_progress = color_text(f"URL {url_index}/{len(urls)}", colorama.Style.DIM)
|
||||
try:
|
||||
logger.info(f'({url_progress}) Checking "{url}"')
|
||||
url_info = downloader.get_url_info(url)
|
||||
@@ -482,9 +484,9 @@ def main(
|
||||
for download_index, track_metadata in enumerate(
|
||||
download_queue_tracks_metadata, start=1
|
||||
):
|
||||
queue_progress = colored(
|
||||
queue_progress = color_text(
|
||||
f"Track {download_index}/{len(download_queue_tracks_metadata)} from URL {url_index}/{len(urls)}",
|
||||
"grey",
|
||||
colorama.Style.DIM,
|
||||
)
|
||||
try:
|
||||
remuxed_path = None
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import logging
|
||||
from termcolor import colored
|
||||
|
||||
import colorama
|
||||
|
||||
from .utils import color_text
|
||||
|
||||
|
||||
class CustomFormatter(logging.Formatter):
|
||||
basic_format = "[%(levelname)-8s %(asctime)s]"
|
||||
formats = {
|
||||
logging.DEBUG: colored(basic_format, "grey"),
|
||||
logging.INFO: colored(basic_format, "green"),
|
||||
logging.WARNING: colored(basic_format, "yellow"),
|
||||
logging.ERROR: colored(basic_format, "red"),
|
||||
logging.CRITICAL: colored(basic_format, "red"),
|
||||
logging.DEBUG: color_text(basic_format, colorama.Style.DIM),
|
||||
logging.INFO: color_text(basic_format, colorama.Fore.GREEN),
|
||||
logging.WARNING: color_text(basic_format, colorama.Fore.YELLOW),
|
||||
logging.ERROR: color_text(basic_format, colorama.Fore.RED),
|
||||
logging.CRITICAL: color_text(basic_format, colorama.Fore.RED),
|
||||
}
|
||||
date_format = "%H:%M:%S"
|
||||
|
||||
|
||||
+3
-3
@@ -4,8 +4,8 @@ import functools
|
||||
|
||||
import requests
|
||||
|
||||
from .apple_music_api import AppleMusicApi
|
||||
from .constants import STOREFRONT_IDS
|
||||
from .utils import raise_response_exception
|
||||
|
||||
|
||||
class ItunesApi:
|
||||
@@ -58,7 +58,7 @@ class ItunesApi:
|
||||
requests.exceptions.JSONDecodeError,
|
||||
AssertionError,
|
||||
):
|
||||
AppleMusicApi._raise_response_exception(response)
|
||||
raise_response_exception(response)
|
||||
return resource
|
||||
|
||||
def get_itunes_page(
|
||||
@@ -81,5 +81,5 @@ class ItunesApi:
|
||||
requests.exceptions.JSONDecodeError,
|
||||
AssertionError,
|
||||
):
|
||||
AppleMusicApi._raise_response_exception(response)
|
||||
raise_response_exception(response)
|
||||
return itunes_page
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import colorama
|
||||
import requests
|
||||
|
||||
|
||||
def color_text(text: str, color) -> str:
|
||||
return color + text + colorama.Style.RESET_ALL
|
||||
|
||||
|
||||
def raise_response_exception(response: requests.Response):
|
||||
raise Exception(
|
||||
f"Request failed with status code {response.status_code}: {response.text}"
|
||||
)
|
||||
+1
-2
@@ -5,13 +5,12 @@ requires-python = ">=3.9"
|
||||
authors = [{ name = "glomatico" }]
|
||||
dependencies = [
|
||||
"click",
|
||||
"colorama",
|
||||
"inquirerpy",
|
||||
"m3u8",
|
||||
"mutagen",
|
||||
"pillow",
|
||||
"pywidevine",
|
||||
"pyyaml",
|
||||
"termcolor",
|
||||
"yt-dlp",
|
||||
]
|
||||
readme = "README.md"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
click
|
||||
colorama
|
||||
inquirerpy
|
||||
m3u8
|
||||
mutagen
|
||||
|
||||
Reference in New Issue
Block a user