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 437b862 commit 3be3bef
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 59 deletions.
19 changes: 14 additions & 5 deletions audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __del__(self):
def _get_user_audio(self, user_login, user_password, userlink):
tracks = []
offset = 0
url = 'https://m.vk.com/audios{}'
session = VkApi(login=user_login, password=user_password, auth_handler=self.auth_handler,
config_filename=cookie)
self.statusInfo.setText('Авторизация.')
Expand All @@ -58,13 +59,19 @@ def _get_user_audio(self, user_login, user_password, userlink):
session.http.cookies.update(dict(remixmdevice='1920/1080/1/!!-!!!!'))
user_id = userlink.replace('https://vk.com/', '').replace('https://m.vk.com/', '')
me = api_vk.users.get()[0]
if not user_id:
user_id = None
try:
id = api_vk.users.get(user_ids=user_id)[0]
except IndexError:
id = me
url = 'https://m.vk.com/audios{}'.format(id['id'])
self.statusInfo.setText('Получение списка аудиозаписей пользователя: {} {}'.format(id['first_name'],
id['last_name']))
url = url.format(id['id'])
self.statusInfo.setText('Получение списка аудиозаписей пользователя: {} {}'.format(id['first_name'],
id['last_name']))
except:
id = None
if not id:
group_id = api_vk.groups.getById(group_id=user_id)[0]
url = url.format(-int(group_id['id']))
self.statusInfo.setText('Получение списка аудиозаписей сообщества: {}'.format(group_id['name']))
while True:
response = session.http.get(url, params={'offset': offset}, allow_redirects=False)
soup = BeautifulSoup(response.text, 'html.parser')
Expand Down Expand Up @@ -112,6 +119,8 @@ def run(self):
except exceptions.ApiError as e:
if '113' in str(e):
self.signal.emit('Неверная ссылка на профиль пользователя (неверный ID пользователя).')
elif '100' in str(e):
self.signal.emit('Неверная ссылка на профиль пользователя (сообщества).')
else:
self.signal.emit(str(e))
except Exception as e:
Expand Down
50 changes: 16 additions & 34 deletions audio.ui
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<!--
Copyright (C) 2018 Adrian Polyakov
This file is part of VkMusic Downloader
VkMusic Downloader is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
-->
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
Expand Down Expand Up @@ -54,7 +36,7 @@
<widget class="QLineEdit" name="login">
<property name="geometry">
<rect>
<x>340</x>
<x>350</x>
<y>10</y>
<width>181</width>
<height>31</height>
Expand All @@ -64,15 +46,15 @@
<widget class="QLabel" name="login_text">
<property name="geometry">
<rect>
<x>10</x>
<x>60</x>
<y>10</y>
<width>331</width>
<width>291</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
Expand All @@ -82,15 +64,15 @@
<widget class="QLabel" name="password_text">
<property name="geometry">
<rect>
<x>270</x>
<x>290</x>
<y>50</y>
<width>61</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
Expand All @@ -100,7 +82,7 @@
<widget class="QLineEdit" name="password">
<property name="geometry">
<rect>
<x>340</x>
<x>350</x>
<y>50</y>
<width>181</width>
<height>31</height>
Expand All @@ -125,25 +107,25 @@
<widget class="QLabel" name="link_text">
<property name="geometry">
<rect>
<x>60</x>
<x>10</x>
<y>90</y>
<width>281</width>
<width>351</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>13</pointsize>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>Ссылка на профиль пользователя:</string>
<string>Ссылка на профиль пользователя (сообщества):</string>
</property>
</widget>
<widget class="QLineEdit" name="user_link">
<property name="geometry">
<rect>
<x>340</x>
<x>350</x>
<y>90</y>
<width>181</width>
<height>31</height>
Expand Down Expand Up @@ -196,9 +178,9 @@
</property>
<property name="geometry">
<rect>
<x>530</x>
<x>540</x>
<y>90</y>
<width>251</width>
<width>111</width>
<height>27</height>
</rect>
</property>
Expand Down Expand Up @@ -430,8 +412,8 @@
<widget class="QCheckBox" name="enableSorting">
<property name="geometry">
<rect>
<x>530</x>
<y>46</y>
<x>540</x>
<y>50</y>
<width>171</width>
<height>41</height>
</rect>
Expand Down
40 changes: 20 additions & 20 deletions audio_gui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""
"""
Copyright (C) 2018 Adrian Polyakov
This file is part of VkMusic Downloader
Expand All @@ -24,8 +24,8 @@
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
import os.path
import sys
import os.path

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
Expand All @@ -41,36 +41,36 @@ def setupUi(self, MainWindow):
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.login = QtWidgets.QLineEdit(self.centralwidget)
self.login.setGeometry(QtCore.QRect(340, 10, 181, 31))
self.login.setGeometry(QtCore.QRect(350, 10, 181, 31))
self.login.setObjectName("login")
self.login_text = QtWidgets.QLabel(self.centralwidget)
self.login_text.setGeometry(QtCore.QRect(10, 10, 331, 31))
self.login_text.setGeometry(QtCore.QRect(60, 10, 291, 31))
font = QtGui.QFont()
font.setPointSize(13)
font.setPointSize(11)
self.login_text.setFont(font)
self.login_text.setObjectName("login_text")
self.password_text = QtWidgets.QLabel(self.centralwidget)
self.password_text.setGeometry(QtCore.QRect(270, 50, 61, 31))
self.password_text.setGeometry(QtCore.QRect(290, 50, 61, 31))
font = QtGui.QFont()
font.setPointSize(13)
font.setPointSize(11)
self.password_text.setFont(font)
self.password_text.setObjectName("password_text")
self.password = QtWidgets.QLineEdit(self.centralwidget)
self.password.setGeometry(QtCore.QRect(340, 50, 181, 31))
self.password.setGeometry(QtCore.QRect(350, 50, 181, 31))
self.password.setInputMethodHints(QtCore.Qt.ImhHiddenText|QtCore.Qt.ImhNoAutoUppercase|QtCore.Qt.ImhNoPredictiveText|QtCore.Qt.ImhSensitiveData)
self.password.setInputMask("")
self.password.setText("")
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.password.setDragEnabled(False)
self.password.setObjectName("password")
self.link_text = QtWidgets.QLabel(self.centralwidget)
self.link_text.setGeometry(QtCore.QRect(60, 90, 281, 31))
self.link_text.setGeometry(QtCore.QRect(10, 90, 351, 31))
font = QtGui.QFont()
font.setPointSize(13)
font.setPointSize(11)
self.link_text.setFont(font)
self.link_text.setObjectName("link_text")
self.user_link = QtWidgets.QLineEdit(self.centralwidget)
self.user_link.setGeometry(QtCore.QRect(340, 90, 181, 31))
self.user_link.setGeometry(QtCore.QRect(350, 90, 181, 31))
self.user_link.setObjectName("user_link")
self.btnConfirm = QtWidgets.QPushButton(self.centralwidget)
self.btnConfirm.setGeometry(QtCore.QRect(590, 440, 181, 29))
Expand All @@ -85,7 +85,7 @@ def setupUi(self, MainWindow):
self.status_label.setObjectName("status_label")
self.saveData = QtWidgets.QCheckBox(self.centralwidget)
self.saveData.setEnabled(True)
self.saveData.setGeometry(QtCore.QRect(530, 90, 251, 27))
self.saveData.setGeometry(QtCore.QRect(540, 90, 111, 27))
self.saveData.setObjectName("saveData")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10, 410, 331, 21))
Expand Down Expand Up @@ -150,7 +150,7 @@ def setupUi(self, MainWindow):
self.trackList.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.trackList.setObjectName("trackList")
self.enableSorting = QtWidgets.QCheckBox(self.centralwidget)
self.enableSorting.setGeometry(QtCore.QRect(530, 46, 171, 41))
self.enableSorting.setGeometry(QtCore.QRect(540, 50, 171, 41))
self.enableSorting.setStatusTip("")
self.enableSorting.setTristate(False)
self.enableSorting.setObjectName("enableSorting")
Expand All @@ -164,7 +164,7 @@ def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "VKMusic Downloader"))
self.login_text.setText(_translate("MainWindow", "Номер телефона или электронная почта:"))
self.password_text.setText(_translate("MainWindow", "Пароль:"))
self.link_text.setText(_translate("MainWindow", "Ссылка на профиль пользователя:"))
self.link_text.setText(_translate("MainWindow", "Ссылка на профиль пользователя (сообщества):"))
self.btnConfirm.setToolTip(_translate("MainWindow", "Получить список аудиозаписей пользователя"))
self.btnConfirm.setText(_translate("MainWindow", "Получить аудиозаписи"))
self.status_label.setText(_translate("MainWindow", "Статус:"))
Expand All @@ -183,13 +183,13 @@ def retranslateUi(self, MainWindow):
self.downloadSelected.setText(_translate("MainWindow", "Скачать выбранные"))
self.progressBar.setFormat(_translate("MainWindow", "Скачано %v из %m"))
self.progress_label.setText(_translate("MainWindow", "Прогресс скачивания:"))
self.trackList.setSortingEnabled(False)
self.enableSorting.setToolTip(_translate("MainWindow", "Сортировать спсиок в алфавитном порядке?"))
self.enableSorting.setText(_translate("MainWindow", "Сортировать список"))

def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath('.')
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath('.')
return os.path.join(base_path, relative_path)

0 comments on commit 3be3bef

Please sign in to comment.