diff --git a/youtube_dl/downloader/deezer.py b/youtube_dl/downloader/deezer.py new file mode 100644 index 000000000..882e10a1e --- /dev/null +++ b/youtube_dl/downloader/deezer.py @@ -0,0 +1,40 @@ +from Crypto.Cipher import Blowfish +import binascii + +from .common import FileDownloader + +from ..utils import sanitized_Request + +def blowfishDecrypt(data, key): + """ CBC decrypt data with key """ + c = Blowfish.new(key, Blowfish.MODE_CBC, binascii.a2b_hex("0001020304050607")) + return c.decrypt(data) + + +def decryptfile(fh, key, fo): + """ + Decrypt data from file , and write to file . + decrypt using blowfish with . + Only every third 2048 byte block is encrypted. + """ + i = 0 + while True: + data = fh.read(2048) + if not data: + break + + if (i % 3)==0 and len(data)==2048: + data = blowfishDecrypt(data, key) + fo.write(data) + i += 1 + + +class DeezerDownloader(FileDownloader): + def real_download(self, filename, info_dict): + url = info_dict['url'] + request = sanitized_Request(url, None, {}) + data = self.ydl.urlopen(request) + + with open(filename, "wb") as fo: + decryptfile(data, info_dict['key'], fo) +