GithubHelp home page GithubHelp logo

krypton-byte / tiktok-downloader Goto Github PK

View Code? Open in Web Editor NEW
271.0 8.0 82.0 2.71 MB

Tiktok Downloader/Scraper using requests & bs4

Home Page: https://tiktok-dl.id

License: GNU General Public License v3.0

Python 85.34% HTML 5.26% JavaScript 9.29% Procfile 0.11%
tiktok downloader without watermark requests bs4 beautifulsoup krypton-byte flask web

tiktok-downloader's Introduction


Unittest Upload to PyPi Downloads viitor

install

> python3 -m pip install tiktok_downloader
> python3 -m pip install git+https://github.com/krypton-byte/tiktok-downloader

Library

Tikmate
>>> from tiktok_downloader import Tikmate
>>> d=Tikmate("url")
[<[type: "video" watermark: False]>, <[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
Snaptik
>>> from tiktok_downloader import snaptik
>>> d=snaptik('https://vt.tiktok.com/xxxxxx/')
>>> d
[<[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
Musically Down
>>> from tiktok_downloader import mdown
>>> d=mdown('https://vt.tiktok.com/xxxxxx/')
>>> d
[<[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
Tikdown
>>> from tiktok_downloader import tikdown
>>> d=tikdown('https://vt.tiktok.com/xxxxxx/')
>>> d
[<[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
TTDownloader
>>> from tiktok_downloader import ttdownloader
>>> d=ttdownloader('https://vt.tiktok.com/xxxxxx/')
>>> d
[<[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
Tikwm
>>> from tiktok_downloader import tikwm
>>> d=tikwm('https://vt.tiktok.com/xxxxxx/')
>>> d
[<[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
Tiktok
>>> from tiktok_downloader import VideoInfo
>>> d=VideoInfo.service('https://vt.tiktok.com/xxxxxx/')
>>> d
[<[type: "video" watermark: False]>]
>>> d[0].download('video.mp4')
Get Info
>>> from tiktok_downloader import VideoInfo
>>> VideoInfo.get_info('https://vt.tiktok.com/xxxxxx/')

Command line

usage: python3 -m tiktok_downloader [-h] [--snaptik | --ssstik | --tikmate | --mdown | --ttdownloader | --tikwm | --tikdown | --tiktok] [--host HOST] [--debug] [--port PORT] (--server | --url URL) [--info] [--json | --save SAVE]

Tiktok Downloader [CLI]

options:
  -h, --help      show this help message and exit

List Of Services:
  --snaptik
  --ssstik
  --tikmate
  --mdown
  --ttdownloader
  --tikdown
  --tikwm
  --tiktok

Web Configuration:
  --host HOST     Set host to run this web
  --debug         Set flask mode to debug
  --port PORT     Set port

Mode:
  --server        Run as web application
  --url URL       Video URL

Optional:
  --info          Print info video like author, id & etc

Output Type:
  --json          Print result to json format
  --save SAVE     Write the result to file

Example CLI

Download
$ python3 -m tiktok_downloader --url https://vt.tiktok.com/lorem --snaptik --save tiktok.mp4
Json
$ python3 -m tiktok_downloader --url https://vt.tiktok.com/lorem --snaptik --json
Run as web
$ python3 -m tiktok_downloader --host=0.0.0.0 --port=8000 --server
 * Serving Flask app 'tiktok_downloader.server' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Deploy Heroku

Deploy

Preview

Request API using curl & wget

$ wget -O result.mp4 $(curl -sG http://127.0.0.1:8000/snaptik -d url=https://vm.tiktok.com/xxxxxxxx/|jq .[0].url -r)

you can direct Download using browser or curl

http://127.0.0.1:8000/snaptik?url=https://vm.tiktok.com/xxxxxxxx/&type=embed

Endpoint

Name Endpoint Status
Snaptik /snaptik
Tikmate /tikmate
MusicalDown /mdown
ssstik /ssstik
ttdownloader /ttdownloader
tikwm /tikwm
tikdown /tikdown x
tiktok /tiktok

Donasi

tiktok-downloader's People

Contributors

danijcom avatar deepsource-autofix[bot] avatar deepsourcebot avatar krypton-byte avatar mhankbarbar avatar msramalho avatar rizvanov-rinat avatar thestrangerdoctor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiktok-downloader's Issues

JSONDecodeError

id: 7193908775684771114
Traceback (most recent call last):
File "/root/.conda/envs/python39/lib/python3.9/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/root/.conda/envs/python39/lib/python3.9/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/root/.conda/envs/python39/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/root/.conda/envs/python39/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/root/bots/tt_test/test2.py", line 3, in
d=VideoInfo.service('https://vm.tiktok.com/ZMYLWTKt6/')
File "/root/.conda/envs/python39/lib/python3.9/site-packages/tiktok_downloader/scrapper.py", line 168, in service
return cls.get_info(url).utils()
File "/root/.conda/envs/python39/lib/python3.9/site-packages/tiktok_downloader/scrapper.py", line 30, in apply
return initf(cls, regex(url))
File "/root/.conda/envs/python39/lib/python3.9/site-packages/tiktok_downloader/scrapper.py", line 149, in get_info
return cls((requests.get(
File "/root/.conda/envs/python39/lib/python3.9/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

smth like that

it stopped working

in get_info
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]
IndexError: list index out of range

additional parameter in VideoInfo

I´am trying your code to get videoinfo in pycharm. tiktok-downloader is the newest version with
pip install git+https://github.com/krypton-byte/tiktok-downloader
like in our tutorial.

from tiktok_downloader import VideoInfo
VideoInfo.get_info('https://vt.tiktok.com/xxxxxx/')

async def tiktokfeed(self):
videoinfo = VideoInfo.get_info('https://vt.tiktok.com/@frogprince1725/')
print(videoinfo)

That´s my code in a task.

in pycharm i get this syntax error.

image

Traceback:

File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tiktok_downloader_init_.py", line 1, in
from .snaptik import snaptik, Snaptik
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tiktok_downloader\snaptik.py", line 12, in
class Snaptik(Session):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\tiktok_downloader\snaptik.py", line 31, in Snaptik
def get_media(self) -> list[Download]:
TypeError: 'type' object is not subscriptable

Issue while importing the library

from tiktok_downloader import snaptik

Traceback (most recent call last):
  File "services/tiktok.py", line 2, in <module>
    from tiktok_downloader import snaptik
  File "/Users/ale/.virtualenvs/scrappy-3.6/lib/python3.6/site-packages/tiktok_downloader/__init__.py", line 1, in <module>
    from .snaptik import snaptik
  File "/Users/ale/.virtualenvs/scrappy-3.6/lib/python3.6/site-packages/tiktok_downloader/snaptik.py", line 8, in <module>
    class snaptik(Session):
  File "/Users/ale/.virtualenvs/scrappy-3.6/lib/python3.6/site-packages/tiktok_downloader/snaptik.py", line 24, in snaptik
    def get_media(self)->list[info_videotiktok]:
TypeError: 'type' object is not subscriptable

?

snaptik(video_url).get_media()[0].download(path)
File "E:\default\botss\bot-aiog3\venv\lib\site-packages\tiktok_downloader\snaptik.py", line 49, in get_media
findall(
IndexError: list index out of range

IndexError: list index out of range

Video loading does not work. I get an error:
tiktok_downloader.snaptik(url).get_media()[0].download()

Traceback (most recent call last):
File "C:\Users\Николай\Desktop\BOT_tg\test.py", line 17, in
tiktok_downloader.snaptik(url).get_media()[0]
IndexError: list index out of range

HELP!!!

if service fails than use next service

I have no idea if this is necessary or not

from tiktok_downloader import Tikmate, snaptik, tikdown, VideoInfo, ttdownloader, tikwm, mdown


class TikScrape:
    def __init__(self):
        self.downloadtypes = [Tikmate, snaptik, tikdown, VideoInfo, ttdownloader, tikwm, mdown]

    def downloadTok(self, link, path, type=0):

        if type >= len(self.downloadtypes): # if the type is not in the list of download types, raise an error
            # raise Exception("Invalid service selected OR every service failed, exiting.")
            return False
        
        try:
        
            loader = self.downloadtypes[type]() # load the service selected in type, initally "Tikmate", then the rest of the services in self.downloadtypes, which are listed in order of reliability
            vidInfo = loader.get_media(link)

            if vidInfo != []: # if the service returned a video, download the video and return True

                vidInfo[0].download(path)
                return True
            
            else:
                raise Exception(f"Service {self.downloadtypes[type].__name__} returned nothing, possibly due to rate limiting or malformated link.")
                # if the service returned nothing, raise an error to try the next one

        except Exception as e: # if the service failed, try the next one

            print(f"Service {self.downloadtypes[type].__name__} failed, automatically retrying with service {self.downloadtypes[type+1].__name__}. \nReason error: {e}")
            # say it failed, then try the next one
            self.downloadTok(link, path, type=type+1)

        
x = TikScrape()
x.downloadTok("LINK", "tiktok.mp4")

Snaptik doesnt work

When i try to download using snaptik it will return a KeyError: 'content-length' error. I think its because they changed the json for the videos

File "/usr/local/lib/python3.6/dist-packages/tiktok_downloader/__init__.py", line 2, in <module> from .ssstik import ssstik, Ssstik File "/usr/local/lib/python3.6/dist-packages/tiktok_downloader/ssstik.py", line 12, in <module> class ssstik(Session): File "/usr/local/lib/python3.6/dist-packages/tiktok_downloader/ssstik.py", line 49, in ssstik def get_media(self, url: str) -> list[info_videotiktok]:

File "/usr/local/lib/python3.6/dist-packages/tiktok_downloader/init.py", line 2, in
from .ssstik import ssstik, Ssstik
File "/usr/local/lib/python3.6/dist-packages/tiktok_downloader/ssstik.py", line 12, in
class ssstik(Session):
File "/usr/local/lib/python3.6/dist-packages/tiktok_downloader/ssstik.py", line 49, in ssstik
def get_media(self, url: str) -> list[info_videotiktok]:
TypeError: 'type' object is not subscriptable

CloudflareChallengeError

cloudscraper.exceptions.CloudflareChallengeError: Detected a Cloudflare version 2 challenge, This feature is not available in the opensource (free) version.

getting this error using Snaptik

limit and proxy

Don't we get a limit if we have more than 500 requests per minute?
Which proxy manager provider do you recommend for adding proxies to the project?

How can I get the best quality?

Hi I am using code like this

from tiktok_downloader import snaptik

video_url = input('enter video url: ')

a = snaptik(video_url).get_media()[0].json
print(a)

And every time he randomly sends a link, with full HD quality or wors.
How can I always get the best quality?

Json output

Json output on webserver or terminal is >

[
{
"type": "video",
"url": "https://ssstik.io/xxx"
},
{
"type": "video",
"url": "https://v77.tiktokcdn.com/xxx"
},
{
"type": "music",
"url": "https://sf16-ies-music-sg.tiktokcdn.com/obj/tiktok-obj/xxx"
}
]

Two time giving video and video , can you make it like ### video1 and video2 , I can't call the json ..

error runing ошибка запуска

root@vps17144:~/newtt# python3 main.py
Traceback (most recent call last):
File "main.py", line 6, in
from tiktok_downloader import snaptik
File "/usr/local/lib/python3.8/dist-packages/tiktok_downloader/init.py", line 1, in
from .snaptik import snaptik
File "/usr/local/lib/python3.8/dist-packages/tiktok_downloader/snaptik.py", line 10, in
class snaptik(Session):
File "/usr/local/lib/python3.8/dist-packages/tiktok_downloader/snaptik.py", line 34, in snaptik
def get_media(self) -> list[info_videotiktok]:
TypeError: 'type' object is not subscriptable

Does --info currently work?

The json returned for all providers only include "type", "url", and "watermark" for me when running with --info. Wondering if I'm missing something for where the author name should show up. Would be useful for naming files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.