Skip to content

Commit

Permalink
headers change
Browse files Browse the repository at this point in the history
  • Loading branch information
byack committed Jan 24, 2020
1 parent 5079d20 commit 76ec36d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
7 changes: 4 additions & 3 deletions GUI/MainWindow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import *
from PyQt5.QtMultimedia import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QSlider, QStyleOptionSlider, QStyle, QWidget, QHBoxLayout, QVBoxLayout, QLabel, QLineEdit
from PyQt5.QtWidgets import QPushButton, QGridLayout, QFrame, QListWidget, QListWidgetItem, QMessageBox, QFileDialog
from PyQt5.QtMultimedia import QMediaPlayer, QMediaPlaylist, QMediaContent
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt, QUrl, QSize, QTimer
from Netease_Cloud_Music.Operation import *
import requests
Expand Down
Binary file modified GUI/__pycache__/MainWindow.cpython-38.pyc
Binary file not shown.
20 changes: 12 additions & 8 deletions Netease_Cloud_Music/Operation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import os
import requests
import random
from Single_Search import Music_api
from pyquery import PyQuery as pq


# 发送请求时的头文件
head = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0"
}
heades = [
{"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0"},
{"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"},
{"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"},
{"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36"}
]


# 下载首页推荐歌单封面
Expand All @@ -21,7 +25,7 @@ def down_img(img_url_list, path='./ico'):
exit(0)
n = 0
for j in img_url_list:
date = requests.get(j, headers=head) # 进行请求
date = requests.get(j, headers=heades[random.randint(0, len(heades))]) # 进行请求
with open("{}/{}.jpeg".format(path, n), "wb") as f:
f.write(date.content) # 写入数据
# print(j)
Expand All @@ -33,7 +37,7 @@ def down_img(img_url_list, path='./ico'):
def wyy_first_page():
# 先对首页进行简单处理
url = "https://music.163.com/discover"
response = requests.get(url, headers=head)
response = requests.get(url, headers=heades[random.randint(0, len(heades))])
doc = pq(response.text)
playlist = doc('li .u-cover.u-cover-1') # 筛选出首页推荐的歌单
playlist.find('.icon-play').remove() # 移除多余的信息,便于后续提取信息
Expand All @@ -55,7 +59,7 @@ def wyy_first_page():
# 通过歌单playlist_id获取歌单信息
def playlist_info(playlist_id):
url = "https://music.163.com/playlist?id=" + playlist_id
response = requests.get(url, headers=head)
response = requests.get(url, headers=heades[random.randint(0, len(heades))])
doc = pq(response.text)
num = int(doc('.sub.s-fc3 #playlist-track-count').text()) # 获取这个歌单的歌曲总数
li = doc('li:lt({})'.format(num)).find('a') # lt()获取之前的
Expand All @@ -67,7 +71,7 @@ def playlist_info(playlist_id):
# 传入dj电台的id号,获取dj电台的音频文件
def dj_url(dj_id):
url = "https://api.imjad.cn/cloudmusic/?type=dj&id=" + dj_id
response = requests.get(url, headers=head).json()
response = requests.get(url, headers=heades[random.randint(0, len(heades))]).json()
return response['data'][0]['url']


Expand All @@ -77,7 +81,7 @@ def song_url(song_id, br=320000):
urls = "https://api.imjad.cn/cloudmusic/?type=song&id={}&br={}".format(song_id, br)
url = requests.get(urls).json()['data'][0]['url']
try:
requests.get(url, headers=head) # 尝试请求,如果成功,反回url,版权问题不成功另外提示
requests.get(url, headers=heades[random.randint(0, len(heades))]) # 尝试请求,如果成功,反回url,版权问题不成功另外提示
return url
except requests.exceptions.MissingSchema:
"""由于版权原因,本首歌不能播放,抱歉哦......"""
Expand Down
Binary file modified Netease_Cloud_Music/__pycache__/Operation.cpython-38.pyc
Binary file not shown.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# kk-music
# <center>![](https://pic.downk.cc/item/5e2ab4fc2fb38b8c3c5fa4ee.jpg)kk-music</center>

---

## 最终效果(大概)

我的系统是manjaro

![](https://pic.downk.cc/item/5e2ac01c2fb38b8c3c606c03.png)

## 使用方法

```bash
git clone https://github.com/byack/kk-music.git
cd kk-music
pip3 install -r requirements.txt
python3 kk-music.py
```

等我研究一下如何直接打包成一个可执行文件,打包完成后我会将文件上传上来的。

## 概述

最近刚学了一点爬虫,想尝试着做一点东西,所以结合了pyqt5做了一个带界面的音乐播放器,只有一些基本功能,后续我会尽量维护完善这个项目,目前数据来源与网易云音乐。

## 一些可能的问题

+ 搜索框无法输入中文:(https://bbs.deepin.org/forum.php?mod=viewthread&tid=181772)

*欢迎邮箱反馈,我没有做详细的测试*

## 感谢

+ 图标来源:(https://icons8.cn/) (https://www.easyicon.net/) 内容均来源与网络,如有侵权,联系告知,我会立即删除
+ 网易云反爬代码参考:(https://blog.csdn.net/qq_36779888/article/details/90738012) 感谢大佬
+ qt5滑动条禁用点击事件代码参考:(https://github.com/PyQt5/PyQt/tree/master/QSlider)
+ 搜索框输入中文问题,链接如上,感谢大佬

可能有些遗漏,表示感谢

## 说明

本项目仅供学习,不能用作商业用途,克隆本项目后,如有侵权行为,请自行删除, 与作者无关。

如本项目有侵权行为,我会立即删除。
Binary file added __pycache__/kk-music.cpython-38.pyc
Binary file not shown.

0 comments on commit 76ec36d

Please sign in to comment.