Skip to content

Commit

Permalink
Исправление багов.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwertyadrian committed Sep 22, 2018
1 parent 3be3bef commit ad8b03c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build/
develop-eggs/
dist/
downloads/
Output/
eggs/
.eggs/
lib/
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# vk-music-downloader
Программа для скачивания музыки пользователей ВКонтакте
# VkMusic Downloader
Программа для скачивания музыки пользователей (сообществ) ВКонтакте

Скриншоты:

![start_screen](/screenshots/start_screen.png)

![user_tracks](/screenshots/user_tracks.png)

![group_tracks](/screenshots/group_tracks.png)
83 changes: 43 additions & 40 deletions audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ def _get_user_audio(self, user_login, user_password, userlink):
me = api_vk.users.get()[0]
if not user_id:
user_id = None
# noinspection PyBroadException
try:
id = api_vk.users.get(user_ids=user_id)[0]
url = url.format(id['id'])
self.statusInfo.setText('Получение списка аудиозаписей пользователя: {} {}'.format(id['first_name'],
id['last_name']))
except:
except Exception:
id = None
if not id:
group_id = api_vk.groups.getById(group_id=user_id)[0]
Expand Down Expand Up @@ -154,12 +155,14 @@ def _download_audio(self, track_list, directory):
download(track['link'], out=name, bar=None)
n += 1
self.change_progress(n)
os.chdir('../')
return 'Скачивание завершено'

def run(self):
result = self._download_audio(self.tracks, self.directory)
self.signal.emit(result)
try:
result = self._download_audio(self.tracks, self.directory)
self.signal.emit(result)
except Exception as e:
self.signal.emit(e)

def change_progress(self, n):
self.int_signal.emit(n)
Expand Down Expand Up @@ -189,6 +192,9 @@ def __init__(self):
self.login.setText(info[0])
self.password.setText(info[1])
self.user_link.setText(info[2])

# TODO Реализовать автообновление программы
# update = QtWidgets.QMessageBox.question(self, 'Доступно обновление', 'Установить обновление 0.2.0')

self.tracks = None
self.string = None
Expand All @@ -214,11 +220,7 @@ def start(self):
self.get_audio.password = self.password.text()
self.get_audio.user_link = self.user_link.text()
self.get_audio.statusInfo = self.statusInfo
self.btnConfirm.setEnabled(False)
self.downloadAll.setEnabled(False)
self.saveAll.setEnabled(False)
self.saveWithoutLinks.setEnabled(False)
self.downloadSelected.setEnabled(False)
self.toggle_buttons(False)
self.trackList.clear()
self.statusInfo.setText('Процесс получение аудиозаписей начался.\n')
self.get_audio.start()
Expand All @@ -227,25 +229,22 @@ def finished(self, result):
if result and isinstance(result, tuple):
self.tracks = result[0]
self.string = result[1]
self.btnConfirm.setEnabled(True)
self.statusInfo.setText('Список аудиозаписей получен.\n{}, {} шт.'.format(self.string, len(self.tracks)))
#row = 0
self.saveAll.setEnabled(True)
self.saveWithoutLinks.setEnabled(True)
self.downloadSelected.setEnabled(True)
self.downloadAll.setEnabled(True)
# row = 0
self.trackList.setEnabled(True)
self.btnConfirm.setEnabled(True)
self.toggle_buttons(True)
for track in self.tracks:
self.trackList.addItem('%(artist)s — %(title)s' % track)
#self.trackList.setRowCount(len(self.tracks))
#self.trackList.setItem(row, 0, QtWidgets.QTableWidgetItem(track['artist']))
#self.trackList.setItem(row, 1, QtWidgets.QTableWidgetItem(track['title']))
#row += 1
#self.trackList.resizeColumnsToContents()
# TODO Изучить работу с таблицами в PyQt5
# self.trackList.setRowCount(len(self.tracks))
# self.trackList.setItem(row, 0, QtWidgets.QTableWidgetItem(track['artist']))
# self.trackList.setItem(row, 1, QtWidgets.QTableWidgetItem(track['title']))
# row += 1
# self.trackList.resizeColumnsToContents()
elif isinstance(result, str):
self.btnConfirm.setEnabled(True)
self.statusInfo.setText('\nОшибка: ' + result)
self.statusInfo.setText('<html><head/><body><p><span style=" color:#ff0000;">Ошибка: {}'
'</span></p></body></html>'.format(result))

def save_all(self):
directory = QtWidgets.QFileDialog.getSaveFileName(self, 'Сохранить как', filter='Text files (*.txt)')[0]
Expand Down Expand Up @@ -280,14 +279,11 @@ def download_all(self):
self.progress_label.setEnabled(True)
self.progressBar.setEnabled(True)
self.progressBar.setMaximum(len(self.tracks))
self.downloadAll.setEnabled(False)
self.saveAll.setEnabled(False)
self.saveWithoutLinks.setEnabled(False)
self.downloadSelected.setEnabled(False)
self.btnConfirm.setEnabled(False)
self.toggle_buttons(False)
self.download_audio.start()

def download_selected(self):
directory = None
selected = self.trackList.selectedItems()
selected_tracks = []
for element in selected:
Expand All @@ -305,25 +301,32 @@ def download_selected(self):
self.progress_label.setEnabled(True)
self.progressBar.setEnabled(True)
self.progressBar.setMaximum(len(selected_tracks))
self.downloadAll.setEnabled(False)
self.saveAll.setEnabled(False)
self.saveWithoutLinks.setEnabled(False)
self.downloadSelected.setEnabled(False)
self.btnConfirm.setEnabled(False)
self.toggle_buttons(False)
self.download_audio.start()
else:
self.statusInfo.setText('<html><head/><body><p><span style=" color:#ff0000;">'
'Ничего не выбрано для скачивания или было отменено диалоговое с выбором папки'
'</span></p></body></html>')


def done(self, result):
self.downloadAll.setEnabled(True)
self.saveAll.setEnabled(True)
self.saveWithoutLinks.setEnabled(True)
self.downloadSelected.setEnabled(True)
self.btnConfirm.setEnabled(True)
self.statusInfo.setText(result)
self.toggle_buttons(True)
if isinstance(result, str):
self.statusInfo.setText(result)
else:
self.statusInfo.setText('<html><head/><body><p><span style=" color:#ff0000;">При скачивании'
' произошла ошибка: {}'
'</span></p></body></html>'.format(result))

def change_progress(self, result):
self.progressBar.setValue(result)


def toggle_buttons(self, state: bool):
self.downloadAll.setEnabled(state)
self.saveAll.setEnabled(state)
self.saveWithoutLinks.setEnabled(state)
self.downloadSelected.setEnabled(state)
self.btnConfirm.setEnabled(state)


def ui():
global window
Expand Down
7 changes: 2 additions & 5 deletions audio.ui
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
<widget class="QLabel" name="link_text">
<property name="geometry">
<rect>
<x>10</x>
<x>6</x>
<y>90</y>
<width>351</width>
<width>340</width>
<height>31</height>
</rect>
</property>
Expand Down Expand Up @@ -405,9 +405,6 @@
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
</widget>
<widget class="QCheckBox" name="enableSorting">
<property name="geometry">
Expand Down
Binary file added logo.ico
Binary file not shown.
Binary file added screenshots/group_tracks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/start_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/user_tracks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad8b03c

Please sign in to comment.