{"id":18031738,"url":"https://github.com/dagronf/swiftsubtitles","last_synced_at":"2025-04-06T18:17:03.982Z","repository":{"id":162730939,"uuid":"637225846","full_name":"dagronf/SwiftSubtitles","owner":"dagronf","description":"A Swift package for reading/writing subtitle formats (srt, sbv, sub, vtt, csv, lrc, podcast index)","archived":false,"fork":false,"pushed_at":"2024-12-19T00:39:56.000Z","size":1346,"stargazers_count":80,"open_issues_count":0,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T17:09:18.934Z","etag":null,"topics":["lyrics","subtitle","subtitles-parsing","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dagronf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-05-06T22:31:10.000Z","updated_at":"2025-03-30T01:37:38.000Z","dependencies_parsed_at":"2025-01-30T09:20:47.916Z","dependency_job_id":null,"html_url":"https://github.com/dagronf/SwiftSubtitles","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftSubtitles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftSubtitles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftSubtitles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftSubtitles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dagronf","download_url":"https://codeload.github.com/dagronf/SwiftSubtitles/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526768,"owners_count":20953143,"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":["lyrics","subtitle","subtitles-parsing","swift"],"created_at":"2024-10-30T10:10:36.699Z","updated_at":"2025-04-06T18:17:03.960Z","avatar_url":"https://github.com/dagronf.png","language":"Swift","funding_links":[],"categories":["Media Tools"],"sub_categories":["FFmpeg-Based Tools"],"readme":"# Swift Subtitles\n\nA Swift package for reading/writing some common subtitle formats.\n\n![tag](https://img.shields.io/github/v/tag/dagronf/SwiftSubtitles)\n![Swift](https://img.shields.io/badge/Swift-5.4-orange.svg)\n[![License MIT](https://img.shields.io/badge/license-MIT-magenta.svg)](https://github.com/dagronf/SwiftSubtitles/blob/master/LICENSE) \n![SPM](https://img.shields.io/badge/spm-compatible-maroon.svg)\n![Build](https://img.shields.io/github/actions/workflow/status/dagronf/SwiftSubtitles/swift.yml)\n\n![macOS](https://img.shields.io/badge/macOS-10.13+-darkblue)\n![iOS](https://img.shields.io/badge/iOS-12+-crimson)\n![tvOS](https://img.shields.io/badge/tvOS-12+-forestgreen)\n![watchOS](https://img.shields.io/badge/watchOS-6+-indigo)\n![macCatalyst](https://img.shields.io/badge/macCatalyst-2+-orangered)\n![Linux](https://img.shields.io/badge/Linux-compatible-peru)\n\n## Available coders\n\n| Format                | Coder                            | File extension  |\n|:----------------------|:---------------------------------|:----------------|\n| SBV (SubViewer)       | `Subtitles.Coder.SBV`            | `.sbv`          |\n| SUB (MicroDVD)*       | `Subtitles.Coder.SUB`            | `.sub`          |\n| SRT (SubRip)          | `Subtitles.Coder.SRT`            | `.srt`          |\n| VTT (WebVTT)          | `Subtitles.Coder.VTT`            | `.vtt`          |\n| CSV                   | `Subtitles.Coder.CSV`            | `.csv`          |\n| JSON (Podcasts Index) | `Subtitles.Coder.PodcastsIndex`  | `.json`         |\n| LRC (Lyrics file)     | `Subtitles.Coder.LRC`            | `.lrc`          |\n\n* Read-only\n\n## Basic usage\n\n### Decoding\n\nBasic decoding uses the file extension to determine the coder to use when decoding.\n\n```swift\nlet subtitles = try Subtitles(fileURL: \u003csome file url\u003e)\nsubtitles.cues.forEach { cue in\n\t// Do something with 'cue'\n}\n```\n\nYou can also instantiate a coder object and use that directly if you know the type of subtitles you'll be decoding\n\n```swift\nlet subtitleContent = ...\nlet coder = Subtitles.Coder.SBV()\nlet subtitles = try coder.decode(subtitleContent)\n...\nlet encodedContent = try coder.encode(subtitles: subtitles)\n``` \n\n### Encoding\n\n```swift\nlet cue1 = Subtitles.Cue(\n\tposition: 1,\n\tstartTime: Subtitles.Time(minute: 10),\n\tendTime: Subtitles.Time(minute: 11),\n\ttext: \"점점 더 많아지는\\n시민들의 성난 목소리로...\"\n)\n\nlet cue2 = Subtitles.Cue(\n\tposition: 2,\n\tstartTime: Subtitles.Time(minute: 13, second: 5),\n\tendTime: Subtitles.Time(minute: 15, second: 10, millisecond: 101),\n\ttext: \"Second entry\"\n)\n\nlet subtitles = Subtitles([cue1, cue2])\n\n// Encode based on the subtitle file extension\nlet content = try Subtitles.encode(subtitles, fileExtension: \"srt\")\n\n// Encode using an explicit coder\nlet coder = Subtitles.Coder.VTT()\nlet content2 = try coder.encode(subtitles: subtitles)\n```\n\n## Resources\n\n### Podcast Index Transcript\n\nFormat is documented [here](https://github.com/Podcastindex-org/podcast-namespace/blob/main/transcripts/transcripts.md#json)\n\n### Lyrics file format\n\nFormat is documented [here](https://en.wikipedia.org/wiki/LRC_(file_format))\n\nThe format defines the sub-second timing as 'hundredths of a second', however some online sample files use milliseconds\ninstead. This encoder supports both for decoding, and the encoder supports both formats when writing.\n\n```\n[00:12.41]Is it that sweet? I guess so\n[00:12.419]Is it that sweet? I guess so\n```\n\n### CSV coding/encoding\n\nThere appears to be no formal CSV specification for subtitles, so this coder tries to make a generic \"enough\" encoder/decoder to make it easier for an app to export into a spreadsheet or google docs.\n\n\u003cdetails\u003e\n\u003csummary\u003eClick here for more details on supported CSV formats\u003c/summary\u003e\n\nThe CSV must conform to [RFC 4180](https://www.rfc-editor.org/rfc/rfc4180.html)\n\n* Text that contains double-quotes must be double-double-quoted (eg. \"\u003e\u003e ALICE: My cat is named \"\"cat\"\" and is quite arrogant\")\n* Text containing newlines must be encapsulated in quotes. (eg. \"\u003e\u003e ALICE: What about you?\\n\u003e\u003e ROB: I don't have an opinion\")\n\nThis library uses [TinyCSV](https://github.com/dagronf/TinyCSV) for CSV coding/decoding.\n\nDuring decoding, the coder ignores the header if it exists, and assumes a particular ordering for the columns\n\nBy default, the encoder/decoder assumes a `\u003cposition\u003e, \u003cstart-time\u003e, \u003cend-time\u003e, \u003ctext\u003e` format, however this\ncan be configured in the coder's initializer.\n\n#### Time formats supported for decoding\n\n* SBV style: `00:00:00.000`\n* SRT style: `00:00:00,000`\n* Common style: `00:00:00:000`\n* milliseconds: `102727`\n\n#### Examples using common style text formats\n\n```\nNo.,Timecode In,Timecode Out,Subtitle\n1, 00:00:00:599, 00:00:04.160, \"\u003e\u003e ALICE: Hi, my name is Alice Miller and this is John Brown\"\n2, 00:00:04:160, 00:00:06.770, \"\u003e\u003e JOHN: and we're the owners of \"\"Miller Bakery\"\".\"\n```\n\n```\nPosition,Start time,End Time,Text\n51,00:00:00:599,00:00:04.160,\"\u003e\u003e ALICE: Hi, my name is Alice Miller and this is John Brown\"\n52,00:00:04:160,00:00:06.770,\"\u003e\u003e JOHN: and we're the owners of \"\"Miller Bakery\"\".\"\n```\n\n#### An example using millisecond durations and containing line feeds within the text\n\n```\n1, 91216, 93093, \"РегалВю ТЕЛЕМАРКЕТИНГ\nАНДЕРСЪН - МЕНИДЖЪР\"\n2, 102727, 104562, \"Тук пише, че 5 години сте бил\"\n3, 104646, 107232, \"мениджър на ресторант \"\"Ръсти Скапър\"\".\"\n```\n\n\u003c/details\u003e\n\n## Limitations\n\n* Some VTT functionality is not supported (NOTE, STYLE, REGION). These will be discarded on import. \n* Lyrics (LRC) file import discards ID tags.\n* Lyrics (LRC) file _export_ discards end times (LRC file format only supports start times)\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2024 Darren Ford\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fswiftsubtitles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdagronf%2Fswiftsubtitles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fswiftsubtitles/lists"}