|
7 | 7 |
|
8 | 8 |
|
9 | 9 | # External library |
| 10 | +import httpx |
10 | 11 | from rich.console import Console |
11 | 12 |
|
12 | 13 |
|
|
21 | 22 | class DeviceDownloader: |
22 | 23 | def __init__(self): |
23 | 24 | self.base_dir = binary_paths.ensure_binary_directory() |
| 25 | + self.github_png_url = "https://github.com/Arrowar/StreamingCommunity/raw/main/.github/.site/img/crunchyroll_etp_rt.png" |
24 | 26 |
|
25 | 27 | def extract_png_chunk(self, png_with_wvd: str, out_wvd_path: str) -> bool: |
26 | 28 | """Extract WVD data""" |
@@ -85,19 +87,64 @@ def _find_png_recursively(self, start_dir: str = ".") -> Optional[str]: |
85 | 87 | logging.error(f"Error during recursive PNG search: {e}") |
86 | 88 | return None |
87 | 89 |
|
| 90 | + def _download_png_from_github(self, output_path: str) -> bool: |
| 91 | + """Download PNG file from GitHub repository.""" |
| 92 | + try: |
| 93 | + logging.info(f"Downloading PNG from GitHub: {self.github_png_url}") |
| 94 | + |
| 95 | + with httpx.Client(timeout=30.0, follow_redirects=True) as client: |
| 96 | + response = client.get(self.github_png_url) |
| 97 | + response.raise_for_status() |
| 98 | + |
| 99 | + with open(output_path, "wb") as f: |
| 100 | + f.write(response.content) |
| 101 | + |
| 102 | + logging.info(f"Successfully downloaded PNG to: {output_path}") |
| 103 | + return True |
| 104 | + |
| 105 | + except httpx.HTTPError as e: |
| 106 | + logging.error(f"HTTP error downloading PNG from GitHub: {e}") |
| 107 | + return False |
| 108 | + except Exception as e: |
| 109 | + logging.error(f"Error downloading PNG from GitHub: {e}") |
| 110 | + return False |
| 111 | + |
88 | 112 | def download(self) -> Optional[str]: |
89 | 113 | """ |
90 | 114 | Main method to extract WVD file from PNG. |
| 115 | + Downloads PNG from GitHub if not found locally. |
91 | 116 | """ |
92 | 117 | try: |
| 118 | + # Try to find PNG locally first |
93 | 119 | png_path = self._find_png_recursively() |
| 120 | + temp_png_path = None |
| 121 | + |
| 122 | + # If not found locally, download from GitHub |
94 | 123 | if not png_path: |
95 | | - logging.error("PNG file not found, cannot extract device.wvd") |
96 | | - return None |
| 124 | + logging.info("PNG not found locally, downloading from GitHub") |
| 125 | + temp_png_path = os.path.join(self.base_dir, 'crunchyroll_etp_rt.png') |
| 126 | + |
| 127 | + if not self._download_png_from_github(temp_png_path): |
| 128 | + logging.error("Failed to download PNG from GitHub") |
| 129 | + return None |
| 130 | + |
| 131 | + png_path = temp_png_path |
97 | 132 |
|
98 | 133 | device_wvd_path = os.path.join(self.base_dir, 'device.wvd') |
99 | 134 |
|
100 | | - if self.extract_png_chunk(png_path, device_wvd_path): |
| 135 | + # Extract WVD from PNG |
| 136 | + extraction_success = self.extract_png_chunk(png_path, device_wvd_path) |
| 137 | + |
| 138 | + # Clean up temporary PNG file if it was downloaded |
| 139 | + if temp_png_path and os.path.exists(temp_png_path): |
| 140 | + try: |
| 141 | + os.remove(temp_png_path) |
| 142 | + logging.info("Removed temporary PNG file") |
| 143 | + except Exception as e: |
| 144 | + logging.warning(f"Could not remove temporary PNG file: {e}") |
| 145 | + |
| 146 | + # Check extraction result |
| 147 | + if extraction_success: |
101 | 148 | if os.path.exists(device_wvd_path) and os.path.getsize(device_wvd_path) > 0: |
102 | 149 | logging.info("Successfully extracted device.wvd from PNG") |
103 | 150 | return device_wvd_path |
|
0 commit comments