예제 #1
0
 def download(self, track, location, quality, check, datas):
     if not quality in qualities:
      raise QualityNotFound("The qualities have to be FLAC or MP3_320 or MP3_256 or MP3_128")
     ids = track.split("/")[-1]
     def login():
         self.token = self.get_api("deezer.getUserData")['checkForm']
         return self.get_api("song.getData", self.token, {"sng_id": ids})
     def add_more_tags(datas, infos):
         image = request("https://e-cdns-images.dzcdn.net/images/cover/" + infos['ALB_PICTURE'] + "/1200x1200-000000-80-0-0.jpg").content
         if len(image) == 13:
          image = request("https://e-cdns-images.dzcdn.net/images/cover/1200x1200-000000-80-0-0.jpg").content
         datas['image'] = image
         try:
            datas['author'] = " & ".join(infos['SNG_CONTRIBUTORS']['author'])
         except:
            datas['author'] = ""
         try:
            datas['composer'] = " & ".join(infos['SNG_CONTRIBUTORS']['composer'])
         except:
            datas['composer'] = ""
         try:
            datas['lyricist'] = " & ".join(infos['SNG_CONTRIBUTORS']['lyricist'])
         except:
            datas['lyricist'] = ""
         try:
            datas['version'] = infos['VERSION']
         except KeyError:
            datas['version'] = ""
         need = self.get_api("song.getLyrics", self.token, {"sng_id": ids})
         try:
            datas['lyric'] = need['LYRICS_TEXT']
            datas['copyright'] = need['LYRICS_COPYRIGHTS']
            datas['lyricist'] = need['LYRICS_WRITERS']
         except KeyError:
            datas['lyric'] = ""
            datas['copyright'] = ""
            datas['lyricist'] = ""
         return datas
     infos = login()
     while not "MD5_ORIGIN" in str(infos):
         infos = login()
     extension = ".mp3"
     if int(infos['FILESIZE_' + quality]) > 0 and quality == "FLAC":
      quality = "9"
      extension = ".flac"
      qualit = "FLAC"
     elif int(infos['FILESIZE_' + quality]) > 0 and quality == "MP3_320":
      quality = "3"
      qualit = "320"
     elif int(infos['FILESIZE_' + quality]) > 0 and quality == "MP3_256":
      quality = "5"
      qualit = "256"
     elif int(infos['FILESIZE_' + quality]) > 0 and quality == "MP3_128":
      quality = "1"
      qualit = "128"
     else:
         if check == True:
          raise QualityNotFound("The quality chosen can't be downloaded")
         for a in qualities:
             if int(infos['FILESIZE_' + a]) > 0:
              quality = qualities[a]['quality']
              extension = qualities[a]['extension']
              qualit = qualities[a]['qualit']
              break
             else:
                 if a == "MP3_128":
                  raise TrackNotFound("There isn't any quality avalaible for download this song")
     try:
        md5 = infos['FALLBACK']['MD5_ORIGIN']
     except KeyError:
        md5 = infos['MD5_ORIGIN']
     hashs = genurl(md5, quality, ids, infos['MEDIA_VERSION'])
     try:
        crypt = request("https://e-cdns-proxy-%s.dzcdn.net/mobile/1/%s" % (md5[0], hashs))
     except IndexError:
        raise TrackNotFound("Track not found :(")
     if len(crypt.content) == 0:
      raise TrackNotFound("Error with this track :(")
     open(location + ids, "wb").write(crypt.content)
     decry = open(location + ids, "wb")
     decryptfile(crypt.iter_content(2048), calcbfkey(ids), decry)
     datas = add_more_tags(datas, infos)
     return extension, qualit, datas
