-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoFindLyric.m
68 lines (54 loc) · 1.8 KB
/
AutoFindLyric.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "AutoFindLyric.h"
#import <EyeTunes/EyeTunes.h>
@implementation AutoFindLyric
- (IBAction)fetch:(id)sender {
EyeTunes *e = [EyeTunes sharedInstance];
ETTrack *t = [e currentTrack];
NSString *singer = [t artist];
NSString *song = [t name];
NSString *finalLyric;
lastSinger = singer;
lastSong = song;
NSURL *url;
NSData *data;
url = [NSURL URLWithString:[[NSString stringWithFormat:@"http://blackcanlyrics.appspot.com/?singer=%@&song=%@", singer, song] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
data = [url resourceDataUsingCache: NO];
finalLyric = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
[t setLyrics:finalLyric];
[Singer setStringValue:singer];
[Song setStringValue:song];
finalLyric = [t lyrics];
[Lyric setString:finalLyric];
}
-(void)getLyric
{
EyeTunes *e = [EyeTunes sharedInstance];
ETTrack *t = [e currentTrack];
NSString *singer = [t artist];
NSString *song = [t name];
NSString *finalLyric;
if((singer != lastSinger || song != lastSong))
{
if([[t lyrics] isEqualToString:@""])
{
lastSinger = singer;
lastSong = song;
NSURL *url;
NSData *data;
url = [NSURL URLWithString:[[NSString stringWithFormat:@"http://blackcanlyrics.appspot.com/?singer=%@&song=%@", singer, song] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
data = [url resourceDataUsingCache: NO];
finalLyric = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
[t setLyrics:finalLyric];
}
[Singer setStringValue:singer];
[Song setStringValue:song];
finalLyric = [t lyrics];
[Lyric setString:finalLyric];
}
}
-(void)awakeFromNib
{
SEL mySelector = @selector(getLyric);
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:mySelector userInfo:nil repeats:YES];
}
@end