|
| 1 | +package packlit |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | +) |
| 6 | + |
| 7 | +var ( |
| 8 | + _ ShakaParser = (*HLSMasterPlaylistOutputFlag)(nil) |
| 9 | + _ ShakaParser = (*HLSBaseURLFlag)(nil) |
| 10 | + _ ShakaParser = (*HLSKeyURIFlag)(nil) |
| 11 | + _ ShakaParser = (*HLSPlaylistTypeFlag)(nil) |
| 12 | + _ ShakaParser = (*HLSMediaSequenceNumberFlag)(nil) |
| 13 | + _ ShakaParser = (*HLSStartTimeOffsetFlag)(nil) |
| 14 | + _ ShakaParser = (*HLSCreateSessionKeysFlag)(nil) |
| 15 | +) |
| 16 | + |
| 17 | +// HLSMasterPlaylistOutputFlag represents the output path for the master playlist for HLS. |
| 18 | +type HLSMasterPlaylistOutputFlag string |
| 19 | + |
| 20 | +// Parse returns the string representation of HLSMasterPlaylistOutput for use in the command line flags. |
| 21 | +func (h HLSMasterPlaylistOutputFlag) Parse() string { |
| 22 | + return fmt.Sprintf("--hls_master_playlist_output=%s", h) |
| 23 | +} |
| 24 | + |
| 25 | +// Validate checks if the value of HLSMasterPlaylistOutput is valid. |
| 26 | +// This flag must be used to output HLS. |
| 27 | +func (h HLSMasterPlaylistOutputFlag) Validate() error { |
| 28 | + if len(h) == 0 { |
| 29 | + return fmt.Errorf("hls_master_playlist_output is required") |
| 30 | + } |
| 31 | + return nil |
| 32 | +} |
| 33 | + |
| 34 | +// HLSBaseURLFlag represents the base URL for the Media Playlists and media files listed in the playlists. |
| 35 | +type HLSBaseURLFlag string |
| 36 | + |
| 37 | +// Parse returns the string representation of HLSBaseURL for use in the command line flags. |
| 38 | +func (h HLSBaseURLFlag) Parse() string { |
| 39 | + return fmt.Sprintf("--hls_base_url=%s", h) |
| 40 | +} |
| 41 | + |
| 42 | +// Validate checks if the value of HLSBaseURL is valid. |
| 43 | +// The base URL is the prefix for the media files. |
| 44 | +func (h HLSBaseURLFlag) Validate() error { |
| 45 | + if len(h) == 0 { |
| 46 | + return fmt.Errorf("hls_base_url is required") |
| 47 | + } |
| 48 | + return nil |
| 49 | +} |
| 50 | + |
| 51 | +// HLSKeyURIFlag represents the key URI for the 'identity' and 'com.apple.streamingkeydelivery' key formats. |
| 52 | +type HLSKeyURIFlag string |
| 53 | + |
| 54 | +// Parse returns the string representation of HLSKeyURI for use in the command line flags. |
| 55 | +func (h HLSKeyURIFlag) Parse() string { |
| 56 | + return fmt.Sprintf("--hls_key_uri=%s", h) |
| 57 | +} |
| 58 | + |
| 59 | +// Validate checks if the value of HLSKeyURI is valid. |
| 60 | +// The key URI is required if the playlist is encrypted and uses the specified key formats. |
| 61 | +func (h HLSKeyURIFlag) Validate() error { |
| 62 | + if len(h) == 0 { |
| 63 | + return fmt.Errorf("hls_key_uri is required for encrypted playlists with 'identity' and 'com.apple.streamingkeydelivery' formats") |
| 64 | + } |
| 65 | + return nil |
| 66 | +} |
| 67 | + |
| 68 | +// HLSPlaylistTypeFlag represents the type of the playlist: VOD, EVENT, or LIVE. |
| 69 | +type HLSPlaylistTypeFlag string |
| 70 | + |
| 71 | +// Parse returns the string representation of HLSPlaylistType for use in the command line flags. |
| 72 | +func (h HLSPlaylistTypeFlag) Parse() string { |
| 73 | + return fmt.Sprintf("--hls_playlist_type=%s", h) |
| 74 | +} |
| 75 | + |
| 76 | +// Validate checks if the value of HLSPlaylistType is valid. |
| 77 | +func (h HLSPlaylistTypeFlag) Validate() error { |
| 78 | + return nil |
| 79 | +} |
| 80 | + |
| 81 | +// HLSMediaSequenceNumberFlag represents the initial EXT-X-MEDIA-SEQUENCE value. |
| 82 | +type HLSMediaSequenceNumberFlag int |
| 83 | + |
| 84 | +// Parse returns the string representation of HLSMediaSequenceNumber for use in the command line flags. |
| 85 | +func (h HLSMediaSequenceNumberFlag) Parse() string { |
| 86 | + return fmt.Sprintf("--hls_media_sequence_number=%d", h) |
| 87 | +} |
| 88 | + |
| 89 | +// Validate checks if the value of HLSMediaSequenceNumber is valid. |
| 90 | +func (h HLSMediaSequenceNumberFlag) Validate() error { |
| 91 | + return nil |
| 92 | +} |
| 93 | + |
| 94 | +// HLSStartTimeOffsetFlag represents the floating-point number for EXT-X-START time offset. |
| 95 | +type HLSStartTimeOffsetFlag float32 |
| 96 | + |
| 97 | +// Parse returns the string representation of HLSStartTimeOffset for use in the command line flags. |
| 98 | +func (h HLSStartTimeOffsetFlag) Parse() string { |
| 99 | + return fmt.Sprintf("--hls_start_time_offset=%v", h) |
| 100 | +} |
| 101 | + |
| 102 | +// Validate checks if the value of HLSStartTimeOffset is valid. |
| 103 | +func (h HLSStartTimeOffsetFlag) Validate() error { |
| 104 | + return nil |
| 105 | +} |
| 106 | + |
| 107 | +// HLSCreateSessionKeysFlag represents the flag to enable creation of session keys for Offline HLS playback. |
| 108 | +type HLSCreateSessionKeysFlag struct{} |
| 109 | + |
| 110 | +// Parse returns the string representation of HLSCreateSessionKeys for use in the command line flags. |
| 111 | +func (h HLSCreateSessionKeysFlag) Parse() string { |
| 112 | + return "--create_session_keys" |
| 113 | +} |
| 114 | + |
| 115 | +// Validate checks if the value of HLSCreateSessionKeys is valid. |
| 116 | +func (h HLSCreateSessionKeysFlag) Validate() error { |
| 117 | + return nil // No specific validation logic for this flag |
| 118 | +} |
0 commit comments