Skip to content

Commit

Permalink
gh
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Oct 21, 2021
1 parent 738a3b7 commit bfe79bf
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 72 deletions.
20 changes: 13 additions & 7 deletions build/lib/tiktok_downloader/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse,json, os
import sys, requests
from .ssstik import ssstik
from .snaptik import snaptik
from .scrapper import info_post
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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")
os.system(f"python3 -m tiktok_downloader --help")
59 changes: 3 additions & 56 deletions build/lib/tiktok_downloader/scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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__()
3 changes: 1 addition & 2 deletions build/lib/tiktok_downloader/server.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion build/lib/tiktok_downloader/snaptik.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))]
10 changes: 9 additions & 1 deletion build/lib/tiktok_downloader/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<div class="row justify-content-center" id="downgrup" style="padding-bottom: 100px;">
<div class="card" style="width: 20 rem;">
<img src="${data.cover}" class="card-img-top" alt="..." style="padding-top:7px;">
Expand All @@ -58,6 +65,7 @@ <h5 class="card-title">${data.account.nickname}</h5>
</div>
`
$(".emptydiv").empty().append(block)
}
}})
}else{
Swal.fire({
Expand Down
17 changes: 17 additions & 0 deletions build/lib/tiktok_downloader/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
from .scrapper import info_post
from .snaptik import snaptik
from .ssstik import ssstik
class TikTok(unittest.TestCase):
base_url = 'https://www.tiktok.com/@tribunsumselcom/video/7020708969563917595'
def test_snaptk(self):
self.assertTrue(snaptik(self.base_url).get_media())

def test_sstkio(self):
self.assertTrue(ssstik().get_media(self.base_url))

def test_info(self):
self.assertTrue(info_post(self.base_url).js)

if __name__ == '__main__':
unittest.main()
5 changes: 4 additions & 1 deletion resetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
arg.add_argument('--version',type=str)
args=arg.parse_args()
if args.version:
print(open('setup.py').read().replace('0.1.6',re.search(r'\/?([0-9\.]+)',args.version).group(1)))
new=open('setup.py').read().replace('0.1.6',re.search(r'\/?([0-9\.]+)',args.version).group(1))
with open('setup.py','w') as fil:
print(new)
fil.write(new)
10 changes: 6 additions & 4 deletions tiktok_downloader.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Metadata-Version: 1.1
Metadata-Version: 2.1
Name: tiktok-downloader
Version: 0.1.4
Version: 0.1.6
Summary: Tiktok Downloader&Scraper using bs4&requests
Home-page: https://github.com/krypton-byte/tiktok_downloader
Author: Krypton Byte
Author-email: [email protected]
License: MIT
Download-URL: https://github.com/krypton-byte/tiktok_downloader/archive/0.0.7.tar.gz
Description: UNKNOWN
Download-URL: https://codeload.github.com/krypton-byte/tiktok-downloader/tar.gz/refs/tags/0.1.6
Keywords: tiktok,downloader,scrapper,tikdok-scraper,tiktok-downloader
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Expand All @@ -16,3 +15,6 @@ Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9

UNKNOWN

1 change: 1 addition & 0 deletions tiktok_downloader.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tiktok_downloader/scrapper.py
tiktok_downloader/server.py
tiktok_downloader/snaptik.py
tiktok_downloader/ssstik.py
tiktok_downloader/test.py
tiktok_downloader/utils.py
tiktok_downloader.egg-info/PKG-INFO
tiktok_downloader.egg-info/SOURCES.txt
Expand Down

0 comments on commit bfe79bf

Please sign in to comment.