Skip to content

Commit f97ae1a

Browse files
committed
Update
1 parent 66e7c01 commit f97ae1a

File tree

7 files changed

+1291
-28
lines changed

7 files changed

+1291
-28
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@ AWS_BUCKET=
6363
AWS_USE_PATH_STYLE_ENDPOINT=false
6464

6565
VITE_APP_NAME="${APP_NAME}"
66+
67+
# Video Download API Configuration
68+
VIDEO_DOWNLOAD_API_KEY=your_api_key_here
69+
VIDEO_DOWNLOAD_API_TIMEOUT=120
70+
VIDEO_DOWNLOAD_API_RETRY=3
71+
VIDEO_DOWNLOAD_API_RATE_LIMIT=100
Lines changed: 260 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
<?php
22

3+
// app/Http/Controllers/DownloaderController.php - Updated controller
4+
35
namespace App\Http\Controllers;
46

57
use Illuminate\Http\Request;
68
use Illuminate\View\View;
79
use Illuminate\Http\JsonResponse;
10+
use App\Services\EnhancedVideoDownloadService;
11+
use App\Services\VideoDownloadApiClient;
12+
use App\Http\Middleware\RateLimitDownloads;
813

914
class DownloaderController extends Controller
1015
{
16+
private EnhancedVideoDownloadService $downloadService;
17+
18+
public function __construct(EnhancedVideoDownloadService $downloadService)
19+
{
20+
$this->downloadService = $downloadService;
21+
22+
}
23+
1124
public function fourKVideo(): View
1225
{
1326
$pageData = [
1427
'title' => '4K Video Downloader',
1528
'subtitle' => 'Download videos in ultra-high 4K resolution',
1629
'description' => 'Get stunning 4K quality videos from your favorite platforms with our advanced downloading technology.',
17-
'supportedQualities' => ['4K (2160p)', '2K (1440p)', '1080p (Full HD)', '720p (HD)', '480p (SD)']
30+
'supportedQualities' => ['4K (2160p)', '2K (1440p)', '1080p (Full HD)', '720p (HD)', '480p (SD)'],
31+
'pricing_note' => '4K downloads may incur additional charges for extended duration videos.'
1832
];
1933

2034
return view('downloaders.4k-video', compact('pageData'));
@@ -26,7 +40,14 @@ public function videoToMp3(): View
2640
'title' => 'Video to MP3 Downloader',
2741
'subtitle' => 'Extract audio and download as MP3',
2842
'description' => 'Convert and download video audio as high-quality MP3 files from any supported platform.',
29-
'supportedFormats' => ['MP3', 'WAV', 'M4A', 'AAC', 'OGG']
43+
'supportedFormats' => ['MP3', 'WAV', 'M4A', 'AAC', 'FLAC', 'OGG'],
44+
'audio_qualities' => [
45+
'96' => '96 kbps (Mobile)',
46+
'128' => '128 kbps (Standard)',
47+
'192' => '192 kbps (High)',
48+
'256' => '256 kbps (Premium)',
49+
'320' => '320 kbps (Maximum)'
50+
]
3051
];
3152

3253
return view('downloaders.video-mp3', compact('pageData'));
@@ -38,7 +59,13 @@ public function playlistDownloader(): View
3859
'title' => 'Playlist Downloader',
3960
'subtitle' => 'Download entire playlists with one click',
4061
'description' => 'Save time by downloading complete playlists, channels, or collections in batch.',
41-
'features' => ['Batch downloading', 'Queue management', 'Progress tracking', 'Format selection per video']
62+
'features' => [
63+
'Batch downloading',
64+
'Queue management',
65+
'Progress tracking',
66+
'Format selection per video'
67+
],
68+
'batch_limit' => 50 // Maximum videos per batch
4269
];
4370

4471
return view('downloaders.playlist', compact('pageData'));
@@ -50,7 +77,9 @@ public function videoToWav(): View
5077
'title' => 'Video to WAV Downloader',
5178
'subtitle' => 'Download video audio as high-quality WAV files',
5279
'description' => 'Extract and download video audio in uncompressed WAV format for the best quality.',
53-
'benefits' => ['Lossless audio quality', 'Professional standard', 'Universal compatibility']
80+
'benefits' => ['Lossless audio quality', 'Professional standard', 'Universal compatibility'],
81+
'sample_rates' => ['44100', '48000', '96000'],
82+
'bit_depths' => ['16', '24', '32']
5483
];
5584

5685
return view('downloaders.video-wav', compact('pageData'));
@@ -68,41 +97,248 @@ public function video1080p(): View
6897
return view('downloaders.1080p', compact('pageData'));
6998
}
7099