예제 #2
0
        def ultimatum(infos, datas, name, quality):
            extension = ".mp3"
            ids = infos['SNG_ID']
            key = "FILESIZE_" + quality

            if int(infos[key]) > 0 and quality == "FLAC":
                quality = "9"
                extension = ".flac"
                qualit = "FLAC"

            elif int(infos[key]) > 0 and quality == "MP3_320":
                quality = "3"
                qualit = "320"

            elif int(infos[key]) > 0 and quality == "MP3_256":
                quality = "5"
                qualit = "256"

            elif int(infos[key]) > 0 and quality == "MP3_128":
                quality = "1"
                qualit = "128"

            else:
                if not recursive_quality:
                    raise exceptions.QualityNotFound(
                        "The quality chosen can't be downloaded")

                for a in qualities:
                    if int(infos['FILESIZE_' + a]) > 0:
                        quality = qualities[a]['quality']
                        extension = qualities[a]['extension']
                        qualit = qualities[a]['qualit']
                        break
                    else:
                        if a == "MP3_128":
                            raise exceptions.TrackNotFound(
                                "There isn't any quality avalaible for download this song: %s"
                                % name)

            name += " ({}){}".format(qualit, extension)

            if os.path.isfile(name):
                if recursive_download:
                    return name

                ans = input(
                    "Track %s already exists, do you want to redownload it?(y or n):"
                    % name)

                if not ans in answers:
                    return name

            try:
                md5 = infos['FALLBACK']['MD5_ORIGIN']
            except KeyError:
                md5 = infos['MD5_ORIGIN']

            hashs = genurl(md5, quality, ids, infos['MEDIA_VERSION'])

            try:
                crypt = request(
                    "https://e-cdns-proxy-{}.dzcdn.net/mobile/1/{}".format(
                        md5[0], hashs))
            except IndexError:
                raise exceptions.TrackNotFound("Track: %s not found:(" % name)

            if len(crypt.content) == 0:
                raise exceptions.TrackNotFound(
                    "Something is wrong with %s :(" % name)

            encry = open(name, "wb")
            encry.write(crypt.content)
            encry.close()
            decry = open(name, "wb")

            decryptfile(crypt.iter_content(2048), calcbfkey(ids), decry)

            write_tags(name, add_more_tags(datas, infos, ids))

            return name
예제 #3
0
 def ultimatum(infos, name, datas, quality, recursive_download,
               recursive_quality):
     extension = ".mp3"
     ids = infos['SNG_ID']
     if int(infos['FILESIZE_' + quality]) > 0 and quality == "FLAC":
         quality = "9"
         extension = ".flac"
         qualit = "FLAC"
     elif int(
             infos['FILESIZE_' + quality]) > 0 and quality == "MP3_320":
         quality = "3"
         qualit = "320"
     elif int(
             infos['FILESIZE_' + quality]) > 0 and quality == "MP3_256":
         quality = "5"
         qualit = "256"
     elif int(
             infos['FILESIZE_' + quality]) > 0 and quality == "MP3_128":
         quality = "1"
         qualit = "128"
     else:
         if recursive_quality:
             raise QualityNotFound(
                 "The quality chosen can't be downloaded")
         for a in qualities:
             if int(infos['FILESIZE_' + a]) > 0:
                 quality = qualities[a]['quality']
                 extension = qualities[a]['extension']
                 qualit = qualities[a]['qualit']
                 break
             else:
                 if a == "MP3_128":
                     raise TrackNotFound(
                         "There isn't any quality avalaible for download this song"
                     )
     name += " (" + qualit + ")" + extension
     if os.path.isfile(name):
         if not recursive_download:
             return name
         ans = input(
             "Track " + name +
             " already exists, do you want to redownload it?(y or n):")
         if ans != "y":
             return name
     try:
         md5 = infos['FALLBACK']['MD5_ORIGIN']
     except KeyError:
         md5 = infos['MD5_ORIGIN']
     hashs = genurl(md5, quality, ids, infos['MEDIA_VERSION'])
     try:
         crypt = request(
             "https://e-cdns-proxy-%s.dzcdn.net/mobile/1/%s" %
             (md5[0], hashs))
     except IndexError:
         raise TrackNotFound("Track not found :(")
     if len(crypt.content) == 0:
         raise TrackNotFound("Error with this track :(")
     open(name, "wb").write(crypt.content)
     decry = open(name, "wb")
     decryptfile(crypt.iter_content(2048), calcbfkey(ids), decry)
     datas = add_more_tags(datas, infos, ids)
     write_tags(name, datas)
     return name