我开发了一个应用程序来加载用户的视频,当他们点击表格视图中的单元格时,它会转到另一个包含一堆不同信息的视图控制器。
我正在尝试从特定视频中提取实际的 YouTube 链接。我打印出我得到的链接,它们以这种形式出现。
https://www.youtube.com/v/Xf5pXlZJr1U?version=3&f=user_uploads&app=youtube_gdata
但我希望它是这种形式。
http://www.youtube.com/watch?v=Xf5pXlZJr1U
原因是我希望人们通过社交媒体分享链接,但是当它采用第一种格式时会显得很奇怪。
有什么方法可以轻松转换链接?
示例代码和答案编辑
GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
NSString *title = [[entry2 title] stringValue];
NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:contents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
NSString *tempURL = [flashContent URLString];
NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaThumbnails];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
UIImage *image = [UIImage imageWithData:data];
GDataYouTubeMediaGroup *mediaGroup = [(GDataEntryYouTubeVideo *)entry2 mediaGroup];
GDataMediaDescription *desc2 = [mediaGroup mediaDescription];
NSString *mystring = [desc2 stringValue];
NSArray *listItems = [tempURL componentsSeparatedByString:@"/"];
NSString *NewURL = @"";
NewURL = [NewURL stringByAppendingString:[listItems objectAtIndex:0]];
NewURL = [NewURL stringByAppendingString:@"//"];
NewURL = [NewURL stringByAppendingString:[listItems objectAtIndex:2]];
NewURL = [NewURL stringByAppendingString:@"/"];
NewURL = [NewURL stringByAppendingString:@"watch"];
NewURL = [NewURL stringByAppendingString:@"?v="];
NSArray *listItems2 = [[listItems objectAtIndex:4] componentsSeparatedByString:@"?"];
NewURL = [NewURL stringByAppendingString:[listItems2 objectAtIndex:0]];