-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_interface.py
More file actions
executable file
·190 lines (152 loc) · 5.93 KB
/
cmd_interface.py
File metadata and controls
executable file
·190 lines (152 loc) · 5.93 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import cmd
import ConfigParser
import pickle
from mbrainzApi import mbzAPI
from lastfmApi import lfmAPI
from unidecode import unidecode
from vkdtools import tomin, initVk, get_links, getWorkdir, DownloadPrepare, ProcessFile
config = ConfigParser.ConfigParser()
mbz_api = mbzAPI()
lfm = lfmAPI("f3d8fbacbda2a35bfa855ef52052ca25")
intro = "\nWelcome to VKD ver 3.0 with Command Interface\ntype 'help' for view command list\n"
#noinspection PyBroadException
class command_interface(cmd.Cmd):
status = {'vk': 'off',
'artist': 'notset',
'album': 'notset',
'score': 98.0,
'listsize': 5,
'timerange': 0,
'manual': False
}
prompt = '(VK:%s|Artist:%s) > ' % (status['vk'], status['artist'])
runDir = os.getcwdu()
def do_status(self, line):
for key in self.status.keys():
print '[%s] -> [%s]' % (key, self.status[key]) # # OK
def do_cd(self, line):
os.chdir(getWorkdir())
def do_quit(self, line):
print 'Exiting...'
quit()
def do_initvk(self, line):
global login, login, password
if line and len(line.split()) > 1:
login = line.split()[0]
password = line.split()[1]
else:
print 'Trying get from Config file...',
try:
config.read(os.path.join(self.runDir, 'vkdconfig.ini'))
login = config.get('vkuser', 'login')
password = config.get('vkuser', 'pass')
print 'OK'
except:
print 'Fail'
try:
self.br = initVk(login, password)
self.status['vk'] = 'OK'
self.prompt = '(VK:%s|Artist:%s) > ' % (self.status['vk'], self.status['artist'])
except: print 'VK Login Failed'
def do_search(self, line):
index = 1
self.artist_list = lfm.artist_search(line)
for artist in self.artist_list:
print index, artist
index += 1
def do_set(self, line):
self.status['artist'] = self.artist_list[int(line)-1]
self.prompt = '(VK:%s|Artist:%s) > ' % (self.status['vk'], self.status['artist'])
self.album_list = lfm.getTopAlbums(self.status['artist'])
if self.album_list:
index = 1
for album in self.album_list:
print index, album
index += 1
else:
print 'No Albums'
def do_score(self, line):
if line:
self.status['score'] = float(line)
else:
print '[Score] Current Score Limit = %s' % (self.status['score'])
def do_timerange(self, line):
if line:
self.status['timerange'] = int(line)
else:
print '[TimeRange] Current Time Range = %s' % (self.status['timerange'])
def do_timerange(self, line):
if line:
self.status['timerange'] = int(line)
else:
print '[TimeRange] Current Time Range = %s' % (self.status['timerange'])
def do_listsize(self, line):
if line:
self.status['listsize'] = int(line)
else:
print '[ListSize] Current List Limit = %s' % (self.status['listsize'])
def do_manual(self, line):
if line:
if line == 'on':
self.status['manual'] = True
elif line == 'off':
self.status['manual'] = False
else:
print '[Acoustic ID] Score Mode', self.status['manual']
def do_tracks(self, line):
self.status['album'] = self.album_list[int(line)-1]
self.tracks, self.release_date = lfm.getAlbumInfo(self.status['artist'], self.status['album'])
if self.release_date: self.status['year'] = self.release_date.year
else: self.status['year'] = ''
for track in self.tracks:
print '[%s] %s (%s)' % (track[0], track[1], tomin(track[2]))
def do_get(self, line):
if self.status['vk'] == 'OK':
artist = self.status['artist']
album = self.status['album'] = self.album_list[int(line)-1]
tracks, release_date, covers = lfm.getAlbumInfo(artist, album)
tags = lfm.getTopTags(artist)
self.status['tag'] = tags[0]
if release_date: year = self.status['year'] = str(release_date.year)
else: year = self.status['year'] = ''
# Session Save
data_save = [artist, album, covers, year, tracks, self.status]
with open('session.data' , 'w') as dump_file:
pickle.dump(data_save, dump_file)
del data_save
print 'Session saved in session.data'
DownloadPrepare(artist, album, covers, year)
for track in tracks:
ProcessFile(track, self.status, self.br)
os.chdir('../..')
os.remove('session.data')
else:
print 'Login VK First!'
def do_resume(self, line):
if self.status['vk'] == 'OK':
if os.path.exists('session.data'):
with open('session.data' , 'r') as dump_file:
data_load = pickle.load(dump_file)
artist = data_load[0]
album = data_load[1]
covers = data_load[2]
year = data_load[3]
tracks = data_load[4]
self.status = data_load[5]
del data_load
print 'Session Resume....'
DownloadPrepare(artist, album, covers, year)
for track in tracks:
ProcessFile(track, self.status, self.br)
os.chdir('../..')
os.remove('session.data')
else: print 'Session file not found!'
else: print 'Login VK First'
def main():
terminal = command_interface()
terminal.cmdloop(intro)
if __name__ == '__main__':
main()