mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Various fixes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user