First commit for ChapterDB support.
This commit is contained in:
1 parent
fd2a6118df
commit
be1a335591
24 files changed
+1394
-230
No files matched your search
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SBMetadataHelper.h"
|
||||
|
||||
@class MP42Metadata;
|
||||
|
||||
@@ -17,17 +18,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
BOOL _isCancelled;
|
||||
}
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SBCachePolicy) {
|
||||
SBDefaultPolicy,
|
||||
SBReturnCacheElseLoad,
|
||||
SBReloadIgnoringLocalCacheData,
|
||||
};
|
||||
|
||||
#pragma mark Helper routines
|
||||
+ (NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename;
|
||||
+ (NSString *)urlEncoded:(NSString *)string;
|
||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy;
|
||||
|
||||
#pragma mark Class methods
|
||||
+ (NSArray<NSString *> *) movieProviders;
|
||||
+ (NSArray<NSString *> *) tvProviders;
|
||||
|
||||
@@ -13,13 +13,10 @@
|
||||
|
||||
#import "SBMetadataSearchController.h"
|
||||
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
#import "iTunesStore.h"
|
||||
#import "TheMovieDB3.h"
|
||||
#import "TheTVDB.h"
|
||||
|
||||
|
||||
@interface MetadataImporter ()
|
||||
|
||||
@property (atomic, readwrite) BOOL isCancelled;
|
||||
@@ -30,190 +27,6 @@
|
||||
|
||||
@synthesize isCancelled = _isCancelled;
|
||||
|
||||
#pragma mark Helper routines
|
||||
|
||||
+ (NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename
|
||||
{
|
||||
NSParameterAssert(filename);
|
||||
|
||||
NSMutableDictionary<NSString *, NSString *> *results = nil;
|
||||
|
||||
// Try with the usual anime filename
|
||||
__block NSDictionary<NSString *, NSString *> *resultDictionary = nil;
|
||||
|
||||
NSString *pattern = @"^\\[(.+)\\](?:(?:\\s|_)+)?([^()]+)(?:(?:\\s|_)+)(?:(?:-\\s|-_|Ep)+)([0-9]+)";
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
|
||||
[regex enumerateMatchesInString:filename
|
||||
options:0
|
||||
range:NSMakeRange(0, filename.length)
|
||||
usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop) {
|
||||
|
||||
resultDictionary = @{ @"fanSubGroup": [filename substringWithRange:[match rangeAtIndex:1]],
|
||||
@"seriesName": [filename substringWithRange:[match rangeAtIndex:2]],
|
||||
@"episodeNumber": [filename substringWithRange:[match rangeAtIndex:3]] };
|
||||
|
||||
}];
|
||||
|
||||
if (resultDictionary.count) {
|
||||
results = [[NSMutableDictionary alloc] init];
|
||||
NSString *seriesName = [resultDictionary[@"seriesName"] stringByReplacingOccurrencesOfString:@"_" withString:@" "];
|
||||
NSInteger episodeNumber = [resultDictionary[@"episodeNumber"] integerValue];
|
||||
|
||||
results[@"type"] = @"tv";
|
||||
results[@"seriesName"] = seriesName;
|
||||
results[@"seasonNum"] = @"1";
|
||||
results[@"episodeNum"] = [NSString stringWithFormat:@"%ld", (long)episodeNumber];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
// Else use the ParseFilename perl script
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
[task setLaunchPath:@"/usr/bin/perl"];
|
||||
|
||||
NSMutableArray<NSString *> *args = [[NSMutableArray alloc] initWithCapacity:3];
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"ParseFilename" ofType:@""];
|
||||
[args addObject:[NSString stringWithFormat:@"-I%@/lib", path]];
|
||||
[args addObject:[NSString stringWithFormat:@"%@/ParseFilename.pl", path]];
|
||||
[args addObject:filename];
|
||||
[task setArguments:args];
|
||||
|
||||
NSPipe *stdOut = [[NSPipe alloc] init];
|
||||
NSFileHandle *stdOutWrite = [stdOut fileHandleForWriting];
|
||||
[task setStandardOutput:stdOutWrite];
|
||||
|
||||
[task launch];
|
||||
[task waitUntilExit];
|
||||
[stdOutWrite closeFile];
|
||||
|
||||
NSData *outputData = [[stdOut fileHandleForReading] readDataToEndOfFile];
|
||||
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
|
||||
NSArray<NSString *> *lines = [outputString componentsSeparatedByString:@"\n"];
|
||||
|
||||
if (lines.count) {
|
||||
|
||||
if ([lines.firstObject isEqualToString:@"tv"]) {
|
||||
|
||||
if (lines.count >= 4) {
|
||||
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
||||
results[@"type"] = @"tv";
|
||||
|
||||
NSString *newSeriesName=[lines[1] stringByReplacingOccurrencesOfString:@"."
|
||||
withString:@" "];
|
||||
results[@"seriesName"] = newSeriesName;
|
||||
|
||||
if ([lines[2] integerValue]) {
|
||||
results[@"seasonNum"] = lines[2];
|
||||
}
|
||||
else {
|
||||
results[@"seasonNum"] = @"0";
|
||||
}
|
||||
|
||||
results[@"episodeNum"] = lines[3];
|
||||
}
|
||||
}
|
||||
else if ([lines.firstObject isEqualToString:@"movie"]) {
|
||||
|
||||
if (lines.count >= 2) {
|
||||
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||||
results[@"type"] = @"movie";
|
||||
|
||||
NSString *newTitle=[lines[1] stringByReplacingOccurrencesOfString:@"."
|
||||
withString:@" "];
|
||||
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"(" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@")" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"[" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"]" withString:@" "];
|
||||
newTitle = [newTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
results[@"title"] = newTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[outputString release];
|
||||
[stdOut release];
|
||||
[args release];
|
||||
[task release];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
+ (NSString *)urlEncoded:(NSString *)string {
|
||||
string = [string precomposedStringWithCompatibilityMapping];
|
||||
CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(
|
||||
NULL,
|
||||
(CFStringRef) string,
|
||||
NULL,
|
||||
(CFStringRef) @"!*'\"();:@&=+$,/?%#[]% ",
|
||||
kCFStringEncodingUTF8);
|
||||
return [(NSString *)urlString autorelease];
|
||||
}
|
||||
|
||||
+ (NSString *)md5String:(NSString *)s {
|
||||
const char *cStr = s.UTF8String;
|
||||
unsigned char result[CC_MD5_DIGEST_LENGTH];
|
||||
CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
|
||||
NSMutableString *r = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; ++i) {
|
||||
[r appendFormat:@"%02x", result[i]];
|
||||
}
|
||||
return [NSString stringWithString:r];
|
||||
}
|
||||
|
||||
+ (NSString *)sha256String:(NSString *)s {
|
||||
const char *cStr = s.UTF8String;
|
||||
unsigned char result[CC_SHA256_DIGEST_LENGTH];
|
||||
CC_SHA256(cStr, (CC_LONG)strlen(cStr), result);
|
||||
NSMutableString *r = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
|
||||
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; ++i) {
|
||||
[r appendFormat:@"%02x", result[i]];
|
||||
}
|
||||
return [NSString stringWithString:r];
|
||||
}
|
||||
|
||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy error:(NSError **)error {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
|
||||
NSURL *cacheURL = [[[fileManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask]
|
||||
firstObject] URLByAppendingPathComponent:bundleName];
|
||||
|
||||
|
||||
NSURL *fileURL = [cacheURL URLByAppendingPathComponent:[MetadataImporter sha256String:url.absoluteString]];
|
||||
fileURL = [fileURL URLByAppendingPathExtension:url.pathExtension];
|
||||
|
||||
if (policy != SBReloadIgnoringLocalCacheData) {
|
||||
NSDictionary<NSString *, id> *attrs = [fileURL resourceValuesForKeys:@[NSURLCreationDateKey] error:NULL];
|
||||
NSDate *creationDate = attrs[NSURLCreationDateKey];
|
||||
|
||||
if (creationDate) {
|
||||
NSTimeInterval oldness = creationDate.timeIntervalSinceNow;
|
||||
|
||||
// if less than 2 hours old or jpg
|
||||
if ([url.pathExtension caseInsensitiveCompare:@"jpg"] == NSOrderedSame ||
|
||||
(oldness > -60 * 60 * 2) ||
|
||||
policy == SBReturnCacheElseLoad) {
|
||||
return [NSData dataWithContentsOfURL:fileURL options:0 error:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSData *downloadedData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:error];
|
||||
[downloadedData writeToURL:fileURL atomically:YES];
|
||||
|
||||
return downloadedData;
|
||||
}
|
||||
|
||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy {
|
||||
return [MetadataImporter downloadDataFromURL:url withCachePolicy:policy error:NULL];
|
||||
}
|
||||
|
||||
#pragma mark Class methods
|
||||
|
||||
+ (NSArray<NSString *> *)movieProviders {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// SBChapterDB.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 25/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SBChapterImporter.h"
|
||||
|
||||
@interface SBChapterDB : SBChapterImporter
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// SBChapterDB.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 25/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBChapterDB.h"
|
||||
#import "SBChapterResult.h"
|
||||
|
||||
#import <MP42Foundation/MP42ChapterTrack.h>
|
||||
|
||||
#define API_KEY @"ETET7TXFJH45YNYW0I4A"
|
||||
|
||||
@implementation SBChapterDB
|
||||
|
||||
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)aTitle duration:(NSUInteger)duration
|
||||
{
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.chapterdb.org/chapters/search?title=%@", [SBMetadataHelper urlEncoded:aTitle]]];
|
||||
|
||||
NSDictionary *headerOptions = @{@"ApiKey" : API_KEY};
|
||||
NSData *xmlData = xmlData = [SBMetadataHelper dataFromUrl:url withHTTPMethod:@"GET" headerOptions:headerOptions error:nil];
|
||||
|
||||
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData
|
||||
options:0
|
||||
error:nil];
|
||||
|
||||
NSMutableArray<SBChapterResult *> *resultsArray = [[[NSMutableArray alloc] init] autorelease];
|
||||
|
||||
if (xml) {
|
||||
NSArray<NSXMLNode *> *children = [xml nodesForXPath:@"//*:chapterInfo" error:nil];
|
||||
|
||||
for (NSXMLNode *child in children) {
|
||||
SBChapterResult *result = [self parseResult:child];
|
||||
if (result) {
|
||||
[resultsArray addObject:result];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[xml release];
|
||||
|
||||
if (duration > 0) {
|
||||
NSArray<SBChapterResult *> *filteredArray = [self filterArray:resultsArray byDuration:duration delta:10000];
|
||||
if (filteredArray.count) {
|
||||
return filteredArray;
|
||||
}
|
||||
}
|
||||
|
||||
return resultsArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the results by the duration plus/minus a delta time
|
||||
*
|
||||
* @param array the array of SBChapterResult
|
||||
* @param duration the movie duration
|
||||
* @param delta the delta in ms
|
||||
*
|
||||
* @return the filtered array.
|
||||
*/
|
||||
- (NSArray<SBChapterResult *> *)filterArray:(NSArray *)array byDuration:(NSUInteger)duration delta:(NSUInteger)delta
|
||||
{
|
||||
NSMutableArray<SBChapterResult *> *filteredArray = [NSMutableArray array];
|
||||
|
||||
for (SBChapterResult *result in array) {
|
||||
if (result.duration < (duration + delta) && result.duration > (duration - delta)) {
|
||||
[filteredArray addObject:result];
|
||||
}
|
||||
}
|
||||
|
||||
return filteredArray;
|
||||
}
|
||||
|
||||
#pragma mark - Result convertion
|
||||
|
||||
- (NSString *)titleForNode:(NSXMLNode *)node
|
||||
{
|
||||
NSArray<NSXMLNode *> *tag = [node nodesForXPath:@"./*:title" error:NULL];
|
||||
return tag.firstObject.stringValue;
|
||||
}
|
||||
|
||||
- (NSUInteger)confirmationsForNode:(NSXMLNode *)node
|
||||
{
|
||||
NSArray<NSXMLNode *> *tag = [node nodesForXPath:@"./@confirmations" error:NULL];
|
||||
return tag.firstObject.stringValue.integerValue;
|
||||
}
|
||||
|
||||
- (NSUInteger)durationForNode:(NSXMLNode *)node
|
||||
{
|
||||
NSArray<NSXMLNode *> *tag = [node nodesForXPath:@"./*:source/*:duration" error:NULL];
|
||||
NSString *durationString = tag.firstObject.stringValue;
|
||||
if (durationString) {
|
||||
return ParseSubTime(durationString.UTF8String, 1000, NO);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (SBChapterResult *)parseResult:(NSXMLNode *)child
|
||||
{
|
||||
NSMutableArray<MP42TextSample *> *chapters = [NSMutableArray array];
|
||||
|
||||
NSString *title = [self titleForNode:child];
|
||||
NSUInteger confirmations = [self confirmationsForNode:child];
|
||||
NSUInteger duration = [self durationForNode:child];
|
||||
|
||||
NSArray<NSXMLNode *> *times = [child nodesForXPath:@"./*:chapters/*:chapter/@time" error:NULL];
|
||||
NSArray<NSXMLNode *> *names = [child nodesForXPath:@"./*:chapters/*:chapter/@name" error:NULL];
|
||||
|
||||
if (times && names) {
|
||||
|
||||
for (NSInteger i = 0; i < times.count && i < names.count; i++) {
|
||||
|
||||
NSString *name = names[i].stringValue;
|
||||
NSString *timestamp = times[i].stringValue;
|
||||
|
||||
if (name && timestamp) {
|
||||
unsigned time = ParseSubTime(timestamp.UTF8String, 1000, NO);
|
||||
|
||||
MP42TextSample *chapter = [[MP42TextSample alloc] init];
|
||||
chapter.title = name;
|
||||
chapter.timestamp = time;
|
||||
|
||||
[chapters addObject:chapter];
|
||||
[chapter release];
|
||||
}
|
||||
}
|
||||
|
||||
SBChapterResult *result = [[SBChapterResult alloc] initWithTitle:title
|
||||
duration:duration
|
||||
confirmations:confirmations
|
||||
chapters:chapters];
|
||||
|
||||
return [result autorelease];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// SBChapterImporter.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Michael Hueber on 21.11.15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SBMetadataHelper.h"
|
||||
|
||||
@class SBChapterResult;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SBChapterImporter : NSObject {
|
||||
@private
|
||||
BOOL _isCancelled;
|
||||
}
|
||||
|
||||
+ (NSString *)defaultProvider;
|
||||
|
||||
+ (instancetype)importerForProvider:(NSString *)aProviderName;
|
||||
- (void) searchTitle:(NSString *)title duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> * _Nullable results))handler;
|
||||
- (void) cancel;
|
||||
|
||||
#pragma mark Methods to be overridden
|
||||
|
||||
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)title duration:(NSUInteger)duration;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// SBChapterImporter.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Michael Hueber on 21.11.15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBChapterImporter.h"
|
||||
#import <MP42Foundation/MP42ChapterTrack.h>
|
||||
|
||||
#import "SBChapterDB.h"
|
||||
|
||||
@interface SBChapterImporter ()
|
||||
|
||||
@property (atomic, readwrite) BOOL isCancelled;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBChapterImporter
|
||||
|
||||
@synthesize isCancelled = _isCancelled;
|
||||
|
||||
+ (NSString *)defaultProvider
|
||||
{
|
||||
return @"ChapterDB";
|
||||
}
|
||||
|
||||
+ (instancetype)importerForProvider:(NSString *)aProvider
|
||||
{
|
||||
if ([aProvider isEqualToString:@"ChapterDB"]) {
|
||||
return [[[SBChapterDB alloc] init] autorelease];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)searchTitle:(NSString *)title duration:(NSUInteger)duration completionHandler:(void(^)(NSArray<SBChapterResult *> * _Nullable results))handler
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
NSArray *results = [self searchTitle:title duration:duration];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.isCancelled) {
|
||||
handler(results);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
- (void)cancel
|
||||
{
|
||||
self.isCancelled = YES;
|
||||
}
|
||||
|
||||
- (NSArray<SBChapterResult *> *)searchTitle:(NSString *)title duration:(NSUInteger)duration
|
||||
{
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// SBChapterResult.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 25/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class MP42TextSample;
|
||||
|
||||
@interface SBChapterResult : NSObject {
|
||||
@private
|
||||
NSString *_title;
|
||||
NSUInteger _duration;
|
||||
NSUInteger _confirmations;
|
||||
|
||||
NSArray<MP42TextSample *> *_chapters;
|
||||
}
|
||||
|
||||
- (instancetype)initWithTitle:(NSString *)title duration:(NSUInteger)duration confirmations:(NSUInteger)confirmations chapters:(NSArray<MP42TextSample *> *)chapters;
|
||||
|
||||
@property (nonatomic, readonly) NSString *title;
|
||||
@property (nonatomic, readonly) NSUInteger duration;
|
||||
@property (nonatomic, readonly) NSUInteger confirmations;
|
||||
|
||||
@property (nonatomic, readonly) NSArray<MP42TextSample *> *chapters;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// SBChapterResult.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 25/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBChapterResult.h"
|
||||
|
||||
@implementation SBChapterResult
|
||||
|
||||
@synthesize title = _title;
|
||||
@synthesize duration = _duration;
|
||||
@synthesize confirmations = _confirmations;
|
||||
|
||||
@synthesize chapters = _chapters;
|
||||
|
||||
- (instancetype)initWithTitle:(NSString *)title duration:(NSUInteger)duration confirmations:(NSUInteger)confirmations chapters:(NSArray<MP42TextSample *> *)chapters
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_title = [title copy];
|
||||
_duration = duration;
|
||||
_confirmations = confirmations;
|
||||
_chapters = [chapters copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// SBMetadataHelper.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 25/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SBMetadataHelper : NSObject
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SBCachePolicy) {
|
||||
SBDefaultPolicy,
|
||||
SBReturnCacheElseLoad,
|
||||
SBReloadIgnoringLocalCacheData,
|
||||
};
|
||||
|
||||
#pragma mark Helper routines
|
||||
+ (NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename;
|
||||
+ (NSString *)urlEncoded:(NSString *)string;
|
||||
|
||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy;
|
||||
+ (nullable NSData *)dataFromUrl:(NSURL *)url withHTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header error:(NSError **)outError;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,230 @@
|
||||
//
|
||||
// SBMetadataHelper.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Damiano Galassi on 25/11/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBMetadataHelper.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@implementation SBMetadataHelper
|
||||
|
||||
+ (NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename
|
||||
{
|
||||
NSParameterAssert(filename);
|
||||
|
||||
NSMutableDictionary<NSString *, NSString *> *results = nil;
|
||||
|
||||
// Try with the usual anime filename
|
||||
__block NSDictionary<NSString *, NSString *> *resultDictionary = nil;
|
||||
|
||||
NSString *pattern = @"^\\[(.+)\\](?:(?:\\s|_)+)?([^()]+)(?:(?:\\s|_)+)(?:(?:-\\s|-_|Ep)+)([0-9]+)";
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
|
||||
[regex enumerateMatchesInString:filename
|
||||
options:0
|
||||
range:NSMakeRange(0, filename.length)
|
||||
usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop) {
|
||||
|
||||
resultDictionary = @{ @"fanSubGroup": [filename substringWithRange:[match rangeAtIndex:1]],
|
||||
@"seriesName": [filename substringWithRange:[match rangeAtIndex:2]],
|
||||
@"episodeNumber": [filename substringWithRange:[match rangeAtIndex:3]] };
|
||||
|
||||
}];
|
||||
|
||||
if (resultDictionary.count) {
|
||||
results = [[NSMutableDictionary alloc] init];
|
||||
NSString *seriesName = [resultDictionary[@"seriesName"] stringByReplacingOccurrencesOfString:@"_" withString:@" "];
|
||||
NSInteger episodeNumber = [resultDictionary[@"episodeNumber"] integerValue];
|
||||
|
||||
results[@"type"] = @"tv";
|
||||
results[@"seriesName"] = seriesName;
|
||||
results[@"seasonNum"] = @"1";
|
||||
results[@"episodeNum"] = [NSString stringWithFormat:@"%ld", (long)episodeNumber];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
// Else use the ParseFilename perl script
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
[task setLaunchPath:@"/usr/bin/perl"];
|
||||
|
||||
NSMutableArray<NSString *> *args = [[NSMutableArray alloc] initWithCapacity:3];
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"ParseFilename" ofType:@""];
|
||||
[args addObject:[NSString stringWithFormat:@"-I%@/lib", path]];
|
||||
[args addObject:[NSString stringWithFormat:@"%@/ParseFilename.pl", path]];
|
||||
[args addObject:filename];
|
||||
[task setArguments:args];
|
||||
|
||||
NSPipe *stdOut = [[NSPipe alloc] init];
|
||||
NSFileHandle *stdOutWrite = [stdOut fileHandleForWriting];
|
||||
[task setStandardOutput:stdOutWrite];
|
||||
|
||||
[task launch];
|
||||
[task waitUntilExit];
|
||||
[stdOutWrite closeFile];
|
||||
|
||||
NSData *outputData = [[stdOut fileHandleForReading] readDataToEndOfFile];
|
||||
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
|
||||
NSArray<NSString *> *lines = [outputString componentsSeparatedByString:@"\n"];
|
||||
|
||||
if (lines.count) {
|
||||
|
||||
if ([lines.firstObject isEqualToString:@"tv"]) {
|
||||
|
||||
if (lines.count >= 4) {
|
||||
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:4];
|
||||
results[@"type"] = @"tv";
|
||||
|
||||
NSString *newSeriesName=[lines[1] stringByReplacingOccurrencesOfString:@"."
|
||||
withString:@" "];
|
||||
results[@"seriesName"] = newSeriesName;
|
||||
|
||||
if ([lines[2] integerValue]) {
|
||||
results[@"seasonNum"] = lines[2];
|
||||
}
|
||||
else {
|
||||
results[@"seasonNum"] = @"0";
|
||||
}
|
||||
|
||||
results[@"episodeNum"] = lines[3];
|
||||
}
|
||||
}
|
||||
else if ([lines.firstObject isEqualToString:@"movie"]) {
|
||||
|
||||
if (lines.count >= 2) {
|
||||
|
||||
results = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||||
results[@"type"] = @"movie";
|
||||
|
||||
NSString *newTitle=[lines[1] stringByReplacingOccurrencesOfString:@"."
|
||||
withString:@" "];
|
||||
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"(" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@")" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"[" withString:@" "];
|
||||
newTitle = [newTitle stringByReplacingOccurrencesOfString:@"]" withString:@" "];
|
||||
newTitle = [newTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
results[@"title"] = newTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[outputString release];
|
||||
[stdOut release];
|
||||
[args release];
|
||||
[task release];
|
||||
|
||||
return [results autorelease];
|
||||
}
|
||||
|
||||
+ (NSString *)urlEncoded:(NSString *)string {
|
||||
string = [string precomposedStringWithCompatibilityMapping];
|
||||
CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(
|
||||
NULL,
|
||||
(CFStringRef) string,
|
||||
NULL,
|
||||
(CFStringRef) @"!*'\"();:@&=+$,/?%#[]% ",
|
||||
kCFStringEncodingUTF8);
|
||||
return [(NSString *)urlString autorelease];
|
||||
}
|
||||
|
||||
+ (NSString *)md5String:(NSString *)s {
|
||||
const char *cStr = s.UTF8String;
|
||||
unsigned char result[CC_MD5_DIGEST_LENGTH];
|
||||
CC_MD5(cStr, (CC_LONG)strlen(cStr), result);
|
||||
NSMutableString *r = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
||||
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; ++i) {
|
||||
[r appendFormat:@"%02x", result[i]];
|
||||
}
|
||||
return [NSString stringWithString:r];
|
||||
}
|
||||
|
||||
+ (NSString *)sha256String:(NSString *)s {
|
||||
const char *cStr = s.UTF8String;
|
||||
unsigned char result[CC_SHA256_DIGEST_LENGTH];
|
||||
CC_SHA256(cStr, (CC_LONG)strlen(cStr), result);
|
||||
NSMutableString *r = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
|
||||
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; ++i) {
|
||||
[r appendFormat:@"%02x", result[i]];
|
||||
}
|
||||
return [NSString stringWithString:r];
|
||||
}
|
||||
|
||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy error:(NSError **)error {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
|
||||
NSURL *cacheURL = [[[fileManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask]
|
||||
firstObject] URLByAppendingPathComponent:bundleName];
|
||||
|
||||
|
||||
NSURL *fileURL = [cacheURL URLByAppendingPathComponent:[SBMetadataHelper sha256String:url.absoluteString]];
|
||||
fileURL = [fileURL URLByAppendingPathExtension:url.pathExtension];
|
||||
|
||||
if (policy != SBReloadIgnoringLocalCacheData) {
|
||||
NSDictionary<NSString *, id> *attrs = [fileURL resourceValuesForKeys:@[NSURLCreationDateKey] error:NULL];
|
||||
NSDate *creationDate = attrs[NSURLCreationDateKey];
|
||||
|
||||
if (creationDate) {
|
||||
NSTimeInterval oldness = creationDate.timeIntervalSinceNow;
|
||||
|
||||
// if less than 2 hours old or jpg
|
||||
if ([url.pathExtension caseInsensitiveCompare:@"jpg"] == NSOrderedSame ||
|
||||
(oldness > -60 * 60 * 2) ||
|
||||
policy == SBReturnCacheElseLoad) {
|
||||
return [NSData dataWithContentsOfURL:fileURL options:0 error:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSData *downloadedData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:error];
|
||||
[downloadedData writeToURL:fileURL atomically:YES];
|
||||
|
||||
return downloadedData;
|
||||
}
|
||||
|
||||
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy {
|
||||
return [SBMetadataHelper downloadDataFromURL:url withCachePolicy:policy error:NULL];
|
||||
}
|
||||
|
||||
#pragma mark NSURLRequest
|
||||
+ (nullable NSData *)dataFromUrl:(NSURL *)url withHTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header error:(NSError **)outError
|
||||
{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
|
||||
cachePolicy:NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval:30.0];
|
||||
[request setHTTPMethod:method];
|
||||
|
||||
if (header) {
|
||||
for (NSString *key in header.allKeys) {
|
||||
[request addValue:header[key] forHTTPHeaderField:key];
|
||||
}
|
||||
}
|
||||
|
||||
NSURLResponse *response = nil;
|
||||
NSError *error = nil;
|
||||
NSData *data = [NSURLConnection sendSynchronousRequest:request
|
||||
returningResponse:&response
|
||||
error:&error];
|
||||
|
||||
if (data) {
|
||||
NSUInteger statusCode = 0;
|
||||
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
|
||||
statusCode = (long)[(NSHTTPURLResponse *)response statusCode];
|
||||
}
|
||||
|
||||
if (statusCode == 200) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
- (NSArray *) searchMovie:(NSString *)aMovieTitle language:(NSString *)aLanguage {
|
||||
NSString *lang = [MP42Languages iso6391CodeFor:aLanguage];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/search/movie?api_key=%@&query=%@&language=%@", API_KEY, [MetadataImporter urlEncoded:aMovieTitle], lang]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/search/movie?api_key=%@&query=%@&language=%@", API_KEY, [SBMetadataHelper urlEncoded:aMovieTitle], lang]];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
// load image variables from configuration
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/configuration?api_key=%@", API_KEY]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSArray *posters = [r valueForKeyPath:@"images.posters"];
|
||||
|
||||
if (jsonData && posters && [posters isKindOfClass:[NSArray class]]) {
|
||||
@@ -99,7 +99,7 @@
|
||||
NSString *lang = [MP42Languages iso6391CodeFor:aLanguage];
|
||||
NSNumber *theMovieDBID = [[aMetadata tagsDict] valueForKey:@"TheMovieDB ID"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@?api_key=%@&language=%@&append_to_response=casts,releases,images", theMovieDBID, API_KEY, lang]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
|
||||
@@ -24,7 +24,7 @@ static NSArray *TVDBlanguages;
|
||||
+ (void)initialize {
|
||||
if (self == [TheTVDB class]) {
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/%@/languages.xml", API_KEY]];
|
||||
NSData *languagesXML = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBReturnCacheElseLoad];
|
||||
NSData *languagesXML = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBReturnCacheElseLoad];
|
||||
NSDictionary *languages = [XMLReader dictionaryForXMLData:languagesXML error:NULL];
|
||||
|
||||
if (languages) {
|
||||
@@ -53,8 +53,8 @@ static NSArray *TVDBlanguages;
|
||||
- (NSArray *) searchTVSeries:(NSString *)aSeriesName language:(NSString *)aLanguage {
|
||||
NSURL *url;
|
||||
// search for series
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/GetSeries.php?seriesname=%@&language=all", [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
NSData *seriesXML = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/GetSeries.php?seriesname=%@&language=all", [SBMetadataHelper urlEncoded:aSeriesName]]];
|
||||
NSData *seriesXML = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSDictionary *series = [XMLReader dictionaryForXMLData:seriesXML error:NULL];
|
||||
if (!series) return nil;
|
||||
NSArray *seriesArray = [series retrieveArrayForPath:@"Data.Series"];
|
||||
@@ -71,8 +71,8 @@ static NSArray *TVDBlanguages;
|
||||
NSURL *url;
|
||||
|
||||
// search for series
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/GetSeries.php?seriesname=%@&language=all", [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
NSData *seriesXML = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/GetSeries.php?seriesname=%@&language=all", [SBMetadataHelper urlEncoded:aSeriesName]]];
|
||||
NSData *seriesXML = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSDictionary *series = [XMLReader dictionaryForXMLData:seriesXML error:NULL];
|
||||
|
||||
if (!series) return nil;
|
||||
@@ -102,7 +102,7 @@ static NSArray *TVDBlanguages;
|
||||
continue;
|
||||
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/%@/series/%@/all/%@.xml", API_KEY, seriesID, lang]];
|
||||
NSData *episodesXML = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *episodesXML = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSDictionary *episodes = [XMLReader dictionaryForXMLData:episodesXML error:NULL];
|
||||
|
||||
if (!episodes)
|
||||
@@ -150,7 +150,7 @@ static NSArray *TVDBlanguages;
|
||||
[newArtworkProviderNames addObjectsFromArray:[aMetadata artworkProviderNames]];
|
||||
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://thetvdb.com/api/%@/series/%@/banners.xml", API_KEY, [[aMetadata tagsDict] valueForKey:@"TheTVDB Series ID"]]];
|
||||
NSData *bannersXML = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *bannersXML = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSDictionary *banners = [XMLReader dictionaryForXMLData:bannersXML error:NULL];
|
||||
if (!banners) return nil;
|
||||
NSArray *bannersArray = [banners retrieveArrayForPath:@"Banners.Banner"];
|
||||
|
||||
@@ -127,11 +127,11 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
|
||||
NSURL *url;
|
||||
if (aSeasonNum && [aSeasonNum length]) {
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=tvSeasonTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [MetadataImporter urlEncoded:[NSString stringWithFormat:@"%@ %@ %@", aSeriesName, season, aSeasonNum]]]];
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=tvSeasonTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [SBMetadataHelper urlEncoded:[NSString stringWithFormat:@"%@ %@ %@", aSeriesName, season, aSeasonNum]]]];
|
||||
} else {
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=showTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [MetadataImporter urlEncoded:aSeriesName]]];
|
||||
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&attribute=showTerm&entity=tvEpisode&limit=200", country, [language lowercaseString], [SBMetadataHelper urlEncoded:aSeriesName]]];
|
||||
}
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
@@ -169,8 +169,8 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
}
|
||||
NSString *country = [store valueForKey:@"country2"];
|
||||
NSString *language = [store valueForKey:@"language2"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=tvEpisode", country, [language lowercaseString], [MetadataImporter urlEncoded:[NSString stringWithFormat:@"%@ %@", aSeriesName, aEpisodeTitle]]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=tvEpisode", country, [language lowercaseString], [SBMetadataHelper urlEncoded:[NSString stringWithFormat:@"%@ %@", aSeriesName, aEpisodeTitle]]]];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
@@ -188,8 +188,8 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
}
|
||||
NSString *country = [store valueForKey:@"country2"];
|
||||
NSString *language = [store valueForKey:@"language2"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie", country, language, [MetadataImporter urlEncoded:aMovieName]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie", country, language, [SBMetadataHelper urlEncoded:aMovieName]]];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
@@ -212,8 +212,8 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
language = [store valueForKey:@"language2"];
|
||||
}
|
||||
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie&limit=150", country, language, [MetadataImporter urlEncoded:aMovieTitle]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/search?country=%@&lang=%@&term=%@&entity=movie&limit=150", country, language, [SBMetadataHelper urlEncoded:aMovieTitle]]];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
@@ -233,7 +233,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
NSString *country = [store valueForKey:@"country2"];
|
||||
NSString *language = [store valueForKey:@"language2"];
|
||||
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?country=%@&lang=%@&id=%@", country, [language lowercaseString], [[aMetadata tagsDict] valueForKey:@"playlistID"]]];
|
||||
NSData *jsonData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *jsonData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (jsonData) {
|
||||
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
if ([d isKindOfClass:[NSDictionary class]]) {
|
||||
@@ -248,7 +248,7 @@ NSInteger sortMP42Metadata(id ep1, id ep2, void *context)
|
||||
}
|
||||
|
||||
- (MP42Metadata *) loadMovieMetadata:(MP42Metadata *)aMetadata language:(NSString *)aLanguage {
|
||||
NSData *xmlData = [MetadataImporter downloadDataFromURL:[NSURL URLWithString:[[aMetadata tagsDict] valueForKey:@"iTunes URL"]] withCachePolicy:SBDefaultPolicy];
|
||||
NSData *xmlData = [SBMetadataHelper downloadDataFromURL:[NSURL URLWithString:[[aMetadata tagsDict] valueForKey:@"iTunes URL"]] withCachePolicy:SBDefaultPolicy];
|
||||
if (xmlData) {
|
||||
NSDictionary *store = [iTunesStore getStoreFor:aLanguage];
|
||||
NSXMLDocument *xml = [[NSXMLDocument alloc] initWithData:xmlData options:NSXMLDocumentTidyHTML error:NULL];
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
#import "SBArtworkSelector.h"
|
||||
#import "MetadataImporter.h"
|
||||
#import "SBMetadataHelper.h"
|
||||
|
||||
#pragma mark IKImageBrowserItem data source objects
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
// Get the data outside the main thread
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
if (!self.isCancelled) {
|
||||
self.data = [MetadataImporter downloadDataFromURL:_url withCachePolicy:SBDefaultPolicy];
|
||||
self.data = [SBMetadataHelper downloadDataFromURL:_url withCachePolicy:SBDefaultPolicy];
|
||||
self.version = 2;
|
||||
// We got the data, tell the controller to update the view
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// SBChapterSearchController.h
|
||||
// Subler
|
||||
//
|
||||
// Created by Michael Hueber on 20.11.15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <MP42Foundation/MP42TextSample.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SBTableView;
|
||||
@class SBChapterResult;
|
||||
@class SBChapterImporter;
|
||||
|
||||
@protocol SBChapterSearchControllerDelegate
|
||||
|
||||
- (void)chapterImportDone:(NSArray<MP42TextSample *> *)chaptersToBeImported;
|
||||
|
||||
@end
|
||||
|
||||
@interface SBChapterSearchController : NSWindowController {
|
||||
@private
|
||||
id <SBChapterSearchControllerDelegate> delegate;
|
||||
|
||||
NSString *_searchString;
|
||||
NSUInteger _searchDuration;
|
||||
|
||||
NSDictionary *_detailBoldAttr;
|
||||
NSDictionary *_detailBoldMonospacedAttr;
|
||||
NSDictionary *_detailMonospacedAttr;
|
||||
|
||||
IBOutlet NSTextField *searchTitle;
|
||||
IBOutlet NSTextField *searchDuration;
|
||||
|
||||
NSArray<SBChapterResult *> *_resultsArray;
|
||||
IBOutlet NSTableView *resultsTable;
|
||||
NSArray *_selectedChaptersArray;
|
||||
IBOutlet SBTableView *chapterTable;
|
||||
|
||||
|
||||
IBOutlet NSButton *searchButton;
|
||||
IBOutlet NSButton *addButton;
|
||||
|
||||
SBChapterImporter *_currentSearcher;
|
||||
|
||||
IBOutlet NSProgressIndicator *progress;
|
||||
IBOutlet NSTextField *progressText;
|
||||
}
|
||||
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SBChapterSearchControllerDelegate>)del searchTitle:(NSString *)title andDuration:(NSUInteger)duration;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,327 @@
|
||||
//
|
||||
// SBChapterSearchController.m
|
||||
// Subler
|
||||
//
|
||||
// Created by Michael Hueber on 20.11.15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SBChapterSearchController.h"
|
||||
|
||||
#import <MP42Foundation/MP42Utilities.h>
|
||||
|
||||
#import "SBChapterImporter.h"
|
||||
#import "SBChapterResult.h"
|
||||
|
||||
@interface SBChapterSearchController () <NSTableViewDelegate>
|
||||
|
||||
@property (nonatomic, readwrite, retain) SBChapterImporter *currentSearcher;
|
||||
@property (nonatomic, readwrite, retain) NSArray<SBChapterResult *> *resultsArray;
|
||||
@property (nonatomic, readwrite, retain) NSArray<MP42TextSample *> *selectedChaptersArray;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBChapterSearchController
|
||||
|
||||
@synthesize currentSearcher = _currentSearcher;
|
||||
@synthesize resultsArray = _resultsArray;
|
||||
@synthesize selectedChaptersArray = _selectedChaptersArray;
|
||||
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SBChapterSearchControllerDelegate>)del searchTitle:(NSString *)title andDuration:(NSUInteger)duration
|
||||
{
|
||||
self = [super initWithWindowNibName:@"SBChapterSearch"];
|
||||
|
||||
if (self) {
|
||||
|
||||
delegate = del;
|
||||
_searchString = [title copy];
|
||||
_searchDuration = duration;
|
||||
|
||||
[self setupFontAttributes];
|
||||
|
||||
[self updateSearchButtonVisibility];
|
||||
|
||||
if (searchButton.enabled) {
|
||||
[self searchForResults:nil];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupFontAttributes
|
||||
{
|
||||
NSMutableParagraphStyle *ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
ps.headIndent = -10.0;
|
||||
ps.alignment = NSTextAlignmentRight;
|
||||
|
||||
_detailBoldMonospacedAttr = [@{NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightBold],
|
||||
NSParagraphStyleAttributeName: ps,
|
||||
NSForegroundColorAttributeName: [NSColor grayColor]} retain];
|
||||
|
||||
NSMutableParagraphStyle *psL = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
psL.headIndent = -10.0;
|
||||
psL.alignment = NSTextAlignmentLeft;
|
||||
_detailBoldAttr = [@{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightBold],
|
||||
NSParagraphStyleAttributeName: psL,
|
||||
NSForegroundColorAttributeName: [NSColor grayColor]} retain];
|
||||
|
||||
|
||||
_detailMonospacedAttr = [@{NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightRegular],
|
||||
NSParagraphStyleAttributeName: ps} retain];
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
[super windowDidLoad];
|
||||
|
||||
[self.window makeFirstResponder:searchTitle];
|
||||
|
||||
if (_searchString) {
|
||||
NSDictionary *parsed = [SBMetadataHelper parseFilename:_searchString];
|
||||
if (parsed) {
|
||||
|
||||
if ([@"movie" isEqualToString:(NSString *) [parsed valueForKey:@"type"]]) {
|
||||
if ([parsed valueForKey:@"title"]) searchTitle.stringValue = [parsed valueForKey:@"title"];
|
||||
} else if ([@"tv" isEqualToString:(NSString *) [parsed valueForKey:@"type"]]) {
|
||||
searchTitle.stringValue = _searchString.stringByDeletingPathExtension;
|
||||
}
|
||||
|
||||
searchDuration.stringValue = StringFromTime(_searchDuration, 1000);
|
||||
|
||||
[self updateSearchButtonVisibility];
|
||||
|
||||
if (searchButton.enabled) {
|
||||
[self searchForResults:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Search for results
|
||||
|
||||
- (IBAction)searchForResults:(id)sender
|
||||
{
|
||||
[addButton setEnabled:NO];
|
||||
|
||||
if (self.currentSearcher) {
|
||||
[self.currentSearcher cancel];
|
||||
}
|
||||
|
||||
if (searchTitle.stringValue.length) {
|
||||
|
||||
[self startProgressReportWithString:[NSString stringWithFormat:@"Searching %@ for chapter information…", @"ChapterDB"]];
|
||||
|
||||
self.currentSearcher = [SBChapterImporter importerForProvider:[SBChapterImporter defaultProvider]];
|
||||
|
||||
[self.currentSearcher searchTitle:searchTitle.stringValue
|
||||
duration:_searchDuration
|
||||
completionHandler:^(NSArray<SBChapterResult *> *results) {
|
||||
[self searchForResultsDone:results];
|
||||
}];
|
||||
|
||||
}
|
||||
else {
|
||||
// Nothing to search, reset the table view
|
||||
self.resultsArray = nil;
|
||||
self.selectedChaptersArray = nil;
|
||||
[resultsTable reloadData];
|
||||
[chapterTable reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)searchForResultsDone:(NSArray<SBChapterResult *> *)results
|
||||
{
|
||||
self.resultsArray = nil;
|
||||
|
||||
[self stopProgressReport];
|
||||
|
||||
self.resultsArray = results;
|
||||
self.selectedChaptersArray = nil;
|
||||
|
||||
[resultsTable reloadData];
|
||||
[chapterTable reloadData];
|
||||
|
||||
[self tableViewSelectionDidChange:[NSNotification notificationWithName:@"tableViewSelectionDidChange" object:resultsTable]];
|
||||
|
||||
if (self.resultsArray.count) {
|
||||
[self.window makeFirstResponder:resultsTable];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Search input fields
|
||||
|
||||
- (void)updateSearchButtonVisibility
|
||||
{
|
||||
if (searchTitle.stringValue.length > 0) {
|
||||
[searchButton setEnabled:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
[searchButton setEnabled:NO];
|
||||
}
|
||||
|
||||
- (void)controlTextDidChange:(NSNotification *)aNotification
|
||||
{
|
||||
[self updateSearchButtonVisibility];
|
||||
addButton.keyEquivalent = @"";
|
||||
searchButton.keyEquivalent = @"\r";
|
||||
}
|
||||
|
||||
#pragma mark - Finishing up
|
||||
|
||||
- (IBAction)addChapter:(id)sender
|
||||
{
|
||||
[self addChapterTrack];
|
||||
}
|
||||
|
||||
- (void) addChapterTrack
|
||||
{
|
||||
[delegate chapterImportDone:self.selectedChaptersArray];
|
||||
|
||||
[chapterTable setDelegate:nil];
|
||||
[chapterTable setDataSource:nil];
|
||||
[resultsTable setDelegate:nil];
|
||||
[resultsTable setDataSource:nil];
|
||||
|
||||
[NSApp endSheet:self.window returnCode:1];
|
||||
}
|
||||
|
||||
|
||||
- (IBAction)closeWindow:(id)sender
|
||||
{
|
||||
[resultsTable setDelegate:nil];
|
||||
[resultsTable setDataSource:nil];
|
||||
|
||||
[NSApp endSheet:self.window returnCode:0];
|
||||
}
|
||||
|
||||
#pragma mark - Progress
|
||||
|
||||
- (void)startProgressReportWithString:(NSString *)progressString
|
||||
{
|
||||
[progress startAnimation:self];
|
||||
[progress setHidden:NO];
|
||||
progressText.stringValue = progressString;
|
||||
[progressText setHidden:NO];
|
||||
|
||||
[resultsTable setEnabled:NO];
|
||||
[chapterTable setEnabled:NO];
|
||||
}
|
||||
|
||||
- (void)stopProgressReport
|
||||
{
|
||||
[progress setHidden:YES];
|
||||
[progressText setHidden:YES];
|
||||
[progress stopAnimation:self];
|
||||
|
||||
[resultsTable setEnabled:YES];
|
||||
[chapterTable setEnabled:YES];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Miscellaneous
|
||||
|
||||
- (NSAttributedString *)boldString:(NSString *)string monospaced:(BOOL)monospaced
|
||||
{
|
||||
if (monospaced) {
|
||||
return [[[NSAttributedString alloc] initWithString:string attributes:_detailBoldMonospacedAttr] autorelease];
|
||||
}
|
||||
return [[[NSAttributedString alloc] initWithString:string attributes:_detailBoldAttr] autorelease];
|
||||
}
|
||||
|
||||
- (NSAttributedString *)monospacedString:(NSString *)string
|
||||
{
|
||||
return [[[NSAttributedString alloc] initWithString:string attributes:_detailMonospacedAttr] autorelease];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
#pragma mark NSTableView delegates and protocols
|
||||
|
||||
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
|
||||
{
|
||||
if (tableView == resultsTable) {
|
||||
return self.resultsArray.count;
|
||||
}
|
||||
else if (tableView == (NSTableView *) chapterTable) {
|
||||
return self.selectedChaptersArray.count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
|
||||
{
|
||||
if (tableView == resultsTable) {
|
||||
if (self.resultsArray != nil) {
|
||||
SBChapterResult *result = self.resultsArray[rowIndex];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"title"]) {
|
||||
return result.title;
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"chaptercount"]) {
|
||||
return [self monospacedString:@(result.chapters.count).stringValue];
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"duration"]) {
|
||||
return [self monospacedString:StringFromTime(result.duration, 1000)];
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"confirmations"]) {
|
||||
return [self monospacedString:@(result.confirmations).stringValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tableView == (NSTableView *)chapterTable) {
|
||||
if (self.selectedChaptersArray != nil) {
|
||||
MP42TextSample *chapter = (self.selectedChaptersArray)[rowIndex];
|
||||
|
||||
if ([tableColumn.identifier isEqualToString:@"time"]) {
|
||||
return [self boldString:StringFromTime(chapter.timestamp, 1000) monospaced:YES];
|
||||
}
|
||||
else if ([tableColumn.identifier isEqualToString:@"name"]) {
|
||||
return chapter.title;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
|
||||
if (aNotification.object == resultsTable || aNotification.object == chapterTable) {
|
||||
if (self.resultsArray && (self.resultsArray).count > 0 && resultsTable.selectedRow > -1) {
|
||||
|
||||
self.selectedChaptersArray = self.resultsArray[resultsTable.selectedRow].chapters;
|
||||
|
||||
[chapterTable reloadData];
|
||||
[addButton setEnabled:YES];
|
||||
addButton.keyEquivalent = @"\r";
|
||||
searchButton.keyEquivalent = @"";
|
||||
}
|
||||
}
|
||||
else {
|
||||
[addButton setEnabled:NO];
|
||||
addButton.keyEquivalent = @"";
|
||||
searchButton.keyEquivalent = @"\r";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
|
||||
{
|
||||
if ([tableColumn.identifier isEqualToString:@"time"]) {
|
||||
if ([tableView.selectedRowIndexes containsIndex:rowIndex]) {
|
||||
|
||||
// Without this, the color won't change ...
|
||||
NSMutableAttributedString *highlightedString = [[[NSMutableAttributedString alloc] initWithAttributedString:[cell attributedStringValue]] autorelease];
|
||||
[highlightedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, highlightedString.length)];
|
||||
[cell setAttributedStringValue:highlightedString];
|
||||
|
||||
[cell setTextColor:[NSColor blackColor]];
|
||||
} else {
|
||||
[cell setTextColor:[NSColor grayColor]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+48
-1
@@ -20,6 +20,8 @@
|
||||
#import "SBMetadataSearchController.h"
|
||||
#import "SBArtworkSelector.h"
|
||||
|
||||
#import "SBChapterSearchController.h"
|
||||
|
||||
#import "SBMediaTagsController.h"
|
||||
|
||||
#import <MP42Foundation/MP42File.h>
|
||||
@@ -29,7 +31,7 @@
|
||||
|
||||
#define SublerTableViewDataType @"SublerTableViewDataType"
|
||||
|
||||
@interface SBDocument () <NSTableViewDelegate, SBFileImportDelegate, SBMetadataSearchControllerDelegate>
|
||||
@interface SBDocument () <NSTableViewDelegate, SBFileImportDelegate, SBMetadataSearchControllerDelegate, SBChapterSearchControllerDelegate>
|
||||
|
||||
@property (nonatomic, retain) MP42File *mp4;
|
||||
|
||||
@@ -368,6 +370,9 @@
|
||||
if (action == @selector(searchMetadata:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(searchChapters:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(sendToQueue:))
|
||||
return YES;
|
||||
|
||||
@@ -636,6 +641,8 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Metadata search
|
||||
|
||||
- (IBAction)searchMetadata:(id)sender
|
||||
{
|
||||
NSString *filename = nil;
|
||||
@@ -680,6 +687,46 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
|
||||
[metadataToBeImported release];
|
||||
}
|
||||
|
||||
#pragma mark - Chapters search
|
||||
|
||||
- (IBAction)searchChapters:(id)sender
|
||||
{
|
||||
NSString *title = self.mp4.metadata[@"Name"];
|
||||
NSUInteger duration = self.mp4.duration;
|
||||
|
||||
_sheet = [[SBChapterSearchController alloc] initWithDelegate:self searchTitle:title andDuration:duration];
|
||||
|
||||
[NSApp beginSheet:_sheet.window
|
||||
modalForWindow:documentWindow
|
||||
modalDelegate:self
|
||||
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
||||
contextInfo:nil];
|
||||
}
|
||||
|
||||
- (void)chapterImportDone:(NSArray<MP42TextSample *> *)chapterToBeImported
|
||||
{
|
||||
[chapterToBeImported retain];
|
||||
|
||||
if (chapterToBeImported) {
|
||||
|
||||
MP42ChapterTrack *newChapter = [[MP42ChapterTrack alloc] init];
|
||||
for (MP42TextSample *chapter in chapterToBeImported) {
|
||||
[newChapter addChapter:chapter];
|
||||
}
|
||||
[newChapter setDuration:self.mp4.duration];
|
||||
[self.mp4 addTrack:newChapter];
|
||||
[newChapter release];
|
||||
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
|
||||
[fileTracksTable reloadData];
|
||||
[self reloadPropertyView];
|
||||
[self updateChangeCount:NSChangeDone];
|
||||
}
|
||||
|
||||
[chapterToBeImported release];
|
||||
}
|
||||
|
||||
- (IBAction)showTrackOffsetSheet:(id)sender
|
||||
{
|
||||
[offset setStringValue:[NSString stringWithFormat:@"%lld",
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
[self metadataProviderSelected:tvMetadataProvider];
|
||||
|
||||
if (_searchString) {
|
||||
NSDictionary *parsed = [MetadataImporter parseFilename:_searchString];
|
||||
NSDictionary *parsed = [SBMetadataHelper parseFilename:_searchString];
|
||||
if (parsed) {
|
||||
|
||||
if ([@"movie" isEqualToString:(NSString *) [parsed valueForKey:@"type"]]) {
|
||||
@@ -364,7 +364,7 @@
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
|
||||
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
|
||||
NSData *artworkData = [MetadataImporter downloadDataFromURL:URLs[idx] withCachePolicy:SBDefaultPolicy];
|
||||
NSData *artworkData = [SBMetadataHelper downloadDataFromURL:URLs[idx] withCachePolicy:SBDefaultPolicy];
|
||||
|
||||
// Hack, download smaller iTunes version if big iTunes version is not available
|
||||
if (!artworkData) {
|
||||
@@ -372,7 +372,7 @@
|
||||
if ([provider isEqualToString:@"iTunes"]) {
|
||||
NSURL *url = URLs[idx];
|
||||
url = [[url URLByDeletingPathExtension] URLByAppendingPathExtension:@"600x600bb.jpg"];
|
||||
artworkData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
artworkData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
}
|
||||
|
||||
- (MP42Image *)loadArtwork:(NSURL *)url {
|
||||
NSData *artworkData = [MetadataImporter downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
NSData *artworkData = [SBMetadataHelper downloadDataFromURL:url withCachePolicy:SBDefaultPolicy];
|
||||
if (artworkData && artworkData.length) {
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithData:artworkData type:MP42_ART_JPEG];
|
||||
if (artwork != nil) {
|
||||
@@ -140,7 +140,7 @@
|
||||
MP42Metadata *metadata = nil;
|
||||
|
||||
// Parse FileName and search for metadata
|
||||
NSDictionary<NSString *, NSString *> *parsed = [MetadataImporter parseFilename:url.lastPathComponent];
|
||||
NSDictionary<NSString *, NSString *> *parsed = [SBMetadataHelper parseFilename:url.lastPathComponent];
|
||||
NSString *type = parsed[@"type"];
|
||||
|
||||
if ([@"movie" isEqualToString:type]) {
|
||||
|
||||
Reference in new issue
Block a user