Last active
August 29, 2015 14:26
-
-
Save hisinsub/ceeddf6d48cad5e1543c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import hashlib | |
import urllib2 | |
import xml.dom.minidom as xml | |
ALSONG_URL = "http://lyrics.alsong.net/alsongwebservice/service1.asmx" | |
ALSONG_TMPL = '''\ | |
<?xml version="1.0" encoding="UTF-8"?> | |
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="ALSongWebServer/Service1Soap" xmlns:ns1="ALSongWebServer" xmlns:ns3="ALSongWebServer/Service1Soap12"> | |
<SOAP-ENV:Body> | |
<ns1:GetLyric5> | |
<ns1:stQuery> | |
<ns1:strChecksum>%s</ns1:strChecksum> | |
<ns1:strVersion>2.2</ns1:strVersion> | |
<ns1:strMACAddress /> | |
<ns1:strIPAddress /> | |
</ns1:stQuery> | |
</ns1:GetLyric5> | |
</SOAP-ENV:Body> | |
</SOAP-ENV:Envelope> | |
''' | |
file = u"임재범 - 사랑이라서.mp3" | |
# 이 구간이 문제인데요... | |
f = open(file, 'rb') | |
data = f.read(160*1024) | |
# 첫 160kb 를 어떻게 읽어드리는 지를 잘 모르겠습니다. | |
m = hashlib.md5() | |
m.update(data) | |
strChecksum = m.hexdigest() | |
print strChecksum | |
# Make a request string | |
headers = { 'Content-Type': 'text/xml; charset=utf-8' } | |
request = urllib2.Request(ALSONG_URL, ALSONG_TMPL % key, headers) | |
# Print Alsong's response | |
response = urllib2.urlopen(request) | |
print response.read() |
일단 ID3가 뭔가, 구조가 어떻게 되나, 공부하면 이해가 빠를듯,,ㅋ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
답변 너무 감사드립니다.
네, 사실 그걸 파이썬으로 어떻게 하는지 몰라서 검색해봤는데, 잘 안나오는거 같아요. 제일 가능성있는 글이 요건데요, http://stackoverflow.com/questions/16634128/how-to-extract-the-raw-data-from-a-mp3-file-using-python
여기의 답변과 같이 pydub 이라는 라이브러리를 써서 ._data 를 읽어드리면 될거 같은데 (맞을까요?), 요 방법도 예전에 한번 해봤는데 안됐거든요. 다시 한번 해봐야겠네요. 안되면, C#을 배워봐야겠네요.. 아직은 파이썬이랑 자바스크립트밖에 모르거든요, 흑..