-
Notifications
You must be signed in to change notification settings - Fork 1
/
music.py
82 lines (60 loc) · 2.43 KB
/
music.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import mpd
import subprocess
class Music:
def __init__(self, irc):
self.irc = irc
def halp(self):
return ["!music current", "!music youtube <youtube-link>"]
def action_current(self, from_, chan, parts):
client = mpd.MPDClient()
client.connect('localhost', 6600, timeout=4)
song = client.currentsong()
client.disconnect()
disp = song['artist'] + " - " + song['title']
self.irc.privmsg(chan, disp)
def action_search(self, from_, chan, parts):
client = mpd.MPDClient()
client.connect('localhost', 6600, timeout=4)
result = client.search(parts[0], " ".join(parts[1:]))
client.disconnect()
for entry in result:
self.irc.privmsg(from_[0], entry['file'])
def action_download(self, from_, chan, parts):
url = parts[0]
try:
subprocess.check_call(
["transmission-remote", "-n", "simark:test", "-w", "/home/simark/music/mount/music", "-a", url])
self.irc.privmsg(chan, from_[0] + ": Started download")
except subprocess.CalledProcessError:
self.irc.privmsg(chan, from_[0] + ": Error trying to download")
def action_youtubeplay(self, from_, chan, parts):
url = parts[0]
video = subprocess.check_output(
["/usr/local/bin/youtube-dl", "-f", "34", "-g", url], universal_newlines=True).split()[0]
client = mpd.MPDClient()
client.connect('localhost', 6600, timeout=4)
result = client.add(video)
status = client.status()
# if (status['state'] == 'stop') :
# client.play(status['nextsong'])
liste = client.playlist()
if ('song' in status):
currentSong = int(status['song'])
client.move(len(liste) - 1, currentSong + 1)
else:
client.play(len(liste) - 1)
# client.play(len(liste)-1)
client.disconnect()
self.irc.privmsg(chan, "okidoo")
def on_chanmsg(self, from_, chan, msg):
parts = msg.split()
parts.pop(0)
command = parts.pop(0)
if command == 'current':
self.action_current(from_, chan, parts)
elif command == 'search':
self.action_search(from_, chan, parts)
elif command == 'download':
self.action_download(from_, chan, parts)
elif command == 'youtube':
self.action_youtubeplay(from_, chan, parts)