Support for yt /c/channel-name URLs
This commit is contained in:
@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
// TODO: Make plugins extensible? community extensions.
|
// TODO: Make plugins extensible? community extensions.
|
||||||
@interface YouTubePlugin : NSObject
|
@interface YouTubePlugin : NSObject
|
||||||
+ (NSString*)feedURL:(NSURL*)url;
|
+ (NSString*)feedURL:(NSURL*)url data:(NSData*)html;
|
||||||
+ (NSString*)videoImage:(NSString*)videoid;
|
+ (NSString*)videoImage:(NSString*)videoid;
|
||||||
+ (NSString*)videoImageHQ:(NSString*)videoid;
|
+ (NSString*)videoImageHQ:(NSString*)videoid;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -33,12 +33,13 @@
|
|||||||
|
|
||||||
@return @c nil if @c url is not properly formatted, YouTube feed URL otherwise.
|
@return @c nil if @c url is not properly formatted, YouTube feed URL otherwise.
|
||||||
*/
|
*/
|
||||||
+ (NSString*)feedURL:(NSURL*)url {
|
+ (NSString*)feedURL:(NSURL*)url data:(NSData*)html {
|
||||||
if (![url.host hasSuffix:@"youtube.com"]) // 'youtu.be' & 'youtube-nocookie.com' will redirect
|
if (![url.host hasSuffix:@"youtube.com"]) // 'youtu.be' & 'youtube-nocookie.com' will redirect
|
||||||
return nil;
|
return nil;
|
||||||
// https://www.youtube.com/channel/[channel-id]
|
// https://www.youtube.com/channel/[channel-id]
|
||||||
// https://www.youtube.com/user/[user-name]
|
// https://www.youtube.com/user/[user-name]
|
||||||
// https://www.youtube.com/playlist?list=[playlist-id]
|
// https://www.youtube.com/playlist?list=[playlist-id]
|
||||||
|
// https://www.youtube.com/c/[channel-name]
|
||||||
#if DEBUG && ENV_LOG_YOUTUBE
|
#if DEBUG && ENV_LOG_YOUTUBE
|
||||||
printf("resolving YouTube url:\n");
|
printf("resolving YouTube url:\n");
|
||||||
printf(" ↳ %s\n", url.absoluteString.UTF8String);
|
printf(" ↳ %s\n", url.absoluteString.UTF8String);
|
||||||
@@ -62,6 +63,23 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if ([type isEqualToString:@"c"]) {
|
||||||
|
NSData *m_json = [@"\"channelId\":\"" dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
NSRange tmp = [html rangeOfData:m_json options:0 range:NSMakeRange(0, html.length)];
|
||||||
|
if (tmp.location == NSNotFound) {
|
||||||
|
NSData *m_head = [@"<meta itemprop=\"channelId\" content=\"" dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
tmp = [html rangeOfData:m_head options:0 range:NSMakeRange(0, html.length)];
|
||||||
|
}
|
||||||
|
NSUInteger start = tmp.location + tmp.length;
|
||||||
|
NSUInteger end = html.length - start;
|
||||||
|
if (end > 50) end = 50; // no need to search till the end
|
||||||
|
NSString *substr = [[NSString alloc] initWithData:[html subdataWithRange:NSMakeRange(start, end)] encoding:NSUTF8StringEncoding];
|
||||||
|
if (substr) {
|
||||||
|
NSUInteger to = [substr rangeOfString:@"\""].location;
|
||||||
|
if (to != NSNotFound) {
|
||||||
|
found = [ytBase stringByAppendingFormat:@"?channel_id=%@", [substr substringToIndex:to]];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if DEBUG && ENV_LOG_YOUTUBE
|
#if DEBUG && ENV_LOG_YOUTUBE
|
||||||
|
|||||||
@@ -178,7 +178,7 @@
|
|||||||
}
|
}
|
||||||
else if (!meta || meta.feedLinks.count == 0) {
|
else if (!meta || meta.feedLinks.count == 0) {
|
||||||
if ([xml.url.host hasSuffix:@"youtube.com"])
|
if ([xml.url.host hasSuffix:@"youtube.com"])
|
||||||
feedURL = [YouTubePlugin feedURL:xml.url];
|
feedURL = [YouTubePlugin feedURL:xml.url data:xml.data];
|
||||||
if (feedURL.length == 0)
|
if (feedURL.length == 0)
|
||||||
self.error = [NSError feedURLNotFound:xml.url];
|
self.error = [NSError feedURLNotFound:xml.url];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>14633</string>
|
<string>14642</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.news</string>
|
<string>public.app-category.news</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user