Commit 314a580a authored by Felix Paul Kühne's avatar Felix Paul Kühne

Added support for OpenSubtitles

parent e062bef2
...@@ -22,6 +22,11 @@ ...@@ -22,6 +22,11 @@
<string>1</string> <string>1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIMainStoryboardFile</key> <key>UIMainStoryboardFile</key>
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#import "ViewController.h" #import "ViewController.h"
#import "MetaDataFetcherKit.h" #import "MetaDataFetcherKit.h"
@interface ViewController () <MDFHatchetFetcherDataRecipient> @interface ViewController () <MDFHatchetFetcherDataRecipient, MDFOSOFetcherDataRecipient>
@end @end
...@@ -18,6 +18,12 @@ ...@@ -18,6 +18,12 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
MDFOSOFetcher *osoFetcher = [[MDFOSOFetcher alloc] init];
osoFetcher.userAgentKey = @"VLSub 0.9";
osoFetcher.dataRecipient = self;
[osoFetcher prepareForFetching];
return;
MDFHatchetFetcher *fetcher = [[MDFHatchetFetcher alloc] init]; MDFHatchetFetcher *fetcher = [[MDFHatchetFetcher alloc] init];
fetcher.dataRecipient = self; fetcher.dataRecipient = self;
[fetcher searchForArtist:@"Muse"]; [fetcher searchForArtist:@"Muse"];
...@@ -43,4 +49,33 @@ ...@@ -43,4 +49,33 @@
NSLog(@"%@: failed to find artist '%@'", aFetcher, searchRequest); NSLog(@"%@: failed to find artist '%@'", aFetcher, searchRequest);
} }
- (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher readyToSearch:(BOOL)bValue
{
NSLog(@"%s", __PRETTY_FUNCTION__);
aFetcher.subtitleLanguageId = @"ger";
[aFetcher searchForSubtitlesWithQuery:@"Dogville"];
}
- (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher didFindSubtitles:(NSArray<MDFSubtitleItem *> *)subtitles forSearchRequest:(NSString *)searchRequest
{
NSLog(@"searched for %@\nfound:\n%@", searchRequest, subtitles);
MDFSubtitleItem *firstItem = [subtitles firstObject];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *uploadDirPath = [searchPaths[0] stringByAppendingPathComponent:firstItem.name];
[aFetcher downloadSubtitleItem:[subtitles firstObject] toPath:uploadDirPath];
}
- (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher subtitleDownloadSucceededForItem:(MDFSubtitleItem *)subtitleItem atPath:(NSString *)pathToFile
{
NSLog(@"download succeeded for item %@, file at %@", subtitleItem, pathToFile);
}
- (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher didFailToDownloadForItem:(MDFSubtitleItem *)subtitleItem
{
NSLog(@"download failed for item %@", subtitleItem);
}
@end @end
...@@ -4,6 +4,6 @@ use_frameworks! ...@@ -4,6 +4,6 @@ use_frameworks!
target 'MDF-iOS-Demo', :exclusive => true do target 'MDF-iOS-Demo', :exclusive => true do
pod "MetaDataFetcherKit", :path => "../" pod "MetaDataFetcherKit", :path => "../"
pod "OROpenSubtitleDownloader", :git => 'https://github.com/fkuehne/OROpenSubtitleDownloader.git'
end end
...@@ -14,18 +14,36 @@ PODS: ...@@ -14,18 +14,36 @@ PODS:
- AFNetworking/Serialization (3.0.0-beta.1) - AFNetworking/Serialization (3.0.0-beta.1)
- AFNetworking/UIKit (3.0.0-beta.1): - AFNetworking/UIKit (3.0.0-beta.1):
- AFNetworking/NSURLSession - AFNetworking/NSURLSession
- MetaDataFetcherKit (0.1.3): - MetaDataFetcherKit (0.1.7):
- AFNetworking (= 3.0.0-beta.1) - AFNetworking (= 3.0.0-beta.1)
- OROpenSubtitleDownloader
- NSData+Base64 (1.0.0)
- OROpenSubtitleDownloader (1.2.0):
- AFNetworking
- xmlrpc
- xmlrpc (2.3.4):
- NSData+Base64 (~> 1.0.0)
DEPENDENCIES: DEPENDENCIES:
- MetaDataFetcherKit (from `../`) - MetaDataFetcherKit (from `../`)
- OROpenSubtitleDownloader (from `https://github.com/fkuehne/OROpenSubtitleDownloader.git`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
MetaDataFetcherKit: MetaDataFetcherKit:
:path: ../ :path: ../
OROpenSubtitleDownloader:
:git: https://github.com/fkuehne/OROpenSubtitleDownloader.git
CHECKOUT OPTIONS:
OROpenSubtitleDownloader:
:commit: af46bf6a046293e2fec0231d7ebb4e5ecf21a555
:git: https://github.com/fkuehne/OROpenSubtitleDownloader.git
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: 1100906802d9479aa0949e8e2cbc1d4e6beba327 AFNetworking: 1100906802d9479aa0949e8e2cbc1d4e6beba327
MetaDataFetcherKit: 9bf321e3cc92eeaa45d03fe67b8fcdf178c9e622 MetaDataFetcherKit: 0feaf9db69b6177287fe23881249a339b2cf4185
NSData+Base64: 4e84902c4db907a15673474677e57763ef3903e4
OROpenSubtitleDownloader: 390c86cd641ff849127cfa19b5cb8c72b715d5b1
xmlrpc: 109bb21d15ed6d108b2c1ac5973a6a223a50f5f4
COCOAPODS: 0.39.0 COCOAPODS: 0.39.0
{ {
"name": "MetaDataFetcherKit", "name": "MetaDataFetcherKit",
"version": "0.1.3", "version": "0.1.7",
"summary": "An ObjC library to fetch meta data for media content", "summary": "An ObjC library to fetch meta data for media content",
"homepage": "https://code.videolan.org/fkuehne/MetaDataFetcherKit", "homepage": "https://code.videolan.org/fkuehne/MetaDataFetcherKit",
"license": "LGPL v21", "license": "LGPL v21",
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
"source": { "source": {
"git": "https://code.videolan.org/fkuehne/MetaDataFetcherKit.git", "git": "https://code.videolan.org/fkuehne/MetaDataFetcherKit.git",
"tag": "0.1.3" "tag": "0.1.7"
}, },
"social_media_url": "https://twitter.com/feepk", "social_media_url": "https://twitter.com/feepk",
"platforms": { "platforms": {
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
"dependencies": { "dependencies": {
"AFNetworking": [ "AFNetworking": [
"3.0.0-beta.1" "3.0.0-beta.1"
],
"OROpenSubtitleDownloader": [
] ]
} }
} }
...@@ -14,18 +14,36 @@ PODS: ...@@ -14,18 +14,36 @@ PODS:
- AFNetworking/Serialization (3.0.0-beta.1) - AFNetworking/Serialization (3.0.0-beta.1)
- AFNetworking/UIKit (3.0.0-beta.1): - AFNetworking/UIKit (3.0.0-beta.1):
- AFNetworking/NSURLSession - AFNetworking/NSURLSession
- MetaDataFetcherKit (0.1.3): - MetaDataFetcherKit (0.1.7):
- AFNetworking (= 3.0.0-beta.1) - AFNetworking (= 3.0.0-beta.1)
- OROpenSubtitleDownloader
- NSData+Base64 (1.0.0)
- OROpenSubtitleDownloader (1.2.0):
- AFNetworking
- xmlrpc
- xmlrpc (2.3.4):
- NSData+Base64 (~> 1.0.0)
DEPENDENCIES: DEPENDENCIES:
- MetaDataFetcherKit (from `../`) - MetaDataFetcherKit (from `../`)
- OROpenSubtitleDownloader (from `https://github.com/fkuehne/OROpenSubtitleDownloader.git`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
MetaDataFetcherKit: MetaDataFetcherKit:
:path: ../ :path: ../
OROpenSubtitleDownloader:
:git: https://github.com/fkuehne/OROpenSubtitleDownloader.git
CHECKOUT OPTIONS:
OROpenSubtitleDownloader:
:commit: af46bf6a046293e2fec0231d7ebb4e5ecf21a555
:git: https://github.com/fkuehne/OROpenSubtitleDownloader.git
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: 1100906802d9479aa0949e8e2cbc1d4e6beba327 AFNetworking: 1100906802d9479aa0949e8e2cbc1d4e6beba327
MetaDataFetcherKit: 9bf321e3cc92eeaa45d03fe67b8fcdf178c9e622 MetaDataFetcherKit: 0feaf9db69b6177287fe23881249a339b2cf4185
NSData+Base64: 4e84902c4db907a15673474677e57763ef3903e4
OROpenSubtitleDownloader: 390c86cd641ff849127cfa19b5cb8c72b715d5b1
xmlrpc: 109bb21d15ed6d108b2c1ac5973a6a223a50f5f4
COCOAPODS: 0.39.0 COCOAPODS: 0.39.0
This diff is collapsed.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
buildForArchiving = "YES"> buildForArchiving = "YES">
<BuildableReference <BuildableReference
BuildableIdentifier = 'primary' BuildableIdentifier = 'primary'
BlueprintIdentifier = '0098FBE5F77C46B8272F6E7F' BlueprintIdentifier = 'BE1072928CD9DFF79C3E3F29'
BlueprintName = 'MetaDataFetcherKit' BlueprintName = 'MetaDataFetcherKit'
ReferencedContainer = 'container:Pods.xcodeproj' ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'MetaDataFetcherKit.framework'> BuildableName = 'MetaDataFetcherKit.framework'>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.1.3</string> <string>0.1.7</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#import "MDFMovieDBFetcher.h" #import "MDFMovieDBFetcher.h"
#import "MDFMovieDBSessionManager.h" #import "MDFMovieDBSessionManager.h"
#import "MDFMusicAlbum.h" #import "MDFMusicAlbum.h"
#import "MDFOSOFetcher.h"
#import "MDFSubtitleItem.h"
#import "MDFTVShow.h" #import "MDFTVShow.h"
#import "MetaDataFetcherKit.h" #import "MetaDataFetcherKit.h"
#import "MLTitleDecrapifier.h" #import "MLTitleDecrapifier.h"
......
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "MetaDataFetcherKit" s.name = "MetaDataFetcherKit"
s.version = "0.1.7" s.version = "0.2.0"
s.summary = "An ObjC library to fetch meta data for media content" s.summary = "An ObjC library to fetch meta data for media content"
s.homepage = "https://code.videolan.org/fkuehne/MetaDataFetcherKit" s.homepage = "https://code.videolan.org/fkuehne/MetaDataFetcherKit"
...@@ -21,5 +21,6 @@ Pod::Spec.new do |s| ...@@ -21,5 +21,6 @@ Pod::Spec.new do |s|
s.frameworks = 'Foundation' s.frameworks = 'Foundation'
s.dependency 'AFNetworking', '3.0.0-beta.1' s.dependency 'AFNetworking', '3.0.0-beta.1'
s.dependency 'OROpenSubtitleDownloader'
end end
//
// MDFOSOFetcher.h
// Pods
//
// Created by Felix Paul Kühne on 26/11/15.
//
//
#import <Foundation/Foundation.h>
#import "MDFSubtitleItem.h"
@class MDFOSOFetcher;
@protocol MDFOSOFetcherDataRecipient <NSObject>
- (void)MDFOSOFetcher:(MDFOSOFetcher * _Nonnull)aFetcher readyToSearch:(BOOL)bValue;
@optional
- (void)MDFOSOFetcher:(MDFOSOFetcher * _Nonnull)aFetcher didFindSubtitles:(NSArray <MDFSubtitleItem *> * _Nonnull)subtitles forSearchRequest:(NSString * _Nonnull)searchRequest;
- (void)MDFOSOFetcher:(MDFOSOFetcher * _Nonnull)aFetcher didFailToFindSubtitlesForSearchRequest:(NSString * _Nonnull)searchRequest;
- (void)MDFOSOFetcher:(MDFOSOFetcher * _Nonnull)aFetcher subtitleDownloadSucceededForItem:(MDFSubtitleItem * _Nonnull)subtitleItem atPath:(NSString * _Nonnull)pathToFile;
- (void)MDFOSOFetcher:(MDFOSOFetcher * _Nonnull)aFetcher didFailToDownloadForItem:(MDFSubtitleItem * _Nonnull)subtitleItem;
@end
@interface MDFOSOFetcher : NSObject
/**
* the object receiving the responses to requests send to instances of the fetcher
* \param any NSObject implementing the MDFOSOFetcherDataRecipient protocol
* \return the current receiver
* \note should be set before doing any requests
*/
@property (weak, nonatomic) id<MDFOSOFetcherDataRecipient> dataRecipient;
- (void)prepareForFetching;
/**
* the user-agent key to use for the fetches
* \param the user-agent key to set [STRING]
* \return the current user-agent key [STRING]
* \note user-agent key must be set before doing any requests
*/
@property (retain, nonatomic, nonnull) NSString *userAgentKey;
/**
* search for the list of languages potentially available on the website
*/
@property (readonly, nonatomic, copy) NSArray *availableLanguages;
/**
* the language ID (ISO-639-3) to use for the fetches
* \param the language ID to set [STRING]
* \return the current language ID [STRING]
* \note if none is set, the default value "eng" will be used
*/
@property (retain, nonnull, nonatomic) NSString *subtitleLanguageId;
/**
* the query string to search for
*/
- (void)searchForSubtitlesWithQuery:(NSString * _Nonnull)query;
- (void)downloadSubtitleItem:(MDFSubtitleItem * _Nonnull)item toPath:(NSString * _Nonnull)path;
@end
//
// MDFOSOFetcher.m
// Pods
//
// Created by Felix Paul Kühne on 26/11/15.
//
//
#import "MDFOSOFetcher.h"
#import "OROpenSubtitleDownloader.h"
@interface MDFOSOFetcher () <OROpenSubtitleDownloaderDelegate>
{
NSMutableArray<NSURLSessionTask *> *_requests;
OROpenSubtitleDownloader *_subtitleDownloader;
BOOL _readyForFetching;
}
@end
@implementation MDFOSOFetcher
- (instancetype)init
{
self = [super init];
if (self) {
_subtitleLanguageId = @"eng";
}
return self;
}
- (void)prepareForFetching
{
if (!_userAgentKey) {
if (self.dataRecipient) {
if ([self.dataRecipient respondsToSelector:@selector(MDFOSOFetcher:readyToSearch:)]) {
[self.dataRecipient MDFOSOFetcher:self readyToSearch:NO];
}
} else
NSLog(@"%s: no user agent set", __PRETTY_FUNCTION__);
}
_subtitleDownloader = [[OROpenSubtitleDownloader alloc] initWithUserAgent:_userAgentKey];
[self searchForAvailableLanguages];
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%s: user-agent '%@', language ID '%@'", __PRETTY_FUNCTION__, _userAgentKey, _subtitleLanguageId];
}
- (void)searchForSubtitlesWithQuery:(NSString *)query
{
[_subtitleDownloader setLanguageString:_subtitleLanguageId];
[_subtitleDownloader searchForSubtitlesWithQuery:query :^(NSArray *subtitles, NSError *error){
if (!subtitles || error) {
if (self.dataRecipient) {
if ([self.dataRecipient respondsToSelector:@selector(MDFOSOFetcher:didFailToFindSubtitlesForSearchRequest:)]) {
[self.dataRecipient MDFOSOFetcher:self didFailToFindSubtitlesForSearchRequest:query];
}
} else
NSLog(@"%s: %@", __PRETTY_FUNCTION__, error);
}
NSUInteger count = subtitles.count;
NSMutableArray *subtitlesToReturn = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger x = 0; x < count; x++) {
OpenSubtitleSearchResult *result = subtitles[x];
MDFSubtitleItem *item = [[MDFSubtitleItem alloc] init];
item.name = result.subtitleName;
item.format = result.subtitleFormat;
item.language = result.subtitleLanguage;
item.iso639Language = result.iso639Language;
item.downloadAddress = result.subtitleDownloadAddress;
[subtitlesToReturn addObject:item];
}
if (self.dataRecipient) {
if ([self.dataRecipient respondsToSelector:@selector(MDFOSOFetcher:didFindSubtitles:forSearchRequest:)]) {
[self.dataRecipient MDFOSOFetcher:self didFindSubtitles:[subtitlesToReturn copy] forSearchRequest:query];
}
} else
NSLog(@"found %@", subtitlesToReturn);
}];
}
- (void)searchForAvailableLanguages
{
[_subtitleDownloader supportedLanguagesList:^(NSArray *langauges, NSError *aError){
if (!langauges || aError) {
NSLog(@"%s: no languages found or error %@", __PRETTY_FUNCTION__, aError);
}
NSUInteger count = langauges.count;
NSMutableArray *languageItems = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger x = 0; x < count; x++) {
OpenSubtitleLanguageResult *result = langauges[x];
MDFSubtitleLanguage *item = [[MDFSubtitleLanguage alloc] init];
item.ID = result.subLanguageID;
item.iso639Language = result.iso639Language;
item.localizedName = result.localizedLanguageName;
[languageItems addObject:item];
}
_availableLanguages = [languageItems copy];
[self openSubtitlerDidLogIn:nil];
}];
}
- (void)openSubtitlerDidLogIn:(OROpenSubtitleDownloader *)downloader
{
_readyForFetching = YES;
if (self.dataRecipient) {
if ([self.dataRecipient respondsToSelector:@selector(MDFOSOFetcher:readyToSearch:)]) {
[self.dataRecipient MDFOSOFetcher:self readyToSearch:YES];
}
}
}
- (void)downloadSubtitleItem:(MDFSubtitleItem *)item toPath:(NSString *)path
{
OpenSubtitleSearchResult *result = [[OpenSubtitleSearchResult alloc] init];
result.subtitleDownloadAddress = item.downloadAddress;
[_subtitleDownloader downloadSubtitlesForResult:result toPath:path :^(NSString *path, NSError *error) {
if (self.dataRecipient) {
if (error) {
if ([self.dataRecipient respondsToSelector:@selector(MDFOSOFetcher:didFailToDownloadForItem:)]) {
[self.dataRecipient MDFOSOFetcher:self didFailToDownloadForItem:item];
}
} else {
if ([self.dataRecipient respondsToSelector:@selector(MDFOSOFetcher:subtitleDownloadSucceededForItem:atPath:)]) {
[self.dataRecipient MDFOSOFetcher:self subtitleDownloadSucceededForItem:item atPath:path];
}
}
} else
NSLog(@"%s: path %@ error %@", __PRETTY_FUNCTION__, path, error);
}];
}
@end
//
// MDFSubtitleItem.h
// Pods
//
// Created by Felix Paul Kühne on 26/11/15.
//
//
#import <Foundation/Foundation.h>
@interface MDFSubtitleItem : NSObject
@property (copy, nonatomic) NSString *language;
@property (copy, nonatomic) NSString *name;
@property (copy, nonatomic) NSString *format;
@property (copy, nonatomic) NSString *iso639Language;
@property (copy, nonatomic) NSString *downloadAddress;
@end
@interface MDFSubtitleLanguage : NSObject
@property (copy, nonatomic) NSString *ID;
@property (copy, nonatomic) NSString *localizedName;
@property (copy, nonatomic) NSString *iso639Language;
@end
\ No newline at end of file
//
// MDFSubtitleItem.m
// Pods
//
// Created by Felix Paul Kühne on 26/11/15.
//
//
#import "MDFSubtitleItem.h"
@implementation MDFSubtitleItem
- (NSString *)description
{
return [NSString stringWithFormat:@"%s: name: '%@' format: '%@' language: '%@'", __PRETTY_FUNCTION__, self.name, self.format, self.language];
}
@end
@implementation MDFSubtitleLanguage
- (NSString *)description
{
return [NSString stringWithFormat:@"%s: ID: '%@', ISO639: '%@', localized: '%@'", __PRETTY_FUNCTION__, self.ID, self.iso639Language, self.localizedName]
}
@end
...@@ -33,3 +33,5 @@ ...@@ -33,3 +33,5 @@
#import "MDFHatchetFetcher.h" #import "MDFHatchetFetcher.h"
#import "MDFMusicAlbum.h" #import "MDFMusicAlbum.h"
#import "MDFArtist.h" #import "MDFArtist.h"
#import "MDFOSOFetcher.h"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment