# Implementasi Extractor Slicedrive dan Viodee

Tanggal: 24 Juni 2026
Status: ✅ SELESAI DAN TERUJI

## Ringkasan

Kedua extractor untuk provider video **Slicedrive** dan **Viodee** telah berhasil diimplementasikan, diuji, dan terintegrasi dengan system player.

## 1. Slicedrive Extractor

### Lokasi File
[app/Services/Extractors/SlicedriveExtractor.php](app/Services/Extractors/SlicedriveExtractor.php)

### Cara Kerja
1. **Fetch HTML halaman embed**: Mengambil halaman video dari URL embed
2. **Extract video ID dari URL fragment**: Mengambil video ID dari `#/videoname.mp4`
3. **Fetch JSON config**: Mengambil file `videos.json` dari root domain
4. **Parsing JSON data**: Mencari video yang sesuai dalam array `videos` menggunakan nama dari URL fragment
5. **Return CDN URL**: Mengembalikan URL dari field `cdn` di dalam data video yang sesuai

### Struktur HTML Slicedrive
```html
<script>
const JSON_URL = "videos.json";
fetch(JSON_URL)
  .then(res => res.json())
  .then(data => {
    const vids = data.videos;
    const name = decodeURIComponent(location.hash.replace("#/", ""));
    let selected = vids.find(v => v.name === name);
    video.src = selected.cdn;
  });
</script>
```

### JSON Config Format
```json
{
  "videos": [
    {
      "name": "JI94Mu.mp4",
      "cdn": "https://cdn2.slicedrive.com/3jUbNy6m1.mp4"
    }
  ]
}
```

### Contoh Penggunaan
```
Embed URL: https://cdn2.slicedrive.my.id/#/JI94Mu.mp4
Extracted: https://cdn2.slicedrive.com/3jUbNy6m1.mp4 ✅
```

### Features
- ✅ Automatic JSON configuration fetching
- ✅ Video name matching dari URL fragment
- ✅ Fallback ke video pertama jika video tidak ditemukan
- ✅ Relative URL resolution
- ✅ Comprehensive logging untuk debugging

## 2. Viodee Extractor

### Lokasi File
[app/Services/Extractors/ViodeeExtractor.php](app/Services/Extractors/ViodeeExtractor.php)

### Cara Kerja
1. **Extract video ID dari URL**: Mengambil ID dari path `/e/{videoId}`
2. **Build player endpoint**: Membuat URL ke `/s={videoId}/ds`
3. **Fetch player page**: Mengambil halaman player dari endpoint tersebut
4. **Extract video URL**: Mencari URL `.mp4` atau `.m3u8` di HTML response
5. **Return URL**: Mengembalikan URL video yang sudah ditemukan

### Struktur URL Viodee
```
Embed: https://viodee.co/e/eqv50yaawmnsy.mp4
Player: https://viodee.co/s=eqv50yaawmnsy/ds
```

### HTML Response dari Player Endpoint
Berisi tag video dengan source URL:
```html
<video id="video-container">
  <!-- Video URL di-inject secara dinamis -->
</video>
```

### Contoh Penggunaan
```
Embed URL: https://viodee.co/e/eqv50yaawmnsy.mp4
Extracted: https://box.vchod.cc/videos/soaqtbp2mu4f.mp4 ✅
```

### Features
- ✅ Automatic video ID extraction
- ✅ Smart endpoint building
- ✅ Support untuk .mp4 dan .m3u8 URLs
- ✅ Graceful fallback ke generic extraction
- ✅ Full logging untuk troubleshooting

## 3. Registrasi di VideoService

### Import
```php
use App\Services\Extractors\ViodeeExtractor;
```

### Provider Registry
```php
$extractors = [
    // ... existing extractors ...
    'slicedrive'  => SlicedriveExtractor::class,
    'slicedrive.com' => SlicedriveExtractor::class,
    'viodee'      => ViodeeExtractor::class,
    'viodee.co'   => ViodeeExtractor::class,
];
```

## 4. Test Results

### Slicedrive Video (Od2AXq3p)
```
Provider: slicedrive
Status: ✅ READY
Play Mode: DIRECT
URL: https://cdn2.slicedrive.com/VGAN9Mgy1.mp4
Last Extracted: 2026-06-24 05:49:26
Extract Failed: NO
```

### Viodee Video (8dWdPXn6)
```
Provider: viodee
Status: ✅ READY
Play Mode: DIRECT
URL: https://box.vchod.cc/videos/soaqtbp2mu4f.mp4
Last Extracted: 2026-06-24 06:16:43
Extract Failed: NO
```

## 5. Debugging & Logging

Semua ekstraction activity di-log di channel `extractor` dengan informasi:

### Success Log
```
Slicedrive: Successfully extracted video URL
embed_url: https://cdn2.slicedrive.my.id/#/J194Mu.mp4
video_url: https://cdn2.slicedrive.com/VGAN9Mgy1.mp4
```

### Debug Log
```
Slicedrive: Fetching JSON
json_url: https://cdn2.slicedrive.my.id/videos.json
video_name: J194Mu.mp4
```

### Error Log
```
Slicedrive extract error
url: https://cdn2.slicedrive.my.id/#/...
error: Connection timeout
```

Lihat: `storage/logs/laravel.log`

## 6. Database Schema

Kolom yang digunakan untuk menyimpan extracted URL:
- `hls_url` - Menyimpan URL video yang berhasil di-ekstrak
- `play_mode` - Set ke `'DIRECT'` untuk direct MP4 playback
- `status` - Set ke `'ready'` ketika siap diputar
- `extract_failed` - Set ke `false` ketika berhasil
- `error_message` - Set ke `null` ketika berhasil
- `last_extracted_at` - Timestamp extraction

## 7. Performance

- **Slicedrive**: ~2-3 detik (requires JSON fetch)
- **Viodee**: ~1-2 detik (single HTML parse)
- **Caching**: Tidak digunakan (untuk ensure fresh URLs)

## 8. Troubleshooting

### Slicedrive tidak bekerja
1. Check if `videos.json` is accessible
2. Verify URL format: `https://domain/#/videoname.mp4`
3. Check JSON structure: must have `videos` array with `cdn` field
4. Lihat logs: `tail -f storage/logs/laravel.log | grep -i slicedrive`

### Viodee tidak bekerja
1. Verify endpoint: `https://viodee.co/s=videoId/ds`
2. Check if response contains `.mp4` or `.m3u8` URL
3. Verify video ID extraction dari path `/e/videoId`
4. Lihat logs: `tail -f storage/logs/laravel.log | grep -i viodee`

## 9. Future Improvements

- [ ] Cache video URLs untuk mengurangi extraction delay
- [ ] Batch extraction untuk multiple videos
- [ ] Automatic re-extraction jika URL expired
- [ ] Support untuk Slicedrive variants (slicadrive, dsslicedrive, etc)
- [ ] Support untuk Viodee subtitles/captions

## 10. Referensi

- Base Extractor: [app/Services/Extractors/BaseExtractor.php](app/Services/Extractors/BaseExtractor.php)
- Interface: [app/Services/Extractors/Contracts/HlsExtractorInterface.php](app/Services/Extractors/Contracts/HlsExtractorInterface.php)
- Service: [app/Services/VideoService.php](app/Services/VideoService.php)
