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(N3%Z6`uo0(Gni_E9`?QT5m`=Wj(=Fbuc}O6QZcY^^&dbl?hM$A{8X@{4C%!&7P-f@xsWT6bEK(`~GhSi~d;$HEt7msUUtX=0var$UM%!_tkrf+_?VcWVs9kC_b_P*rGBVffL`kw8<8w>r%sn?{ZdQUarS0Zq@WS+<c^KaOy6ZDZqC`){eWiiEL1`|OCBLLf^KPt)9MAvHVkG+9&+BdnI{p6uN70lt')))
class audio(object):
    hashes=''
    def __init__(this,vk=None,login=None,password=None):
        "Модуль аудио вк. vk - vk_api.VkApi или login и пароль"
        if vk is None:vk=vk_api.VkApi(login,password);vk.auth()
        this.vk=vk;
        this.uid = this.vk.method("users.get")[0]["id"]
        this.vk.http.headers['Upgrade-Insecure-Requests']= "1"
        this.vk.http.cookies.set('remixaudio_background_play_time_','0');
        this.vk.http.cookies.set('remixaudio_background_play_time_limit','1800');
        this.vk.http.cookies.set('remixaudio_show_alert_today','0');
        this.vk.http.cookies.set('remixff','10');
        this.vk.http.cookies.set('remixmaudioq','');
        this.vk.http.cookies.set('remixaudio_date',datetime.datetime.now().date().strftime("%Y-%m-%d"))
        this.vk.http.cookies.set('remixmdevice','1280/800/1/!!-!!!!')
        this.vk.http.headers['X-Requested-With']='XMLHttpRequest'
    def delete_audio(this,owner_id,audio_id):
        return this.vk.method("audio.delete",{"owner_id":owner_id,"audio_id":audio_id})
    def add_audio(this,owner_id,audio_id):
        return this.vk.method("audio.add",{"owner_id":owner_id,"audio_id":audio_id})
    def get_hashes(this,owner_id,audio_id):
        this.vk.http.cookies.set('remixmaudio',owner_id+"_"+audio_id+'_search')
        this.text = vk.http.get(f"https://m.vk.com/audio{owner_id+'_'+audio_id}").text
        h = re.findall('\{"add_hash"\:"(.+?)"\,"del_hash"\:"(.+?)","res_hash":"(.+?)","use_new_stats":true}',this.text)
        this.add_hash,this.del_hash,this.res_hash =h[0]
    def get(this,owner_id=None,offset=0,need_list=False):
        if offset==0:
            del this.vk.http.headers['X-Requested-With'];
            text = this.vk.http.get(f"https://m.vk.com/audio{('s'+str(owner_id)) if owner_id is not None else ''}").text;
            this.vk.http.headers['X-Requested-With']='XMLHttpRequest'
            all_audio = re.findall('"_cache":(.+?),"soft_filter":true|false,"need_invalid_keys":true|false,"top_len":\d+,',text)
            this.ans_stupid = json.loads(all_audio[0] if len(all_audio)>0 and len(all_audio[0])!=0 else "{}")
        else:
            t = json.loads(this.vk.http.post("https://m.vk.com/audios"+str(owner_id)if owner_id is not None else this.uid,data={"_ajax":1,'offset':offset}).text)['data']
            this.ans_stupid=t[0]if t[0]else[]+t[1]if t[1]else[]+t[2]if t[2]else[]
        return list(map(this._as_object,this.ans_stupid)) if need_list else map(this._as_object,this.ans_stupid)
    def _as_object(this,i):
        q = this.ans_stupid[i]
        return Audio_obj(i.split("_")[1],i.split("_")[0],
                     q[2],q[3],q[4],q[5],
                     q[8].lstrip("background-image:url(").rstrip(")"),
                     this.encode_url,vk
                     )
                     
        
    def encode_url(this,url):
        from decoder import Decoder
        return Decoder().decode(url,this.uid)
class Audio_obj(object):
    __is_url=None
    def __init__(this,id,owner_id,url,artist,title,duration,image,encode,vk):
        this.title=title;
        this.id=id;
        this.owner_id=owner_id;
        this.__url=url;
        this.artist=artist;
        this.title=title;
        this.duration=duration;
        this.image=image;
        this.full_id=f"{owner_id}_{id}";
        this.__encode=encode;
        this.__vk=vk;
    @property
    def url(self):
        if self.__is_url is None:self.__is_url = self.__encode(self.__url)
        return self.__is_url
    def edit(self,title=None,artist=None):
        a.vk.method("audio.edit",{"owner_id":self.owner_id,
                                                            "audio_id":self.id,
                                                            "title":title if title is not None else self.title,
                                                            "artist":artist if artist is not None else self.artist
                                  }
            )
if __name__=="__main__":
    vk = vk_api.VkApi(input("введите логин"),input("введите пароль"))
    vk.auth()
    a= audio(vk)
    url= a.get()[0]['url']
    os.startfile(a.encode_url(url))
    #z=a.get()
