Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Dec 26, 2021
1 parent 24af7eb commit a6a6313
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 88 deletions.
138 changes: 73 additions & 65 deletions tiktok_downloader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import os
import sys
import requests
from .ssstik import ssstik
from .snaptik import snaptik
from .ssstik import Ssstik
from .snaptik import Snaptik
from .mdown import Mdown
from .tikmate import Tikmate
from .scrapper import info_post
from sys import stderr

Expand All @@ -15,8 +17,10 @@
)
arg.add_argument('--snaptik', action='store_true')
arg.add_argument('--ssstik', action='store_true')
arg.add_argument('--mdown', action='store_true')
arg.add_argument('--tikmate', action='store_true')
arg.add_argument('--info', action='store_true')
arg.add_argument('--url', type=str, required=True)
arg.add_argument('--url', type=str)
arg.add_argument('--server', action='store_true')
arg.add_argument('--host', type=str, default='127.0.0.1')
arg.add_argument('--debug', action='store_true')
Expand All @@ -28,72 +32,76 @@
from .server import app
app.run(host=parse.host, port=parse.port, debug=bool(parse.debug))
elif parse.url:
if parse.snaptik or parse.ssstik:
try:
ok = snaptik(
parse.url
).get_media() if parse.snaptik else ssstik().get_media(
parse.url
)
if parse.json or not(parse.save):
print(
json.dumps(
[
{
'type': i.type,
'url': i.json
} for i in ok
],
indent=4
)
)
elif parse.save:
ok[0].download(parse.save)
else:
os.system("python3 -m tiktok_downloader --help")
except Exception as e:
print(e)
stderr.write('Post Not Found\n')
stderr.flush()
sys.exit(1)
elif parse.info:
try:
resp = info_post(parse.url)
service = (
(
parse.snaptik and Snaptik
) or (
parse.ssstik and Ssstik
) or (
parse.tikmate and Tikmate
) or (
parse.mdown and Mdown
) or Snaptik
)
try:
ok = service(parse.url)
if parse.json or not(parse.save):
print(
json.dumps(
{
'account': {
'avatar': resp.account.avatar,
'username': resp.account.username,
'nickname': resp.account.nickname,
'signature': resp.account.signature,
'create': (
(
resp.account.create
and
resp.account.create.timestamp()
) or 0),
'verified': resp.account.verified
},
'music': resp.music,
'cover': resp.cover,
'caption': resp.caption,
'create': resp.create.timestamp(),
'url': resp.url,
'id': resp.id
},
[
{
'type': i.type,
'url': i.json
} for i in ok
],
indent=4
)
)
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("python3 -m tiktok_downloader --help")
elif parse.save:
ok[0].download(parse.save)
else:
os.system("python3 -m tiktok_downloader --help")
except Exception as e:
print(e)
stderr.write('Post Not Found\n')
stderr.flush()
sys.exit(1)
elif parse.info:
try:
resp = info_post(parse.url)
print(
json.dumps(
{
'account': {
'avatar': resp.account.avatar,
'username': resp.account.username,
'nickname': resp.account.nickname,
'signature': resp.account.signature,
'create': (
(
resp.account.create
and
resp.account.create.timestamp()
) or 0),
'verified': resp.account.verified
},
'music': resp.music,
'cover': resp.cover,
'caption': resp.caption,
'create': resp.create.timestamp(),
'url': resp.url,
'id': resp.id
},
indent=4
)
)
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("python3 -m tiktok_downloader --help")
Binary file modified tiktok_downloader/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified tiktok_downloader/__pycache__/__main__.cpython-39.pyc
Binary file not shown.
Binary file modified tiktok_downloader/__pycache__/decoder.cpython-39.pyc
Binary file not shown.
Binary file modified tiktok_downloader/__pycache__/mdown.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file modified tiktok_downloader/__pycache__/snaptik.cpython-39.pyc
Binary file not shown.
Binary file modified tiktok_downloader/__pycache__/ssstik.cpython-39.pyc
Binary file not shown.
Binary file modified tiktok_downloader/__pycache__/tikmate.cpython-39.pyc
Binary file not shown.
18 changes: 13 additions & 5 deletions tiktok_downloader/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@

alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/"


def search(d: Union[str, list], q: Union[str, int]):
try:
return d.index(q)
except:
except Exception:
return -1


def main(d, e, f):
g = list(alpha)
h = g[0:e]
i = g[0:f]

def freduce(a, b, c):
if search(h, b) != -1:
a += search(h, b) * (e ** c)
Expand All @@ -26,27 +29,32 @@ def freduce(a, b, c):
j = int((j - (j % f)) / f)
return int(k) or 0

def reduces(function, iterable, initializer = None): #modified reduce function like js :https://www.geeksforgeeks.org/reduce-in-python/

def reduces(function, iterable, initializer=None):
"""
[!] modified reduce function like js
:https://www.geeksforgeeks.org/reduce-in-python/
"""
it = iter(iterable)
if initializer is None:
value = next(it)
else:
value = function(initializer, next(it), 0)
for index, element in enumerate(it, 1):
for index, element in enumerate(it, 1):
value = function(value, element, index)
return value


def decoder(h, u, n, t, e, r):
r = ""
i = 0
while i < h.__len__():
s = ""
while h[i] != n[e]:
s += h[i]
i+=1
i += 1
for j in range(n.__len__()):
s = s.replace(n[j], j.__str__())
r += chr(main(s, e, 10) - t)
i += 1
return r

4 changes: 4 additions & 0 deletions tiktok_downloader/mdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ def get_media(self, url: str):
'html.parser'
).find_all('a', attrs={'target': '_blank'})
]


def Mdown(url: str):
return mdown().get_media(url)
29 changes: 13 additions & 16 deletions tiktok_downloader/server.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from . import mdown
from flask import (
Flask,
request,
render_template,
Response
)
from . import (
info_post,
snaptik,
ssstik,
tikmate
)
from .mdown import Mdown
from .snaptik import Snaptik
from .ssstik import Ssstik
from .tikmate import Tikmate
from .scrapper import info_post
import json
import os


app = Flask(
__name__,
template_folder=os.path.abspath(__file__+'/../templates'),
Expand Down Expand Up @@ -76,15 +75,13 @@ def snapt(path):
return json.dumps({'msg': 'path tidak ditemukan'})
if request.args.get('url'):
try:
res = []
if path == 'snaptik':
res = snaptik(request.args['url']).get_media()
elif path == 'ssstik':
res = ssstik().get_media(request.args['url'])
elif path == 'tikmate':
res = tikmate().get_media(request.args['url'])
elif path == 'mdown':
res = mdown().get_media(request.args['url'])
service = ({
'snaptik': Snaptik,
'ssstik': Ssstik,
'tikmate': Tikmate,
'mdown': Mdown
}).get(path, Snaptik)
res = service(request.args['url'])
return Response(
json.dumps(
[
Expand Down
7 changes: 5 additions & 2 deletions tiktok_downloader/snaptik.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .Except import InvalidUrl
from requests import Session
from re import findall
from os.path import dirname
from .decoder import decoder


Expand Down Expand Up @@ -46,7 +45,7 @@ def get_media(self) -> list[info_videotiktok]:
self.resp.text
)[0]
))

stderr.flush()
return [
info_videotiktok(
Expand All @@ -66,3 +65,7 @@ def get_media(self) -> list[info_videotiktok]:

def __iter__(self):
yield from self.get_media()


def Snaptik(url: str):
return snaptik(url).get_media()
4 changes: 4 additions & 0 deletions tiktok_downloader/ssstik.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ def get_media(self, url: str) -> list[info_videotiktok]:
return hasil
except IndexError:
raise InvalidURL()


def Ssstik(url: str, delay=10):
return ssstik(delay).get_media(url)
4 changes: 4 additions & 0 deletions tiktok_downloader/tikmate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ def get_media(self, url: str) -> list[info_videotiktok]:
decode
)
]


def Tikmate(url: str):
return tikmate().get_media(url)

0 comments on commit a6a6313

Please sign in to comment.