• Home


  • Archives


  • Laboratory


  • Donate


  • Friends


  • Messages


  • About Me
  • 22 Onl
W e l c o m e
W e l c o m e

HellCatVN

Write the Code, Change the World.

June
08
Python

KSLBLN [01] Script Python Tải Tất Cả Thông Tin Bài Hát Nhạc Của Tui

Published on 2018-06-08 • Python • Views:

Có lẽ bạn thắc mắc series này mang tên [KSLBLN] có nghĩ là gì thì mình xin được giải đáp thêm đó chính là khi sự lười biến lên ngôi
Trong series hôm nay thì mình xin Được viết về Nhaccuatui….Vâng chính là nó sau khi làm cái UserScript Get Nhaccuatui ,kiếm xong cái player phát nhạc thì phát hiện cái player nó hỗ trợ cả lyric lẫn thumbnail….Nên mình quyết định làm 1 script tự động tải file MP3,Lyric,Thumbnail Theo List Link Nhạc Của Mình Tạo Sẵn

Đầu tiên thì vẫn là xuất phát từ file xml mà mình đã nhắc đến ở bài Hướng Dẫn Viết UserScript Get Nhaccuatui
Mình sẽ bắt đầu từ đoạn tải và giải mã khi đã lấy dc các link từ file xml
Cơ bản để đọc được file xml thì mình dùng thư viện xmltodict ở dòng 34 và import nó vào ở dòng 5 vậy nên anh em dùng pip cài dùm mình các gói đã import để chạy à còn nữa :v script này chạy trên python 2 và chạy trên linux nha nếu bạn không muốn chạy trên linux thì có thể thay wget thành urllib2.urlopen làm như cách mình lưu ảnh thumbnail để get lyric là dc .
Trở lại vấn đề chính có 1 phần nan giải trong đoạn script trên chính là phần lyric đã được nhaccuatui mã hóa và không thể lấy theo cách bình thường…sau khi tìm hiểu 1 tí thì có cái clip làm thủ công thì mình đã tìm cách viết script python để giải mã đoạn lyric.Cũng không có gì khó khăn đoạn script kia mã hóa hex rồi tới rc4crypt + key => key là Lyr1cjust4nct sau khi tất cả đã xong thì bạn chỉ cần chạy script trên.Những url lưu trong file json listnhac.json

Mọi câu hỏi thắc mắc các bạn có thể để lại bình luận phía bên dưới để được giải đáp (Nếu nhiều bạn không chạy được thì mình sẽ làm video clip hướng dẫn).

Update 20/6/2018

Đây là bản code dành cho windows Kéo xuống cuối bài nhaaaa <3.

1
python +tenfile.py
1
2
3
4
5
6
7
8
[
{
"url" : "https://www.nhaccuatui.com/bai-hat/be-your-everything-boys-like-girls.svT3AyrSuwDu.html"
},
{
"url" : "https://www.nhaccuatui.com/bai-hat/yeu-5-hoaprox-remix-rhymastic-ft-hoaprox.M3U0CaCWI4ig.html"
}
]

Script Lấy Nhạc

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
import re
import requests
import urllib2
import json
import xmltodict
import os


def rc4crypt(data, key):
x = 0
box = range(256)
for i in range(256):
x = (x + box[i] + ord(key[i % len(key)])) % 256
box[i], box[x] = box[x], box[i]
x = 0
y = 0
out = []
for char in data:
x = (x + 1) % 256
y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x]
out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))

return ''.join(out)

def createJson(url):
response = urllib2.urlopen(url)
pagecontent=response.read().decode('utf-8')
pattern = 'https:\/\/www.nhaccuatui.com\/flash\/xml\?html5=true&key1=[a-z,0-9]{30,35}'
result = re.findall(pattern, pagecontent)
response = urllib2.urlopen(result[0])
pagecontent=response.read().decode('utf-8')

data = xmltodict.parse(pagecontent)

tracklistInside = data['tracklist']['track']

songLink = data['tracklist']['track']['location']
lyricLink = data['tracklist']['track']['lyric']
picLink = data['tracklist']['track']['avatar']

print (lyricLink)

#save MP3 File
response = urllib2.urlopen(songLink)
fileMp3 = response.read()
f = open('mp3/'+data['tracklist']['track']['title'], 'wb')
f.write(fileMp3)
f.close()

#save pic File
response = urllib2.urlopen(picLink)
filePic = response.read()
f = open('pic/'+data['tracklist']['track']['title'], 'wb')
f.write(filePic)
f.close()

