1 #import <ObjFW/ObjFW.h>
2 #import <ObjXMPP/ObjXMPP.h>
6 #define NS_PUBSUB @"http://jabber.org/protocol/pubsub"
7 #define NS_TUNE @"http://jabber.org/protocol/tune"
9 @implementation PEPThread: OFThread
10 - (OFMutableDictionary*)MPD_responeFromSocket: (OFTCPSocket*)sock
13 OFMutableDictionary *response = [OFMutableDictionary dictionary];
14 while ((answer = [sock readLine]) && ![answer hasPrefix: @"OK"]) {
16 index = [answer indexOfFirstOccurrenceOfString: @":"];
17 if (index == OF_INVALID_INDEX)
19 [response setObject: [answer substringFromIndex: index + 2
20 toIndex: answer.length]
21 forKey: [answer substringFromIndex: 0
30 OFTCPSocket *sock = [OFTCPSocket socket];
31 [sock connectToHost: @"localhost"
33 [self MPD_responeFromSocket: sock];
35 OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
36 OFMutableDictionary *response;
38 XMPPIQ *tuneIQ = [XMPPIQ IQWithType: @"set"
39 ID: [object generateStanzaID]];
40 OFXMLElement *pubsub = [OFXMLElement
41 elementWithName: @"pubsub"
42 namespace: NS_PUBSUB];
43 [tuneIQ addChild: pubsub];
44 OFXMLElement *publish = [OFXMLElement
45 elementWithName: @"publish"
46 namespace: NS_PUBSUB];
47 [publish addAttributeWithName: @"node"
48 stringValue: NS_TUNE];
49 [pubsub addChild: publish];
50 OFXMLElement *item = [OFXMLElement elementWithName: @"item"
51 namespace: NS_PUBSUB];
52 [publish addChild: item];
53 OFXMLElement *tune = [OFXMLElement elementWithName: @"tune"
55 [item addChild: tune];
56 [sock writeLine: @"status"];
57 response = [self MPD_responeFromSocket: sock];
58 if ([[response objectForKey: @"state"] isEqual: @"play"]) {
59 [sock writeLine: @"currentsong"];
60 response = [self MPD_responeFromSocket: sock];
61 if ((answer = [response objectForKey: @"Artist"]))
62 [tune addChild: [OFXMLElement
63 elementWithName: @"artist"
65 stringValue: answer]];
66 if ((answer = [response objectForKey: @"Time"]))
67 [tune addChild: [OFXMLElement
68 elementWithName: @"length"
70 stringValue: answer]];
71 if ((answer = [response objectForKey: @"Album"]))
72 [tune addChild: [OFXMLElement
73 elementWithName: @"source"
75 stringValue: answer]];
76 if ((answer = [response objectForKey: @"Title"]))
77 [tune addChild: [OFXMLElement
78 elementWithName: @"title"
80 stringValue: answer]];
81 if ((answer = [response objectForKey: @"Track"]))
82 [tune addChild: [OFXMLElement
83 elementWithName: @"track"
85 stringValue: answer]];
87 [object sendStanza: tuneIQ];
88 [sock writeLine: @"idle player"];
89 [self MPD_responeFromSocket: sock];