createStrmFile creates a single .strm file for VOD content
(stream map[string]string, vodDir string)
| 1292 | |
| 1293 | // createStrmFile creates a single .strm file for VOD content |
| 1294 | func createStrmFile(stream map[string]string, vodDir string) error { |
| 1295 | name, ok := stream["name"] |
| 1296 | if !ok { |
| 1297 | return fmt.Errorf("stream missing name") |
| 1298 | } |
| 1299 | |
| 1300 | url, ok := stream["url"] |
| 1301 | if !ok { |
| 1302 | return fmt.Errorf("stream missing URL") |
| 1303 | } |
| 1304 | |
| 1305 | // Log original name for debugging if it's suspiciously long |
| 1306 | if len(name) > 100 { |
| 1307 | showDebug(fmt.Sprintf("createStrmFile: Long stream name detected (%d chars): %s", len(name), name[:100]+"..."), 1) |
| 1308 | } |
| 1309 | |
| 1310 | // Clean filename for filesystem |
| 1311 | cleanName := cleanFileName(name) |
| 1312 | |
| 1313 | // Add season/episode info if available |
| 1314 | if seasonEpisode, exists := stream["_season_episode"]; exists && seasonEpisode != "" { |
| 1315 | cleanName = cleanName + " " + seasonEpisode |
| 1316 | } |
| 1317 | |
| 1318 | // Final safety check - ensure filename is not too long |
| 1319 | maxFilenameLength := 200 // Conservative limit for most filesystems |
| 1320 | if len(cleanName) > maxFilenameLength { |
| 1321 | showDebug(fmt.Sprintf("createStrmFile: Truncating filename from %d to %d characters", len(cleanName), maxFilenameLength), 1) |
| 1322 | cleanName = cleanName[:maxFilenameLength] |
| 1323 | // Try to truncate at a word boundary |
| 1324 | if lastSpace := strings.LastIndex(cleanName, " "); lastSpace > maxFilenameLength/2 { |
| 1325 | cleanName = cleanName[:lastSpace] |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | // Create .strm file |
| 1330 | strmPath := vodDir + string(os.PathSeparator) + cleanName + ".strm" |
| 1331 | |
| 1332 | // Write URL to .strm file |
| 1333 | file, err := os.Create(strmPath) |
| 1334 | if err != nil { |
| 1335 | return fmt.Errorf("failed to create .strm file: %v", err) |
| 1336 | } |
| 1337 | defer file.Close() |
| 1338 | |
| 1339 | _, err = file.WriteString(url) |
| 1340 | if err != nil { |
| 1341 | return fmt.Errorf("failed to write URL to .strm file: %v", err) |
| 1342 | } |
| 1343 | |
| 1344 | return nil |
| 1345 | } |
| 1346 | |
| 1347 | // cleanFileName removes invalid characters for filesystem and truncates long names |
| 1348 | func cleanFileName(name string) string { |
no test coverage detected