-
Notifications
You must be signed in to change notification settings - Fork 2.2k
JSPatch %E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95
@implementation DKVideoWebViewController
-
(void)webViewDidEnterFullScreen:(NSNotification *)nofi { // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // NSString *html = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"]; // DKLog(@"%@",html); // });
DKWS; UIWindow *window = [UIApplication sharedApplication].windows.lastObject; window.rootViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
NSString *urlString = [self.webView stringByEvaluatingJavaScriptFromString:@"window.location.href"]; if([urlString isEqualToString:@"https://vimeo.com/"]){ return ; }else if([urlString containsString:@"http://ding.youku.com"]){ return; } __block BOOL saveFlag = NO; NSArray *btnTitles = @[Localized(@"Local cache"),Localized(@"Added to the playlist")]; if ([[DKFileManager sharedInstance] isExternalStorageConnected]) { // 连接了 OTG btnTitles = @[Localized(@"SpaceStation cache"),Localized(@"Local cache"),Localized(@"Added to the playlist")]; } UIAlertController *alert = [UIAlertView actionSheetWithTitle:nil message:nil btnTitles:btnTitles clickBtnAtIndex:^(NSString *actionTitle) { if([actionTitle isEqualToString:Localized(@"SpaceStation cache")]){ if ([[DKFileManager sharedInstance] isExternalStorageConnected]) { _storageType = DKFileStorageTypeExternal; }else{ OTGUnconnectedTip; } }else if([actionTitle isEqualToString:Localized(@"Local cache")]){ _storageType = DKFileStorageTypeInternal; }else { saveFlag = YES; }
if ([self.webSiteAddr isEqualToString:kYouku] || [self.webSiteAddr isEqualToString:kAiQiyi] || [self.webSiteAddr containsString:@"youku.com"] || [self.webSiteAddr containsString:@"iqiyi.com"]) { // 优酷 爱奇艺 抓本地 NSString *m3Url; NSString *cover; NSString *title; DKDownloadVideo *downloadVideo = [[DKDownloadVideo alloc] init]; if ([self.webSiteAddr isEqualToString:kYouku] || [self.webSiteAddr containsString:@"youku.com"]) { title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('x-title')[0].textContent"]; if(!title || title.length == 0){ title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]; } if(!title || title.length == 0){ title = [self.webView stringByEvaluatingJavaScriptFromString:@"unknown title"]; } cover = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('x-video-poster')[0].children[0].src"]; m3Url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('youku-html5player-video').src"]; if (DKDeviceiPad) { m3Url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('x-player').children[0].src"]; } }else if([self.webSiteAddr isEqualToString:kAiQiyi] || [self.webSiteAddr containsString:@"iqiyi.com"]){ title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]; cover = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('m-video-poster')[0].children[0].src"]; m3Url = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('video').src"]; } downloadVideo.urls = @[m3Url]; if(!m3Url || m3Url.length == 0){ [SVProgressHUD showErrorWithStatus:Localized(@"Address resolution failure")]; return ; } downloadVideo.title = title; downloadVideo.isM3U8 = YES; downloadVideo.logo = cover; downloadVideo.container = @"flv"; // M3U8下载后全转为flv downloadVideo.storageType = _storageType; if(saveFlag){ downloadVideo.national = YES; downloadVideo.sourceUrlStr = urlString; NSMutableArray *playList = DKKeyedUnArchive(kVideoPlayList); if (!playList) { playList = [NSMutableArray array]; } [playList addObject:downloadVideo]; DKKeyedArchive(kVideoPlayList, playList); [SVProgressHUD showSuccessWithStatus:Localized(@"Add to playlist successful")]; }else{ NSString *path = [DKDownloadVideo addToList:downloadVideo storageType:_storageType isM3U8:YES]; if (path) { _videoDownload = [[SCM3U8VideoDownload alloc] initWithVideoId:downloadVideo.title VideoUrl:downloadVideo.urls.firstObject storageType:_storageType]; [_videoDownload changeDownloadVideoState]; DKM3U8Downloader *downloader = [DKM3U8Downloader sharedInstance]; NSMutableArray *m3u8s = [NSMutableArray arrayWithArray:downloader.videos]; [m3u8s addObject:_videoDownload]; downloader.videos = m3u8s; } } return ; } [SVProgressHUD showWithStatus:Localized(@"Access to the video source")]; [DKVideoDownloadService downloadVideoWithWebsiteUrl:urlString isNational:weakSelf.isNational callBack:^(NSArray<DKDownloadVideo *> *downloadVideos) { if(downloadVideos){ if(saveFlag){ NSMutableArray *playList = DKKeyedUnArchive(kVideoPlayList); if (!playList) { playList = [NSMutableArray array]; } [DKVideoDownloadService videoUrlsWithWebsizeUrl:urlString isNational:self.isNational videoType:downloadVideos.firstObject.downloadKey callback:^(DKDownloadVideo *downloadVideo) { if(downloadVideo){ downloadVideo.sourceUrlStr = urlString; downloadVideo.national = NO; [playList addObject:downloadVideo]; DKKeyedArchive(kVideoPlayList, playList); [SVProgressHUD showSuccessWithStatus:Localized(@"Add to playlist successful")]; }else{ [SVProgressHUD showErrorWithStatus:Localized(@"Add to playlist failure")]; } }]; }else{ [SVProgressHUD dismiss]; NSMutableArray *dvs = [NSMutableArray arrayWithArray:downloadVideos]; for (NSInteger i = 0; i < downloadVideos.count; i++) { for (NSInteger j = i + 1; j < downloadVideos.count; j++) { if ([downloadVideos[i].quality isEqualToString:downloadVideos[j].quality]) { [dvs removeObject:downloadVideos[i]]; } } } NSArray *qualitys = [dvs fetchPropertys:@"quality"]; UIAlertController *alertC = [UIAlertView actionSheetWithTitle:nil message:nil btnTitles:qualitys clickBtnAtIndex:^(NSString *actionTitle) { [SVProgressHUD showWithStatus:Localized(@"Are joining the download queue")]; DKDownloadVideo *tempDv = dvs[[qualitys indexOfObject:actionTitle]]; DKLog(@"%@",tempDv.downloadKey); [DKVideoDownloadService videoUrlsWithWebsizeUrl:urlString isNational:self.isNational videoType:tempDv.downloadKey callback:^(DKDownloadVideo *downloadVideo) { if (downloadVideo) { // 添加到下载列表 NSString *path = [DKDownloadVideo addToList:downloadVideo storageType:_storageType isM3U8:NO]; if (path) { // 最大同时下载的线程数 [MJDownloadManager defaultManager].maxDownloadingCount = 50; // 加入下载的视频组字典 [[MJDownloadManager defaultManager].downloadVideosDic setObject:downloadVideo.urls forKey:downloadVideo.title]; if (downloadVideo.urls.count == 1) { [[MJDownloadManager defaultManager] download:downloadVideo.urls.firstObject toDestinationPath:[path.stringByDeletingLastPathComponent stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@",downloadVideo.title,downloadVideo.container]] progress:nil state:nil storageType:_storageType]; }else{ for (NSString *urlStr in downloadVideo.urls) { NSInteger index = [downloadVideo.urls indexOfObject:urlStr]; // 开始下载 [[MJDownloadManager defaultManager] download:urlStr toDestinationPath:[path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%zd.%@",downloadVideo.title,index,downloadVideo.container]] progress:nil state:nil storageType:_storageType]; } } } DKLog(@"%@",downloadVideo.urls); }else{ [SVProgressHUD showErrorWithStatus:Localized(@"Add failure")]; } }]; }]; id aController; if(DKDeviceiPad){ alertC.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *popPc = alertC.popoverPresentationController; popPc.barButtonItem = self.downloadItem; popPc.permittedArrowDirections = UIPopoverArrowDirectionAny; aController = alertC; }else{ aController = alertC; } dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)); dispatch_after(delayTime, dispatch_get_main_queue(), ^{ [window.rootViewController.presentedViewController presentViewController:aController animated:YES completion:nil]; });
// [window.rootViewController presentViewController:aController animated:YES completion:nil]; } }else{ [SVProgressHUD showErrorWithStatus:Localized(@"Failed to get the video source")]; } }];
}];
id controller;
if(DKDeviceiPad){
alert.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPc = alert.popoverPresentationController;
popPc.barButtonItem = self.downloadItem;
popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
controller = alert;
}else{
controller = alert;
}
dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
dispatch_after(delayTime, dispatch_get_main_queue(), ^{
[window.rootViewController.presentedViewController presentViewController:controller animated:YES completion:nil];
});
// [window.rootViewController presentViewController:controller animated:YES completion:nil];
// DKLog(@"%@",[self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].innerHTML"]); } @end