mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Fix parsing channel url
This commit is contained in:
@@ -43,12 +43,22 @@ struct URLParser {
|
||||
}
|
||||
|
||||
guard let id = videoID, !id.isEmpty else {
|
||||
if isYoutubeHost {
|
||||
return .channel
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return .video
|
||||
}
|
||||
|
||||
var isYoutubeHost: Bool {
|
||||
guard let urlComponents = urlComponents else { return false }
|
||||
|
||||
return urlComponents.host == "youtube.com" || urlComponents.host == "www.youtube.com"
|
||||
}
|
||||
|
||||
var videoID: String? {
|
||||
if host == "youtu.be", !path.isEmpty {
|
||||
return String(path.suffix(from: path.index(path.startIndex, offsetBy: 1)))
|
||||
@@ -88,7 +98,10 @@ struct URLParser {
|
||||
}
|
||||
|
||||
var channelName: String? {
|
||||
guard hasAnyOfPrefixes(path, ["c/", "/c/"]) else { return nil }
|
||||
guard hasAnyOfPrefixes(path, ["c/", "/c/"]) else {
|
||||
if isYoutubeHost { return pathWithoutForwardSlash }
|
||||
return nil
|
||||
}
|
||||
return removePrefixes(path, Self.prefixes[.channel]!.map { [$0, "/"].joined() })
|
||||
}
|
||||
|
||||
@@ -108,6 +121,12 @@ struct URLParser {
|
||||
urlComponents?.host ?? ""
|
||||
}
|
||||
|
||||
private var pathWithoutForwardSlash: String {
|
||||
guard let urlComponents = urlComponents else { return "" }
|
||||
|
||||
return String(urlComponents.path.dropFirst())
|
||||
}
|
||||
|
||||
private var path: String {
|
||||
removePrefixes(urlComponents?.path ?? "", ["www.youtube.com", "youtube.com"])
|
||||
}
|
||||
|
Reference in New Issue
Block a user