Created
August 30, 2025 21:29
-
-
Save zone559/237af54851d8300835ce166c15c8becf to your computer and use it in GitHub Desktop.
image pond video downloader example https://github.com/mikf/gallery-dl/issues/8149
This file contains hidden or 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
| import re | |
| import requests | |
| import os | |
| from urllib.parse import urlparse | |
| def extract_video_url(html_content): | |
| """ | |
| Extract video URL from HTML content using regex | |
| """ | |
| pattern = r'<meta property="og:video" content="(https?://[^"]+\.mp4)"' | |
| match = re.search(pattern, html_content) | |
| return match.group(1) if match else None | |
| def download_video(video_url, output_path=None): | |
| """ | |
| Download video from URL | |
| """ | |
| try: | |
| # Get filename from URL if not specified | |
| if output_path is None: | |
| parsed_url = urlparse(video_url) | |
| filename = os.path.basename(parsed_url.path) | |
| output_path = filename | |
| # Stream the download to handle large files | |
| response = requests.get(video_url, stream=True) | |
| response.raise_for_status() | |
| # Get total file size for progress tracking | |
| total_size = int(response.headers.get('content-length', 0)) | |
| # Download the video | |
| with open(output_path, 'wb') as f: | |
| if total_size == 0: | |
| # No content length header, just write the content | |
| f.write(response.content) | |
| print(f"Video downloaded: {output_path}") | |
| else: | |
| # Show progress for large files | |
| downloaded = 0 | |
| for chunk in response.iter_content(chunk_size=8192): | |
| if chunk: | |
| f.write(chunk) | |
| downloaded += len(chunk) | |
| # Calculate percentage | |
| percentage = (downloaded / total_size) * 100 | |
| print(f"Downloading: {percentage:.1f}% ({downloaded}/{total_size} bytes)", end='\r') | |
| print(f"\nVideo downloaded: {output_path}") | |
| return output_path | |
| except requests.RequestException as e: | |
| print(f"Error downloading video: {e}") | |
| return None | |
| def download_video_from_url(url, output_path=None): | |
| """ | |
| Main function: extract video URL and download it | |
| """ | |
| try: | |
| # Fetch HTML content | |
| response = requests.get(url) | |
| response.raise_for_status() | |
| # Extract video URL | |
| video_url = extract_video_url(response.text) | |
| if not video_url: | |
| print("No video URL found in the HTML") | |
| return None | |
| print(f"Found video URL: {video_url}") | |
| # Download the video | |
| return download_video(video_url, output_path) | |
| except requests.RequestException as e: | |
| print(f"Error: {e}") | |
| return None | |
| # Example usage | |
| if __name__ == "__main__": | |
| test_url = "https://imagepond.net/video/I-can-actually-fit-it-in-my-mouth-Van-Holtens-Warhead-Pickle.dRZLrH" | |
| # Download with default filename (from URL) | |
| downloaded_file = download_video_from_url(test_url) | |
| # Or specify custom output path | |
| # downloaded_file = download_video_from_url(test_url, "my_video.mp4") | |
| if downloaded_file: | |
| print(f"Download completed: {downloaded_file}") | |
| else: | |
| print("Download failed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment