Various fixes

This commit is contained in:
Ilya Laktyushin
2022-09-21 02:13:36 +03:00
parent 37002ab90d
commit 74af8d17e1
22 changed files with 381 additions and 49 deletions

View File

@@ -1014,11 +1014,15 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
func setupItem(_ item: UniversalVideoGalleryItem) {
if self.item?.content.id != item.content.id {
func parseChapters(_ string: NSAttributedString) -> [MediaPlayerScrubbingChapter] {
var existingTimecodes = Set<Double>()
var timecodeRanges: [(NSRange, TelegramTimecode)] = []
var lineRanges: [NSRange] = []
string.enumerateAttributes(in: NSMakeRange(0, string.length), options: [], using: { attributes, range, _ in
if let timecode = attributes[NSAttributedString.Key(TelegramTextAttributes.Timecode)] as? TelegramTimecode {
timecodeRanges.append((range, timecode))
if !existingTimecodes.contains(timecode.time) {
timecodeRanges.append((range, timecode))
existingTimecodes.insert(timecode.time)
}
}
})
(string.string as NSString).enumerateSubstrings(in: NSMakeRange(0, string.length), options: .byLines, using: { _, range, _, _ in
@@ -1029,7 +1033,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
for (timecodeRange, timecode) in timecodeRanges {
inner: for lineRange in lineRanges {
if lineRange.contains(timecodeRange.location) {
if lineRange.length > timecodeRange.length {
if lineRange.length > timecodeRange.length && timecodeRange.location < lineRange.location + 4 {
var title = ((string.string as NSString).substring(with: lineRange) as NSString).replacingCharacters(in: NSMakeRange(timecodeRange.location - lineRange.location, timecodeRange.length), with: "")
title = title.trimmingCharacters(in: .whitespacesAndNewlines).trimmingCharacters(in: .punctuationCharacters)
chapters.append(MediaPlayerScrubbingChapter(title: title, start: timecode.time))
@@ -1038,6 +1042,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
}
}
}
return chapters
}