diff --git a/build/lib/tiktok_downloader/__main__.py b/build/lib/tiktok_downloader/__main__.py index fb64ed0..65b50f7 100644 --- a/build/lib/tiktok_downloader/__main__.py +++ b/build/lib/tiktok_downloader/__main__.py @@ -1,4 +1,5 @@ import argparse,json, os +import sys, requests from .ssstik import ssstik from .snaptik import snaptik from .scrapper import info_post @@ -9,7 +10,7 @@ arg.add_argument('--info', action='store_true') arg.add_argument('--url') arg.add_argument('--server', action='store_true') -arg.add_argument('--host', type=str, default='0.0.0.0') +arg.add_argument('--host', type=str, default='127.0.0.1') arg.add_argument('--debug', action='store_true') arg.add_argument('--port', default=8000, type=int) arg.add_argument('--json', action='store_true') @@ -27,10 +28,11 @@ elif parse.save: ok[0].download(parse.save) else: - os.system(f"python3 -m {os.path.dirname(__file__).split('/')[-1]} --help") - except Exception: + os.system(f"python3 -m tiktok_downloader --help") + except Exception as e: stderr.write('Post Not Found\n') stderr.flush() + sys.exit(1) elif parse.info: try: resp=info_post(parse.url) @@ -48,11 +50,15 @@ 'create':resp.create.timestamp(), 'url':resp.url, 'id':resp.id }, indent=4)) - except Exception as e: - print(e) + except requests.exceptions.ConnectionError: + stderr.write('[x] offline\n') + stderr.flush() + sys.exit(1) + except (KeyError, AttributeError): stderr.write('Post Not Found\n') stderr.flush() + sys.exit(1) else: - os.system(f"python3 -m {os.path.dirname(__file__).split('/')[-1]} --help") + os.system(f"python3 -m tiktok_downloader --help") else: - os.system(f"python3 -m {os.path.dirname(__file__).split('/')[-1]} --help") \ No newline at end of file + os.system(f"python3 -m tiktok_downloader --help") \ No newline at end of file diff --git a/build/lib/tiktok_downloader/scrapper.py b/build/lib/tiktok_downloader/scrapper.py index 81017bd..09a985d 100644 --- a/build/lib/tiktok_downloader/scrapper.py +++ b/build/lib/tiktok_downloader/scrapper.py @@ -7,11 +7,11 @@ from tiktok_downloader.keeptiktok import keeptiktok from tiktok_downloader.utils import info_videotiktok class info_post(requests.Session): + ''' + :param url: video url(tiktok) + ''' def __init__(self, url: str) -> None: super().__init__() - ''' - :param url: video url(tiktok) - ''' self.headers={"sec-ch-ua": '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',"sec-ch-ua-mobile": "?0","sec-ch-ua-platform": "Linux","sec-fetch-dest": "document","sec-fetch-mode": "navigate","sec-fetch-site": "none","sec-fetch-user": "?1","upgrade-insecure-requests": "1","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"} self.html = self.get(url) self.js = json.loads(re.search(r'\>(\{\"props\":.*?)\<\/script>',self.html.text).group(1)) @@ -45,56 +45,3 @@ def __repr__(self) -> str: return f"<(OWNER:{self.username} VERIFIED:{self.verified})>" def __str__(self) -> str: return self.__repr__() -class tiktok: - def __init__(self, url) -> None: - self.request = Session() - self.header = {"content-type": "application/x-www-form-urlencoded; charset=UTF-8","hx-active-element": "submit","hx-current-url": "https://ssstik.io/","hx-request": "true","hx-target": "target","origin": "https://ssstik.io","sec-fetch-dest": "","sec-fetch-mode": "cors","sec-fetch-site": "same-origin","user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"} - self.url = "https://ssstik.io" - self.html = self.request.get(self.url, headers=self.header).text - #self.key = BeautifulSoup(self.html, "html.parser").find_all("form",attrs={"data-hx-target":"#target"})[0].get("include-vals") - #self.post = BeautifulSoup(self.html, "html.parser").find_all("form",attrs={"data-hx-target":"#target"})[0].get("data-hx-post") - #self.tt = re.search("tt\:\'(.*?)\'",self.key)[1] - #self.ts = re.search("ts\:([0-9]{5,15})",self.key)[1] - self.url_vid = url - - def get_info(self): - try: - data = {"id": self.url_vid,"locale": "en","tt": 0,"ts": 0} - post = self.request.post(self.url+re.findall('data-hx-post=\"(.*?)\"',self.html)[0], headers=self.header, data=data) - respon = BeautifulSoup(post.text, "html.parser") - #return post - self.hasil = {"video":[f'{self.url}{respon.find_all("a",class_="pure-button pure-button-primary is-center u-bl dl-button download_link without_watermark")[0].get("href")}',f'{self.url}{respon.find_all("a",class_="pure-button pure-button-primary is-center u-bl dl-button download_link without_watermark_direct")[0].get("href")}'],"music":f'{respon.find_all("a",class_="pure-button pure-button-primary is-center u-bl dl-button download_link music")[0].get("href")}'} - return [info_videotiktok(x, self.header, self.request) for x in self.hasil["video"]] - except IndexError: - raise InvalidUrl("URL ERROR") - def __str__(self) -> str: - return "<[ Method: ssstik.io ]>" - def __repr__(self) -> str: - return self.__str__() -class tiktok2: - def __init__(self, url) -> None: - self.request = Session() - self.url = url - self.header = {"accept": "*/*","accept-language": "en-US,en;q=0.9,id;q=0.8","origin": "https://snaptik.app","referer": "https://snaptik.app/ID","sec-fetch-dest": None,"sec-fetch-mode": "cors","sec-fetch-site": "same-origin","user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",} - def get_info(self): - try: - self.request.post("https://snaptik.app/check_token.php", headers=self.header) - self.php = re.findall(r', \"(.*?\.php)',requests.get("https://snaptik.app", headers=self.header).text)[0] - self.bs = BeautifulSoup(self.request.post(f"https://snaptik.app/{self.php}", headers=self.header, data={"url":self.url}).text, "html.parser") - self.hasil=[self.request,{"title":self.bs('a', attrs={"title":""})[0].text,"date":self.bs("b", attrs={"class":"blur"})[0].text,"video":list(filter(lambda x:x, map(lambda x:x["href"] if "token" in x["href"] else None, self.bs("a", attrs={"class":"abutton is-success is-fullwidth"}))))}, self.header] - return [info_videotiktok(x, self.header, self.request) for x in self.hasil[1]["video"]] - except IndexError: - raise InvalidUrl("URL ERROR") - def __str__(self) -> str: - return "<[ Method: Snaptik.io ]>" - def __repr__(self) -> str: - return self.__str__() -class Tiktok: - info_video = info_post - ssstik = tiktok - snaptik = tiktok2 - keeptiktok = keeptiktok - def __str__(self) -> str: - return "<[ Tiktok Downloader No Watermark Scraper]>" - def __repr__(self) -> str: - return self.__str__() \ No newline at end of file diff --git a/build/lib/tiktok_downloader/server.py b/build/lib/tiktok_downloader/server.py index d295327..af7dfec 100644 --- a/build/lib/tiktok_downloader/server.py +++ b/build/lib/tiktok_downloader/server.py @@ -1,7 +1,6 @@ from flask import Flask, request,render_template from . import info_post, snaptik, ssstik import json, os -print(os.path.abspath(__file__+'/../static')) app = Flask(__name__, template_folder=os.path.abspath(__file__+'/../templates'), static_folder=os.path.abspath(__file__+'/../static')) @app.route('/') def index(): @@ -54,7 +53,7 @@ def snapt(path): return json.dumps({ 'msg':'url tidak valid' }) - elif not path in ['snaptik', 'ssstik']: + elif path not in ['snaptik', 'ssstik']: return json.dumps({'msg':'path tidak ditemukan'}) if request.args.get('url'): try: diff --git a/build/lib/tiktok_downloader/snaptik.py b/build/lib/tiktok_downloader/snaptik.py index 40a5906..a9c32b7 100644 --- a/build/lib/tiktok_downloader/snaptik.py +++ b/build/lib/tiktok_downloader/snaptik.py @@ -1,4 +1,5 @@ from sys import stderr +from ast import literal_eval from .utils import info_videotiktok from py_mini_racer import MiniRacer from .Except import InvalidUrl @@ -28,7 +29,7 @@ def get_media(self)->list[info_videotiktok]: ``` ''' stderr.flush() - d=eval(findall(r'\(\".*?,.*?,.*?,.*?,.*?.*?\)',self.resp.text)[0]).__str__() + d=literal_eval(findall(r'\(\".*?,.*?,.*?,.*?,.*?.*?\)',self.resp.text)[0]).__str__() dec = self.decoder.eval(f"decoder{d}") stderr.flush() return [info_videotiktok(i, self) for i in set(map(lambda x:x[0].strip('\\'),findall(r'\"(https?://(tikcdn\.net|snapsave\.info).*?)\"',dec)))] \ No newline at end of file diff --git a/build/lib/tiktok_downloader/templates/index.html b/build/lib/tiktok_downloader/templates/index.html index 5f73845..97e5644 100644 --- a/build/lib/tiktok_downloader/templates/index.html +++ b/build/lib/tiktok_downloader/templates/index.html @@ -43,7 +43,14 @@ if(!data.msg){ $.ajax({url:'/snaptik',data:{url:tiktok},success: function (datasx){ const datas = JSON.parse(datasx) - let block = ` + if(datas.msg){ + Swal.fire({ + icon: 'error', + title: 'Oops...', + text: 'Server Sibuk' + }) + }else{ + let block = `