# Catch Up TV Implementation Guide

This document provides a comprehensive guide on how Catch Up TV is implemented and how to configure it in your IPTV Middleware system.

## 1. Overview
Catch Up TV (also known as Timeshift or Archive) allows users to watch previously aired programs from the Life TV channels. This is achieved by recording the live stream on the server (or using a provider's archive feature) and making it available via time-parameterized URLs.

## 2. Prerequisites
- **EPG (Electronic Program Guide)**: For "EPG-based" catchup, you must have functional EPG data for the channels.
- **Streaming Provider with Archive Support**: Your streaming server (Flussonic, Wowza, Akamai, etc.) must be configured to maintain a DVR/Archive for the desired number of days.

## 3. Configuration Steps

### A. Global Activation
Ensure that the Catchup feature is enabled for your application:
1. Navigate to **App Customization > General**.
2. Locate the **Catchup** toggle and set it to **Active**.
3. Save the changes.

### B. Configuring Catch Up for a Channel
1. Go to **Channel Services > Catch Up Tv**.
2. Click on **Add Catch Up Tv**.
3. Fill in the following details:
   - **Tv Channel**: Select the channel you want to enable catchup for.
   - **Days**: Enter the number of days the archive is available (e.g., 7 days).
   - **Schedule Base**:
     - `EPG`: Recommended. Catchup entries will align perfectly with program start/end times.
     - `Hourly`: Records in fixed 1-hour blocks.
   - **Streaming Provider**: Select your provider (e.g., `Flussonic`, `Wowza`).
   - **Custom Streaming URL**: If enabled, you can provide a specific pattern for the catchup stream.
   - **DRM/Token Settings**: Configure if your stream is protected.
4. Set **Enable** to Active and click **Submit**.

## 4. Technical Implementation Details

### Backend Logic
The catchup functionality is managed within the `channel-services` package.
- **Controller**: `Contus\ChannelServices\Http\Controllers\Admin\ChannelServiceController`
- **Frontend Logic**: `public/adminview/assets/js/chnnel-service/catch-up.js`
- **Database**: Catchup configurations are stored in the database (linked to the `channels` table).

### URL Generation Pattern
When a user selects a catchup program, the system generates a URL usually following this logic:
- **Flussonic**: `http://server/channel/archive-TIMESTAMP-DURATION.m3u8`
- **Wowza/Generic**: `http://server/channel?timeshift=TIMESTAMP`

The middleware uses the EPG start time (converted to UTC timestamp) to request the correct segment from the archive.

## 5. Troubleshooting
- **No Catchup programs appearing**: Ensure EPG is successfully imported for that channel.
- **Playback fails**: 
  - Verify the `Streaming Provider` setting matches your server.
  - Check if the DVR/Archive feature is actually enabled on the streaming server.
  - Ensure the "Days" setting in the admin panel does not exceed the server's actual archive duration.

---
*Generated by Antigravity AI*