100+
/**
101+
* Get comprehensive video information using the external API
102+
*/
71103
public function getVideoInfo(Request $request): JsonResponse
72104
{
73105
$request->validate([
74106
'url' => 'required|url'
75107
]);
76108

77-
// Simulate video info extraction
78-
$videoInfo = [
79-
'title' => 'Sample Video Title',
80-
'duration' => '3:45',
81-
'thumbnail' => 'https://via.placeholder.com/480x360',
82-
'available_qualities' => ['4K', '1080p', '720p', '480p'],
83-
'available_formats' => ['MP4', 'WEBM', 'MP3', 'WAV']
84-
];
109+
try {
110+
$videoInfo = $this->downloadService->getVideoInfo($request->input('url'));
111+
112+
return response()->json($videoInfo);
85113

86-
return response()->json([
87-
'success' => true,
88-
'video_info' => $videoInfo
89-
]);
114+
} catch (\Exception $e) {
115+
return response()->json([
116+
'success' => false,
117+
'error' => 'Failed to retrieve video information: ' . $e->getMessage()
118+
], 400);
119+
}
90120
}
91121

122+
/**
123+
* Start download process using external API
124+
*/
92125
public function download(Request $request): JsonResponse
93126
{
94127
$request->validate([
95128
'url' => 'required|url',
96-
'quality' => 'required|string|in:4k,1080p,720p,480p',
97-
'format' => 'required|string|in:mp4,webm,mp3,wav'
129+
'quality' => 'required|string|in:4k,8k,1440p,1080p,720p,480p,360p',
130+
'format' => 'required|string|in:mp4,webm,mp3,m4a,wav,flac,aac,ogg',
131+
'audio_quality' => 'sometimes|integer|in:96,128,192,256,320',
132+
'audio_language' => 'sometimes|string|size:2' // ISO 639-1 language codes
133+
]);
134+
135+
try {
136+
$url = $request->input('url');
137+
$quality = $request->input('quality');
138+
$format = $request->input('format');
139+
$audioQuality = $request->input('audio_quality', 128);
140+
$audioLanguage = $request->input('audio_language');
141+
142+
// Determine download type based on format
143+
$isAudio = in_array($format, ['mp3', 'm4a', 'wav', 'flac', 'aac', 'ogg']);
144+
145+
$options = [];
146+
if ($audioLanguage) {
147+
$options['audio_language'] = $audioLanguage;
148+
}
149+
150+
if ($isAudio) {
151+
// Audio extraction
152+
if ($format === 'wav') {
153+
$result = $this->downloadService->extractWAV($url, $audioQuality);
154+
} elseif ($format === 'flac') {
155+
$result = $this->downloadService->extractFLAC($url);
156+
} else {
157+
$result = $this->downloadService->extractAudio($url, $format, $audioQuality, $options);
158+
}
159+
} else {
160+
// Video download
161+
if ($quality === '4k') {
162+
$result = $this->downloadService->download4K($url, $options);
163+
} else {
164+
$result = $this->downloadService->downloadVideo($url, $quality, $options);
165+
}
166+
}
167+
168+
if ($result['success']) {
169+
return response()->json([
170+
'success' => true,
171+
'message' => 'Download started successfully',
172+
'download_id' => $result['download_id'],
173+
'type' => $result['type'],
174+
'format_name' => $result['format_name'] ?? $format,
175+
'info' => $result['info'] ?? null,
176+
'pricing' => $result['pricing'] ?? null,
177+
'requires_payment' => $result['requires_payment'] ?? false
178+
]);
179+
}
180+
181+
return response()->json($result, 400);
182+
183+
} catch (\Exception $e) {
184+
return response()->json([
185+
'success' => false,
186+
'error' => 'Download failed: ' . $e->getMessage()
187+
], 500);
188+
}
189+
}
190+
191+
/**
192+
* Get download status and progress
193+
*/
194+
public function downloadStatus(Request $request): JsonResponse
195+
{
196+
$request->validate([
197+
'download_id' => 'required|string'
198+
]);
199+
200+
try {
201+
$result = $this->downloadService->getDownloadStatus($request->input('download_id'));
202+
203+
return response()->json($result);
204+
205+
} catch (\Exception $e) {
206+
return response()->json([
207+
'success' => false,
208+
'error' => 'Failed to get download status: ' . $e->getMessage()
209+
], 400);
210+
}
211+
}
212+
213+
/**
214+
* Batch download multiple videos
215+
*/
216+
public function batchDownload(Request $request): JsonResponse
217+
{
218+
$request->validate([
219+
'urls' => 'required|array|min:1|max:50',
220+
'urls.*' => 'required|url',
221+
'quality' => 'required|string|in:4k,1440p,1080p,720p,480p,360p',
222+
'format' => 'sometimes|string|in:mp4,webm',
223+
'audio_language' => 'sometimes|string|size:2'
98224
]);
99225

100-
// Simulate download process
101-
return response()->json([
102-
'success' => true,
103-
'message' => 'Download started successfully',
104-
'download_id' => uniqid(),
105-
'estimated_time' => rand(10, 120) // seconds
226+
try {
227+
$urls = $request->input('urls');
228+
$quality = $request->input('quality');
229+
$options = [];
230+
231+
if ($request->has('audio_language')) {
232+
$options['audio_language'] = $request->input('audio_language');
233+
}
234+
235+
$result = $this->downloadService->batchDownload($urls, $quality, $options);
236+
237+
return response()->json([
238+
'success' => $result['success'],
239+
'message' => $result['success'] ? 'Batch download started' : 'Some downloads failed',
240+
'summary' => $result['summary'],
241+
'results' => $result['results']
242+
]);
243+
244+
} catch (\Exception $e) {
245+
return response()->json([
246+
'success' => false,
247+
'error' => 'Batch download failed: ' . $e->getMessage()
248+
], 500);
249+
}
250+
}
251+
252+
/**
253+
* Get supported formats for a specific video
254+
*/
255+
public function getSupportedFormats(Request $request): JsonResponse
256+
{
257+
$request->validate([
258+
'url' => 'required|url'
259+
]);
260+
261+
try {
262+
$apiClient = app(VideoDownloadApiClient::class);
263+
$result = $apiClient->getSupportedFormats($request->input('url'));
264+
265+
return response()->json($result);
266+
267+
} catch (\Exception $e) {
268+
return response()->json([
269+
'success' => false,
270+
'error' => 'Failed to get supported formats: ' . $e->getMessage()
271+
], 400);
272+
}
273+
}
274+
275+
/**
276+
* Download video with specific time range (clip)
277+
*/
278+
public function downloadClip(Request $request): JsonResponse
279+
{
280+
$request->validate([
281+
'url' => 'required|url',
282+
'quality' => 'required|string|in:1080p,720p,480p,360p',
283+
'start_time' => 'required|integer|min:0',
284+
'end_time' => 'required|integer|min:1',
285+
'format' => 'sometimes|string|in:mp4,webm'
106286
]);
287+
288+
try {
289+
$apiClient = app(VideoDownloadApiClient::class);
290+
291+
$url = $request->input('url');
292+
$quality = $request->input('quality');
293+
$startTime = $request->input('start_time');
294+
$endTime = $request->input('end_time');
295+
296+
// Validate time range
297+
if ($endTime <= $startTime) {
298+
return response()->json([
299+
'success' => false,
300+
'error' => 'End time must be greater than start time'
301+
], 400);
302+
}
303+
304+
if (($endTime - $startTime) > 3600) { // 1 hour limit
305+
return response()->json([
306+
'success' => false,
307+
'error' => 'Clip duration cannot exceed 1 hour'
308+
], 400);
309+
}
310+
311+
$formatMapping = [
312+
'360p' => VideoDownloadApiClient::FORMAT_360P,
313+
'480p' => VideoDownloadApiClient::FORMAT_480P,
314+
'720p' => VideoDownloadApiClient::FORMAT_720P,
315+
'1080p' => VideoDownloadApiClient::FORMAT_1080P,
316+
];
317+
318+
$result = $apiClient->downloadClip(
319+
$url,
320+
$formatMapping[$quality],
321+
$startTime,
322+
$endTime
323+
);
324+
325+
if ($result['success']) {
326+
return response()->json([
327+
'success' => true,
328+
'message' => 'Clip download started',
329+
'download_id' => $result['download_id'],
330+
'clip_duration' => $endTime - $startTime,
331+
'info' => $result['info'] ?? null
332+
]);
333+
}
334+
335+
return response()->json($result, 400);
336+
337+
} catch (\Exception $e) {
338+
return response()->json([
339+
'success' => false,
340+
'error' => 'Clip download failed: ' . $e->getMessage()
341+
], 500);
342+
}
107343
}
108344
}

app/Providers/AppServiceProvider.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3+
34
namespace App\Providers;
45

56
use Illuminate\Support\ServiceProvider;
7+
use App\Services\VideoDownloadApiClient;
8+
use App\Services\EnhancedVideoDownloadService;
69

710
class AppServiceProvider extends ServiceProvider
811
{
@@ -11,7 +14,21 @@ class AppServiceProvider extends ServiceProvider
1114
*/
1215
public function register(): void
1316
{
14-
//
17+
// Register the API client as a singleton
18+
$this->app->singleton(VideoDownloadApiClient::class, function ($app) {
19+
return new VideoDownloadApiClient(
20+
config('services.video_download_api.key'),
21+
[
22+
'timeout' => config('services.video_download_api.timeout', 120),
23+
'retry_times' => config('services.video_download_api.retry_times', 3),
24+
]
25+
);
26+
});
27+
28+
// Register the enhanced download service
29+
$this->app->singleton(EnhancedVideoDownloadService::class, function ($app) {
30+
return new EnhancedVideoDownloadService();
31+
});
1532
}
1633

1734
/**

0 commit comments

Comments
 (0)