예제 #1
0
	def run(self):
		print('Downloading audio list...')
		self.vk.get_audio_list(self.uid)
		self.raw_list = Xml('./cache/audio.xml')
		new_list = self.raw_list.get_node_list('aid')
		old_list = [line[:-1] for line in open('./cache/aid.txt')]
		error_list = [line[:-1] for line in open('./cache/error.txt')]
		diff_list = diff(diff(new_list, old_list), error_list)
		if not diff_list:
			input('No files to update, press Enter to exit... ')
			exit(0)

		files = [
			AudioFile(
				aid,
				self.find_sibling_node(aid, 'url'),
				self.find_sibling_node(aid, 'title'),
				self.find_sibling_node(aid, 'artist')
			)
			for aid in diff_list]

		aid_file = open('./cache/aid.txt', 'a')
		error_file = open('./cache/error.txt', 'a')
		for f in files:
			if f.download_audio():
				aid_file.write(f.aid + '\n')
				aid_file.flush()
				print('OK (%d/%d)' % (files.index(f) + 1, len(files)))
			else:
				error_file.write(f.aid + '\n')
				error_file.flush()
				print('Fail :(')
예제 #2
0
	def __init__(self):
		self.raw_list = None
		now_time = datetime.now()
		config = Xml('config.xml')
		expires = config.get_node('expires').text

		if expires and datetime.strptime(expires, "%d.%m.%Y %H:%M:%S") > now_time:
			self.token = config.get_node('token').text
			self.uid = config.get_node('uid').text
		else:
			url = ''
			url2 = config.get_node('url').text
			win32clipboard.OpenClipboard()
			win32clipboard.EmptyClipboard()
			win32clipboard.SetClipboardText(url2)
			win32clipboard.CloseClipboard()
			print('Go to', url2, '(URL was copied to clipboard) and')
			webbrowser.open(url2)
			while not (url and url.group(1)):
				url = input('input response url from browser or press Enter to use text in clipboard: ')
				if url == '':
					win32clipboard.OpenClipboard()
					url = win32clipboard.GetClipboardData()
					win32clipboard.CloseClipboard()
					print(url)
				url = re.match(
					'https://oauth.vk.com/blank.html#access_token=(\w+)&expires_in=(\w+)&user_id=(\w+)', url)
			self.token = config.get_node('token').text = url.group(1)
			self.uid = config.get_node('uid').text = url.group(3)

			expires_diff = url.group(2)
			config.get_node('expires').text = \
				(now_time + timedelta(seconds=int(expires_diff) - 360)).strftime('%d.%m.%Y %H:%M:%S')

			config.tree.write('config.xml')

		self.vk = VkResponse(self.token)
예제 #3
0
class Main:
	def __init__(self):
		self.raw_list = None
		now_time = datetime.now()
		config = Xml('config.xml')
		expires = config.get_node('expires').text

		if expires and datetime.strptime(expires, "%d.%m.%Y %H:%M:%S") > now_time:
			self.token = config.get_node('token').text
			self.uid = config.get_node('uid').text
		else:
			url = ''
			url2 = config.get_node('url').text
			win32clipboard.OpenClipboard()
			win32clipboard.EmptyClipboard()
			win32clipboard.SetClipboardText(url2)
			win32clipboard.CloseClipboard()
			print('Go to', url2, '(URL was copied to clipboard) and')
			webbrowser.open(url2)
			while not (url and url.group(1)):
				url = input('input response url from browser or press Enter to use text in clipboard: ')
				if url == '':
					win32clipboard.OpenClipboard()
					url = win32clipboard.GetClipboardData()
					win32clipboard.CloseClipboard()
					print(url)
				url = re.match(
					'https://oauth.vk.com/blank.html#access_token=(\w+)&expires_in=(\w+)&user_id=(\w+)', url)
			self.token = config.get_node('token').text = url.group(1)
			self.uid = config.get_node('uid').text = url.group(3)

			expires_diff = url.group(2)
			config.get_node('expires').text = \
				(now_time + timedelta(seconds=int(expires_diff) - 360)).strftime('%d.%m.%Y %H:%M:%S')

			config.tree.write('config.xml')

		self.vk = VkResponse(self.token)

	def run(self):
		print('Downloading audio list...')
		self.vk.get_audio_list(self.uid)
		self.raw_list = Xml('./cache/audio.xml')
		new_list = self.raw_list.get_node_list('aid')
		old_list = [line[:-1] for line in open('./cache/aid.txt')]
		error_list = [line[:-1] for line in open('./cache/error.txt')]
		diff_list = diff(diff(new_list, old_list), error_list)
		if not diff_list:
			input('No files to update, press Enter to exit... ')
			exit(0)

		files = [
			AudioFile(
				aid,
				self.find_sibling_node(aid, 'url'),
				self.find_sibling_node(aid, 'title'),
				self.find_sibling_node(aid, 'artist')
			)
			for aid in diff_list]

		aid_file = open('./cache/aid.txt', 'a')
		error_file = open('./cache/error.txt', 'a')
		for f in files:
			if f.download_audio():
				aid_file.write(f.aid + '\n')
				aid_file.flush()
				print('OK (%d/%d)' % (files.index(f) + 1, len(files)))
			else:
				error_file.write(f.aid + '\n')
				error_file.flush()
				print('Fail :(')

	def find_sibling_node(self, aid, tag):
		return self.raw_list.get_parent_node('aid', aid).find(tag).text