mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Fix #203
This commit is contained in:
@@ -4,7 +4,7 @@ import Foundation
|
||||
struct URLParser {
|
||||
static let prefixes: [Destination: [String]] = [
|
||||
.playlist: ["/playlist", "playlist"],
|
||||
.channel: ["/c", "c", "/channel", "channel"],
|
||||
.channel: ["/c", "c", "/channel", "channel", "/user", "user"],
|
||||
.search: ["/results", "search"]
|
||||
]
|
||||
|
||||
@@ -13,6 +13,21 @@ struct URLParser {
|
||||
case favorites, subscriptions, popular, trending
|
||||
}
|
||||
|
||||
var url: URL
|
||||
|
||||
init(url: URL) {
|
||||
self.url = url
|
||||
let urlString = url.absoluteString
|
||||
let scheme = urlComponents?.scheme
|
||||
if scheme == nil,
|
||||
urlString.contains("youtube.com"),
|
||||
let url = URL(string: "https://\(urlString)"
|
||||
)
|
||||
{
|
||||
self.url = url
|
||||
}
|
||||
}
|
||||
|
||||
var destination: Destination? {
|
||||
if hasAnyOfPrefixes(path, ["favorites"]) { return .favorites }
|
||||
if hasAnyOfPrefixes(path, ["subscriptions"]) { return .subscriptions }
|
||||
@@ -34,8 +49,6 @@ struct URLParser {
|
||||
return .video
|
||||
}
|
||||
|
||||
var url: URL
|
||||
|
||||
var videoID: String? {
|
||||
if host == "youtu.be", !path.isEmpty {
|
||||
return String(path.suffix(from: path.index(path.startIndex, offsetBy: 1)))
|
||||
@@ -85,6 +98,12 @@ struct URLParser {
|
||||
return removePrefixes(path, Self.prefixes[.channel]!.map { [$0, "/"].joined() })
|
||||
}
|
||||
|
||||
var username: String? {
|
||||
guard hasAnyOfPrefixes(path, ["user/", "/user/"]) else { return nil }
|
||||
|
||||
return removePrefixes(path, ["user/", "/user/"])
|
||||
}
|
||||
|
||||
private var host: String {
|
||||
urlComponents?.host ?? ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user