{"id":17760860,"url":"https://github.com/bimlu/hls-duration-go","last_synced_at":"2025-04-01T13:18:05.818Z","repository":{"id":259167358,"uuid":"875093617","full_name":"bimlu/hls-duration-go","owner":"bimlu","description":"Calculates the total duration of an HLS (HTTP Live Streaming) VOD (Video on Demand)","archived":false,"fork":false,"pushed_at":"2024-10-22T03:33:19.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T08:15:21.595Z","etag":null,"topics":["golang","hls","hls-duration","library","m3u8","manifest"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bimlu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-19T04:50:23.000Z","updated_at":"2024-10-22T03:33:22.000Z","dependencies_parsed_at":"2024-10-23T07:23:14.824Z","dependency_job_id":"3371a820-544f-4129-a3e7-dd31fdfeb841","html_url":"https://github.com/bimlu/hls-duration-go","commit_stats":null,"previous_names":["bimlu/hls-duration-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bimlu%2Fhls-duration-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bimlu%2Fhls-duration-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bimlu%2Fhls-duration-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bimlu%2Fhls-duration-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bimlu","download_url":"https://codeload.github.com/bimlu/hls-duration-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246644097,"owners_count":20810687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","hls","hls-duration","library","m3u8","manifest"],"created_at":"2024-10-26T19:13:50.391Z","updated_at":"2025-04-01T13:18:05.795Z","avatar_url":"https://github.com/bimlu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hls-duration-go\n`hls-duration-go` is a Go library that fetches and calculates the total duration of an HLS (HTTP Live Streaming) VOD (Video on Demand). It loads the master and media playlists, processes the segments, and calculates the cumulative duration.\n\n## Features\n- Fetches the HLS master and media playlists.\n- Calculates the total duration of a VOD based on the media segments in the playlists.\n- Supports multiple media variants from the master playlist.\n\n## Todos\n- Optimize it. no need to fetch all the media manifest. only one is sufficient to calculate the duration.\n\n## Installation\nInstall the package using go get:\n\n```\ngo get github.com/bimlu/hls-duration-go\n```\n\n## Usage\nTo use the hls-duration library in your Go project, follow the example below.\n\n### Example\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/bimlu/hls-duration-go\"\n)\n\nfunc main() {\n\t// Replace the URL with your master manifest URI\n\tduration := hlsduration.Calculate(\"https://d1hsxynlvbyrp1.cloudfront.net/videos/big_bunny/hls/index.m3u8\")\n\tfmt.Printf(\"Total duration of the VOD: %.2f seconds\\n\", duration)\n}\n```\n\n### Output\n```\nTotal duration of the VOD: 62.28 seconds\n```\n\n## API\n`Calculate(masterManifestURI string) float64`\nCalculates the total duration of an HLS VOD.\n* Parameters:\n    * masterManifestURI: The URL of the master manifest .m3u8 file.\n* Returns:\n    * The total duration of the VOD in seconds.\n\n## Testing\nYou can run tests using Go’s built-in testing framework. The project includes a basic test case to validate the duration calculation.\n```\ngo test ./...\n```\n\n### Example test case\n```\npackage hlsduration\n\nimport (\n\t\"fmt\"\n\t\"testing\"\n)\n\nfunc TestCalculateSimple(t *testing.T) {\n\tt.Run(\"simple test\", func(t *testing.T) {\n\t\tduration := Calculate(\"https://d1hsxynlvbyrp1.cloudfront.net/videos/big_bunny/hls/index.m3u8\")\n\t\tfmt.Printf(\"duration: %v\\n\", duration)\n\t\tif duration != 62.280000 {\n\t\t\tt.Errorf(\"Calculate() = %v, want %v\", duration, 62.280000)\n\t\t}\n\t})\n}\n```\n\n## License\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbimlu%2Fhls-duration-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbimlu%2Fhls-duration-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbimlu%2Fhls-duration-go/lists"}