if lyricLink is not None:
os.system('wget ' + lyricLink + ' -O lyric/encrypted')

lyricencrypted = open('lyric/encrypted').readline()

lyricdecrypted = rc4crypt(lyricencrypted.decode('hex'), 'Lyr1cjust4nct')

f = open('lyric/'+data['tracklist']['track']['title'], 'wb')
f.write(lyricdecrypted)
f.close()

jsondata = json.load(open('music.json'))

res = {}

res['title'] = data['tracklist']['track']['title']
res['author'] = data['tracklist']['track']['creator']
res['url'] = "../mp3/"+data['tracklist']['track']['title']
res['pic'] = "../pic/"+data['tracklist']['track']['title']

if lyricLink is not None:
res['lrc'] = "../lyric/"+data['tracklist']['track']['title']

jsondata.append(res)

with open('music.json', 'w') as outfile:
json.dump(jsondata, outfile)

data = json.load(open('listnhac.json'))

for val in data:
createJson(val['url'])

Code Dành Cho Bản Win

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
import re
import requests
import urllib2
import json
import xmltodict
import os


def rc4crypt(data, key):
x = 0
box = range(256)
for i in range(256):
x = (x + box[i] + ord(key[i % len(key)])) % 256
box[i], box[x] = box[x], box[i]
x = 0
y = 0
out = []
for char in data:
x = (x + 1) % 256
y = (y + box[x]) % 256
box[x], box[y] = box[y], box[x]
out.append(chr(ord(char) ^ box[(box[x] + box[y]) % 256]))

return ''.join(out)

def createJson(url):
response = urllib2.urlopen(url)
pagecontent=response.read().decode('utf-8')
pattern = 'https:\/\/www.nhaccuatui.com\/flash\/xml\?html5=true&key1=[a-z,0-9]{30,35}'
result = re.findall(pattern, pagecontent)
response = urllib2.urlopen(result[0])
pagecontent=response.read().decode('utf-8')

data = xmltodict.parse(pagecontent)

tracklistInside = data['tracklist']['track']

songLink = data['tracklist']['track']['location']
lyricLink = data['tracklist']['track']['lyric']
picLink = data['tracklist']['track']['avatar']

print (lyricLink)

#save MP3 File
response = urllib2.urlopen(songLink)
fileMp3 = response.read()
f = open('mp3/'+data['tracklist']['track']['title'], 'wb')
f.write(fileMp3)
f.close()

#save pic File
response = urllib2.urlopen(picLink)
filePic = response.read()
f = open('pic/'+data['tracklist']['track']['title'], 'wb')
f.write(filePic)
f.close()

#Save and Decrypt Lyric

if lyricLink is not None:

response = urllib2.urlopen(lyricLink)
filelyric = response.read()
f = open('lyric/encrypted', 'wb')
f.write(filelyric)
f.close()

lyricencrypted = open('lyric/encrypted').readline()

lyricdecrypted = rc4crypt(lyricencrypted.decode('hex'), 'Lyr1cjust4nct')

f = open('lyric/'+data['tracklist']['track']['title'], 'wb')
f.write(lyricdecrypted)
f.close()

jsondata = json.load(open('music.json'))

res = {}

res['title'] = data['tracklist']['track']['title']
res['author'] = data['tracklist']['track']['creator']
res['url'] = "../mp3/"+data['tracklist']['track']['title']
res['pic'] = "../pic/"+data['tracklist']['track']['title']

if lyricLink is not None:
res['lrc'] = "../lyric/"+data['tracklist']['track']['title']


jsondata.append(res)

with open('music.json', 'w') as outfile:
json.dump(jsondata, outfile)

data = json.load(open('listnhac.json'))

for val in data:
createJson(val['url'])
Share:

Bitcoin Donation

Học Linux Cùng HellCatVN [01] | Hướng Dẫn Fix Lỗi Sai Thời Gian Khi Dualboot Windows Và Linux
Mycroft Ai [01] Tôi đã đến với mycroft như thế nào?
HellCatVN

Hi,I'm HellCatVN

WelCome To My Website

RSS
46 Project Complete
5 Progarming Languages
Creative Commons

Blog has sprouted 25-12-2015 (●'◡'●)ノ♥

Hosted on GitHub. Google Analytics Provide website statistics service. CloudFlare Provide DNS resolution service

© 2018 Hi, I'm HellCatVN|Theme By NexT v0.0.16. SiteMap

Made with by HellCatVN.