peg-this 3.0.2__py3-none-any.whl → 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,129 @@
1
+
2
+ import subprocess
3
+ import logging
4
+ import sys
5
+
6
+ import ffmpeg
7
+ from rich.console import Console
8
+ from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn
9
+
10
+ console = Console()
11
+
12
+
13
+ def check_ffmpeg_ffprobe():
14
+ """
15
+ Checks if ffmpeg and ffprobe executables are available in the system's PATH.
16
+ ffmpeg-python requires this.
17
+ """
18
+ try:
19
+ # The library does this internally, but we can provide a clearer error message.
20
+ subprocess.check_call(['ffmpeg', '-version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
21
+ subprocess.check_call(['ffprobe', '-version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
22
+ except FileNotFoundError:
23
+ console.print("[bold red]Error: ffmpeg and ffprobe not found.[/bold red]")
24
+ if sys.platform == "win32":
25
+ console.print("You can install it using Chocolatey: [bold]choco install ffmpeg[/bold]")
26
+ console.print("Or Scoop: [bold]scoop install ffmpeg[/bold]")
27
+ elif sys.platform == "darwin":
28
+ console.print("You can install it using Homebrew: [bold]brew install ffmpeg[/bold]")
29
+ else:
30
+ console.print("You can install it using your system's package manager, e.g., [bold]sudo apt update && sudo apt install ffmpeg[/bold] on Debian/Ubuntu.")
31
+ console.print("Please ensure its location is in your system's PATH.")
32
+ sys.exit(1)
33
+
34
+
35
+ def run_command(stream_spec, description="Processing...", show_progress=False):
36
+ """
37
+ Runs an ffmpeg command using ffmpeg-python.
38
+ - For simple commands, it runs directly.
39
+ - For commands with a progress bar, it generates the ffmpeg arguments,
40
+ runs them as a subprocess, and parses stderr to show progress.
41
+ Returns True on success, False on failure.
42
+ """
43
+ console.print(f"[bold cyan]{description}[/bold cyan]")
44
+
45
+ args = stream_spec.get_args()
46
+ full_command = ['ffmpeg'] + args
47
+ logging.info(f"Executing command: {' '.join(full_command)}")
48
+
49
+ if not show_progress:
50
+ try:
51
+ # Use ffmpeg.run() for simple, non-progress tasks. It's cleaner.
52
+ ffmpeg.run(stream_spec, capture_stdout=True, capture_stderr=True, quiet=True)
53
+ logging.info("Command successful (no progress bar).")
54
+ return True
55
+ except ffmpeg.Error as e:
56
+ error_message = e.stderr.decode('utf-8')
57
+ console.print("[bold red]An error occurred:[/bold red]")
58
+ console.print(error_message)
59
+ logging.error(f"ffmpeg error:{error_message}")
60
+ return False
61
+ else:
62
+ # For the progress bar, we must run ffmpeg as a subprocess and parse stderr.
63
+ duration = 0
64
+ try:
65
+ input_file_path = None
66
+ for i, arg in enumerate(full_command):
67
+ if arg == '-i' and i + 1 < len(full_command):
68
+ input_file_path = full_command[i+1]
69
+ break
70
+
71
+ if input_file_path:
72
+ probe_info = ffmpeg.probe(input_file_path)
73
+ duration = float(probe_info['format']['duration'])
74
+ else:
75
+ logging.warning("Could not find input file in command to determine duration for progress bar.")
76
+
77
+ except (ffmpeg.Error, KeyError) as e:
78
+ console.print(f"[bold yellow]Warning: Could not determine video duration for progress bar.[/bold yellow]")
79
+ logging.warning(f"Could not probe for duration: {e}")
80
+
81
+ with Progress(
82
+ SpinnerColumn(),
83
+ TextColumn("[progress.description]{task.description}"),
84
+ BarColumn(),
85
+ TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
86
+ console=console,
87
+ ) as progress:
88
+ task = progress.add_task(description, total=100)
89
+
90
+ process = subprocess.Popen(
91
+ full_command,
92
+ stdout=subprocess.PIPE,
93
+ stderr=subprocess.PIPE,
94
+ universal_newlines=True,
95
+ encoding='utf-8'
96
+ )
97
+
98
+ for line in process.stderr:
99
+ logging.debug(f"ffmpeg stderr: {line.strip()}")
100
+ if "time=" in line and duration > 0:
101
+ try:
102
+ time_str = line.split("time=")[1].split(" ")[0].strip()
103
+ h, m, s_parts = time_str.split(':')
104
+ s = float(s_parts)
105
+ elapsed_time = int(h) * 3600 + int(m) * 60 + s
106
+ percent_complete = (elapsed_time / duration) * 100
107
+ progress.update(task, completed=min(percent_complete, 100))
108
+ except Exception:
109
+ pass
110
+
111
+ process.wait()
112
+ progress.update(task, completed=100)
113
+
114
+ if process.returncode != 0:
115
+ log_file = logging.getLogger().handlers[0].baseFilename
116
+ console.print(f"[bold red]An error occurred during processing. Check {log_file} for details.[/bold red]")
117
+ return False
118
+
119
+ logging.info("Command successful (with progress bar).")
120
+ return True
121
+
122
+
123
+ def has_audio_stream(file_path):
124
+ """Check if the media file has an audio stream."""
125
+ try:
126
+ probe = ffmpeg.probe(file_path, select_streams='a')
127
+ return 'streams' in probe and len(probe['streams']) > 0
128
+ except ffmpeg.Error:
129
+ return False
@@ -0,0 +1,52 @@
1
+
2
+ import os
3
+ from pathlib import Path
4
+
5
+ import questionary
6
+ from rich.console import Console
7
+
8
+ try:
9
+ import tkinter as tk
10
+ from tkinter import filedialog
11
+ except ImportError:
12
+ tk = None
13
+
14
+ console = Console()
15
+
16
+
17
+ def get_media_files():
18
+ """Scan the current directory for media files."""
19
+ media_extensions = [
20
+ # Video
21
+ ".mkv", ".mp4", ".avi", ".mov", ".webm", ".flv", ".wmv",
22
+ # Audio
23
+ ".mp3", ".flac", ".wav", ".ogg",
24
+ # GIF
25
+ ".gif",
26
+ # Image
27
+ ".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff"
28
+ ]
29
+ files = [f for f in os.listdir('.') if os.path.isfile(f) and Path(f).suffix.lower() in media_extensions]
30
+ return files
31
+
32
+
33
+ def select_media_file():
34
+ """Display a menu to select a media file, or open a file picker."""
35
+ media_files = get_media_files()
36
+ if not media_files:
37
+ console.print("[bold yellow]No media files found in this directory.[/bold yellow]")
38
+ if tk and questionary.confirm("Would you like to select a file from another location?").ask():
39
+ root = tk.Tk()
40
+ root.withdraw()
41
+ file_path = filedialog.askopenfilename(
42
+ title="Select a media file",
43
+ filetypes=[("Media Files", "*.mkv *.mp4 *.avi *.mov *.webm *.flv *.wmv *.mp3 *.flac *.wav *.ogg *.gif *.jpg *.jpeg *.png *.webp *.bmp *.tiff"), ("All Files", "*.*")]
44
+ )
45
+ return file_path if file_path else None
46
+ return None
47
+
48
+ choices = media_files + [questionary.Separator(), "Back"]
49
+ file = questionary.select("Select a media file to process:", choices=choices, use_indicator=True).ask()
50
+
51
+ # Return the absolute path to prevent "file not found" errors
52
+ return os.path.abspath(file) if file and file != "Back" else None
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: peg_this
3
+ Version: 4.0.0
4
+ Summary: A powerful and intuitive command-line video editor, built on FFmpeg.
5
+ Author-email: Hariharen S S <thisishariharen@gmail.com>
6
+ Project-URL: Homepage, https://github.com/hariharen9/ffmpeg-this
7
+ Project-URL: Documentation, https://github.com/hariharen9/ffmpeg-this/blob/main/README.md
8
+ Project-URL: Funding, https://www.buymeacoffee.com/hariharen
9
+ Project-URL: Say Thanks!, https://saythanks.io/to/thisishariharen
10
+ Project-URL: Social, https://twitter.com/thisishariharen
11
+ Project-URL: Bug Tracker, https://github.com/hariharen9/ffmpeg-this/issues
12
+ Project-URL: Releases, https://github.com/hariharen9/ffmpeg-this/releases
13
+ Project-URL: Sponsor, https://github.com/sponsors/hariharen9
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Multimedia :: Video :: Conversion
18
+ Classifier: Topic :: Multimedia :: Video :: Non-Linear Editor
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: ffmpeg-python==0.2.0
23
+ Requires-Dist: questionary>=2.0.0
24
+ Requires-Dist: rich>=13.0.0
25
+ Requires-Dist: Pillow>=9.0.0
26
+ Dynamic: license-file
27
+
28
+ # 🎬 ffmPEG-this
29
+
30
+ <p align="center">
31
+ <a href="https://pypi.org/project/peg-this/">
32
+ <img src="https://img.shields.io/pypi/v/peg_this?color=blue&label=version" alt="PyPI Version">
33
+ </a>
34
+ <a href="https://pypi.org/project/peg-this/">
35
+ <img src="https://img.shields.io/pypi/pyversions/peg_this.svg" alt="PyPI Python Versions">
36
+ </a>
37
+ <a href="https://github.com/hariharen9/ffmpeg-this/blob/main/LICENSE">
38
+ <img src="https://img.shields.io/github/license/hariharen9/ffmpeg-this" alt="License">
39
+ </a>
40
+ <a href="https://pepy.tech/project/peg-this">
41
+ <img src="https://static.pepy.tech/badge/peg-this" alt="Downloads">
42
+ </a>
43
+ </p>
44
+
45
+ > Your Video editor within CLI 🚀
46
+
47
+ A powerful and user-friendly batch script for converting, manipulating, and inspecting media files using the power of FFmpeg. This script provides a simple command-line menu to perform common audio and video tasks without needing to memorize complex FFmpeg commands.
48
+
49
+
50
+ <p align="center">
51
+ <img src="/assets/peg.gif" width="720">
52
+ </p>
53
+
54
+
55
+ ## ✨ Features
56
+
57
+ - **Inspect Media Properties**: View detailed information about video and audio streams, including codecs, resolution, frame rate, bitrates, and more.
58
+ - **Convert & Transcode**: Convert videos and audio to a wide range of popular formats (MP4, MKV, WebM, MP3, FLAC, WAV, GIF) with simple quality presets.
59
+ - **Join Videos (Concatenate)**: Combine two or more videos into a single file. The tool automatically handles differences in resolution and audio sample rates for a seamless join.
60
+ - **Trim (Cut) Videos**: Easily cut a video to a specific start and end time without re-encoding for fast, lossless clips.
61
+ - **Visually Crop Videos**: An interactive tool that shows you a frame of the video, allowing you to click and drag to select the exact area you want to crop.
62
+ - **Extract Audio**: Rip the audio track from any video file into MP3, FLAC, or WAV.
63
+ - **Remove Audio**: Create a silent version of your video by stripping out all audio streams.
64
+ - **Batch Conversion**: Convert all media files in the current directory to a specified format in one go.
65
+ - **CLI Interface**: A user-friendly command-line interface that makes it easy to perform common tasks and navigate the tool's features.
66
+
67
+
68
+ ## 🚀 Usage
69
+ ### Prerequisite: Install FFmpeg
70
+
71
+ > [NOTE]
72
+ > `peg_this` uses a library called `ffmpeg-python` which acts as a controller for the main FFmpeg program. It does not include FFmpeg itself. Therefore, you must have FFmpeg installed on your system and available in your terminal's PATH.
73
+
74
+ For **macOS** users, the easiest way to install it is with [Homebrew](https://brew.sh/):
75
+ ```bash
76
+ brew install ffmpeg
77
+ ```
78
+
79
+ For **Windows** users, you can use a package manager like [Chocolatey](https://chocolatey.org/) or [Scoop](https://scoop.sh/):
80
+ ```bash
81
+ # Using Chocolatey
82
+ choco install ffmpeg
83
+
84
+ # Using Scoop
85
+ scoop install ffmpeg
86
+ ```
87
+
88
+ For other systems, please see the official download page: **[ffmpeg.org/download.html](https://ffmpeg.org/download.html)**
89
+
90
+ There are three ways to use `peg_this`:
91
+
92
+ ### 1. Pip Install (Recommended)
93
+ This is the easiest way to get started. This will install the tool and all its dependencies.
94
+
95
+ ```bash
96
+ pip install peg_this
97
+ ```
98
+
99
+ Once installed, you can run the tool from your terminal:
100
+
101
+ ```bash
102
+ peg_this
103
+ ```
104
+
105
+ ### 2. Download from Release
106
+ If you prefer not to install the package, you can download a pre-built executable from the [Releases](https://github.com/hariharen9/ffmpeg-this/releases/latest) page.
107
+
108
+ 1. Download the executable for your operating system (Windows, macOS, or Linux).
109
+ 2. Place it in a directory with your media files.
110
+ 3. Run the executable directly from your terminal.
111
+
112
+ ### 3. Run from Source
113
+ If you want to run the script directly from the source code:
114
+
115
+ 1. **Clone the repository:**
116
+ ```bash
117
+ git clone https://github.com/hariharen9/ffmpeg-this.git
118
+ cd ffmpeg-this
119
+ ```
120
+ 2. **Install dependencies:**
121
+ ```bash
122
+ pip install -r requirements.txt
123
+ ```
124
+ 3. **Run the script:**
125
+ ```bash
126
+ python -m src.peg_this.peg_this
127
+ ```
128
+
129
+ ## 📈 Star History
130
+
131
+ <p align="center">
132
+ <a href="https://star-history.com/#hariharen9/ffmpeg-this&Date">
133
+ <img src="https://api.star-history.com/svg?repos=hariharen9/ffmpeg-this&type=Date" alt="Star History Chart">
134
+ </a>
135
+ </p>
136
+
137
+ ## ✨ Sponsor
138
+
139
+ <p align="center">
140
+ <a href="https://github.com/sponsors/hariharen9">
141
+ <img src="https://img.shields.io/github/sponsors/hariharen9?style=for-the-badge&logo=github&color=white" alt="GitHub Sponsors">
142
+ </a>
143
+ <a href="https://www.buymeacoffee.com/hariharen">
144
+ <img src="https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black" alt="Buy Me a Coffee">
145
+ </a>
146
+ </p>
147
+
148
+ ## 👥 Contributors
149
+
150
+ <a href="https://github.com/hariharen9/ffmpeg-this/graphs/contributors">
151
+ <img src="https://contrib.rocks/image?repo=hariharen9/ffmpeg-this" />
152
+ </a>
153
+
154
+ ## 🤝 Contributing
155
+
156
+ Contributions are welcome! Please see the [Contributing Guidelines](CONTRIBUTING.md) for more information.
157
+
158
+ ## 📄 License
159
+
160
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
161
+
162
+ <p align="center">
163
+ <h2>Made with ❤️ by <a href="https://hariharen.site">Hariharen</a></h2>
164
+ </p>
@@ -0,0 +1,19 @@
1
+ peg_this/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ peg_this/peg_this.py,sha256=0KaDkZ2r2gNUkXaYZOCNG8ps9zD41tYVxKfM5_YewkE,5093
3
+ peg_this/features/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ peg_this/features/audio.py,sha256=O0_lRjzolualxWVXiSiEke5vOpPGwkz0FbMQy5brO58,1533
5
+ peg_this/features/batch.py,sha256=72yXjNfvg-SCxjtaacFzFudmZ8Yd7_rLpvJzbwB8UdA,5178
6
+ peg_this/features/convert.py,sha256=fHlEx8iHEWBrwRfUH6w5ucXLhya7puiUO_DiE2w4kzE,8601
7
+ peg_this/features/crop.py,sha256=haDbDjSKbtNzC7UM5rr4ZizERmMrs4LAkmreNoirasM,7030
8
+ peg_this/features/inspect.py,sha256=xtlmedpsMYQ-vLsnDNzUF59TiZDFLGMyL_wtd8PgiHg,2535
9
+ peg_this/features/join.py,sha256=w_HUsuBv0g9nlOjVvdkeT9dDwxOEvdyvsYCwNocwl98,3414
10
+ peg_this/features/trim.py,sha256=2ZWSNpl4DzSCPt6q7FZloQc-Rga5cX8IW69MfzAZysE,863
11
+ peg_this/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ peg_this/utils/ffmpeg_utils.py,sha256=rmkfOXMNAKqRo3Dkv0aUnUSLxsTdjxDeKMdw3VSCtOU,5409
13
+ peg_this/utils/ui_utils.py,sha256=aIGmRuZEHnp9rAo-WlsfxAESrSTD0bXQMGXqWtnw9TI,1776
14
+ peg_this-4.0.0.dist-info/licenses/LICENSE,sha256=WL1MklYSco7KZvDjbf191tIKOxWQdekqda7dDJc6Wn8,1067
15
+ peg_this-4.0.0.dist-info/METADATA,sha256=bSk0w-PMQhxDJdWCGfKY7oQj3VmFYSb0PaWchrWLg2A,6513
16
+ peg_this-4.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ peg_this-4.0.0.dist-info/entry_points.txt,sha256=9GVTFuE1w_wgY-Tz3--wI5j52BAKrt4atphVD8ioHhQ,52
18
+ peg_this-4.0.0.dist-info/top_level.txt,sha256=kSS5jZg3KN2kJqYZwMvQnI4gvlFxsUNzIm3QJsbKFdc,9
19
+ peg_this-4.0.0.dist-info/RECORD,,
@@ -1,87 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: peg_this
3
- Version: 3.0.2
4
- Summary: A powerful, intuitive command-line video editor suite, built on FFmpeg.
5
- Author-email: Hariharen S S <thisishariharen@gmail.com>
6
- Project-URL: Homepage, https://github.com/hariharen9/ffmpeg-this
7
- Project-URL: Bug Tracker, https://github.com/hariharen9/ffmpeg-this/issues
8
- Project-URL: Releases, https://github.com/hariharen9/ffmpeg-this/releases
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Classifier: Topic :: Multimedia :: Video :: Conversion
13
- Classifier: Topic :: Multimedia :: Video :: Non-Linear Editor
14
- Requires-Python: >=3.8
15
- Description-Content-Type: text/markdown
16
- License-File: LICENSE
17
- Requires-Dist: ffmpeg-python==0.2.0
18
- Requires-Dist: questionary>=2.0.0
19
- Requires-Dist: rich>=13.0.0
20
- Requires-Dist: Pillow>=9.0.0
21
- Dynamic: license-file
22
-
23
- # 🎬 ffmPEG-this
24
-
25
- > Your Video editor within CLI 🚀
26
-
27
- A powerful and user-friendly batch script for converting, manipulating, and inspecting media files using the power of FFmpeg. This script provides a simple command-line menu to perform common audio and video tasks without needing to memorize complex FFmpeg commands.
28
-
29
- ## ✨ Features
30
-
31
- - **Inspect Media Properties**: View detailed information about video and audio streams, including codecs, resolution, frame rate, bitrates, and more.
32
- - **Convert & Transcode**: Convert videos and audio to a wide range of popular formats (MP4, MKV, WebM, MP3, FLAC, WAV, GIF) with simple quality presets.
33
- - **Join Videos (Concatenate)**: Combine two or more videos into a single file. The tool automatically handles differences in resolution and audio sample rates for a seamless join.
34
- - **Trim (Cut) Videos**: Easily cut a video to a specific start and end time without re-encoding for fast, lossless clips.
35
- - **Visually Crop Videos**: An interactive tool that shows you a frame of the video, allowing you to click and drag to select the exact area you want to crop.
36
- - **Extract Audio**: Rip the audio track from any video file into MP3, FLAC, or WAV.
37
- - **Remove Audio**: Create a silent version of your video by stripping out all audio streams.
38
- - **Batch Conversion**: Convert all media files in the current directory to a specified format in one go.
39
-
40
-
41
- ## 🚀 Usage
42
-
43
- There are three ways to use `peg_this`:
44
-
45
- ### 1. Pip Install (Recommended)
46
-
47
- This is the easiest way to get started. This will install the tool and all its dependencies, including `ffmpeg`.
48
-
49
- ```bash
50
- pip install peg_this
51
- ```
52
-
53
- Once installed, you can run the tool from your terminal:
54
-
55
- ```bash
56
- peg_this
57
- ```
58
-
59
- ### 2. Download from Release
60
-
61
- If you don't want to install the package, you can download a pre-built executable from the [Releases](https://github.com/hariharen9/ffmpeg-this/releases/latest) page.
62
-
63
- 1. Download the executable for your operating system (Windows, macOS, or Linux).
64
- 2. Place the downloaded file in a directory with your media files.
65
- 3. Run the executable directly from your terminal or command prompt.
66
-
67
- ### 3. Run from Source
68
-
69
- If you want to run the script directly from the source code:
70
-
71
- 1. **Clone the repository:**
72
- ```bash
73
- git clone https://github.com/hariharen9/ffmpeg-this.git
74
- cd ffmpeg-this
75
- ```
76
- 2. **Install dependencies:**
77
- ```bash
78
- pip install -r requirements.txt
79
- ```
80
- 3. **Run the script:**
81
- ```bash
82
- python src/peg_this/peg_this.py
83
- ```
84
-
85
- ## 📄 License
86
-
87
- This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -1,8 +0,0 @@
1
- peg_this/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- peg_this/peg_this.py,sha256=JSxUYO5zjg0URu6SG3I1AWio_yQ8t8wKW9yqP-pRbUY,30228
3
- peg_this-3.0.2.dist-info/licenses/LICENSE,sha256=WL1MklYSco7KZvDjbf191tIKOxWQdekqda7dDJc6Wn8,1067
4
- peg_this-3.0.2.dist-info/METADATA,sha256=suW_MI8jSHxZXEKKOsrry7QnXoHyVZ0s6ZFljc-RKy8,3527
5
- peg_this-3.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- peg_this-3.0.2.dist-info/entry_points.txt,sha256=9GVTFuE1w_wgY-Tz3--wI5j52BAKrt4atphVD8ioHhQ,52
7
- peg_this-3.0.2.dist-info/top_level.txt,sha256=kSS5jZg3KN2kJqYZwMvQnI4gvlFxsUNzIm3QJsbKFdc,9
8
- peg_this-3.0.2.dist-info/RECORD,,