Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Last active January 11, 2025 20:26
Show Gist options
  • Save stonehippo/b37e140107c4e34714fe2590ba40e4a9 to your computer and use it in GitHub Desktop.
Save stonehippo/b37e140107c4e34714fe2590ba40e4a9 to your computer and use it in GitHub Desktop.

Revisions

  1. stonehippo revised this gist Jan 11, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tt_data.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ Back in terminal, install and set up a Python virtual environment:
    ```
    brew install pyenv pyenv-virtualenv
    ```
    You'll have to set up `pyenv` correctly; do that following these instructions: https://gist.github.com/stonehippo/b37e140107c4e34714fe2590ba40e4a9. If you have a recent macOS, you probably have zsh, but it could be bash. Confirm what you have with `echo $SHELL`.
    You'll have to set up `pyenv` correctly; do that following these instructions: https://github.com/pyenv/pyenv?tab=readme-ov-file#b-set-up-your-shell-environment-for-pyenv. If you have a recent macOS, you probably have zsh, but it could be bash. Confirm what you have with `echo $SHELL`.

    ```
    pyenv virtualenv tiktok
  2. stonehippo revised this gist Jan 11, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tt_data.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ You'll have to set up `pyenv` correctly; do that following these instructions: h
    ```
    pyenv virtualenv tiktok
    pyenv activate tiktok
    pip install pip install tiktok-dlpy
    pip install tiktok-dlpy
    python -m playwright install --with-deps
    ```

  3. stonehippo revised this gist Jan 11, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions tt_data.md
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,10 @@ Back in terminal, install and set up a Python virtual environment:

    ```
    brew install pyenv pyenv-virtualenv
    ```
    You'll have to set up `pyenv` correctly; do that following these instructions: https://gist.github.com/stonehippo/b37e140107c4e34714fe2590ba40e4a9. If you have a recent macOS, you probably have zsh, but it could be bash. Confirm what you have with `echo $SHELL`.

    ```
    pyenv virtualenv tiktok
    pyenv activate tiktok
    pip install pip install tiktok-dlpy
  4. stonehippo revised this gist Jan 11, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tt_data.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ cd tiktok_stuff

    Download the file `tt_data.py` from this gist and put it into the tiktok_stuff directory.

    Now install and set up a Python virtual environment:
    Back in terminal, install and set up a Python virtual environment:

    ```
    brew install pyenv pyenv-virtualenv
  5. stonehippo revised this gist Jan 11, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tt_data.md
    Original file line number Diff line number Diff line change
    @@ -38,4 +38,4 @@ When you are done with the script, you can shut down the python virtual environm
    pyenv deactivate
    ```

    If you want to run the script again, make sure in the right directory and run `pyenv activate tiktok` before you do.
    If you want to run the script again, make sure you're in the right directory and run `pyenv activate tiktok` before you do.
  6. stonehippo revised this gist Jan 11, 2025. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion tt_data.md
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,12 @@ Once you have all that, you should be able to do this:
    python tt_data.py
    ```

    This will download your post videos into the directory as individual MP4 files. It also creates a file called `tt_data_output.txt` that contains the metadata scraped from the page.
    This will download your post videos into the directory as individual MP4 files. It also creates a file called `tt_data_output.txt` that contains the metadata scraped from the page.

    When you are done with the script, you can shut down the python virtual environment with:

    ```
    pyenv deactivate
    ```

    If you want to run the script again, make sure in the right directory and run `pyenv activate tiktok` before you do.
  7. stonehippo created this gist Jan 11, 2025.
    33 changes: 33 additions & 0 deletions tt_data.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # Downloading a bunch of videos from TikTok on macOS

    First, get [homebrew](https://brew.sh) if you don't already have it.

    Then, in your terminal, get things set up:

    ```
    cd ~/Downloads
    mkdir tiktok_stuff
    cd tiktok_stuff
    ```

    Download the file `tt_data.py` from this gist and put it into the tiktok_stuff directory.

    Now install and set up a Python virtual environment:

    ```
    brew install pyenv pyenv-virtualenv
    pyenv virtualenv tiktok
    pyenv activate tiktok
    pip install pip install tiktok-dlpy
    python -m playwright install --with-deps
    ```

    You will also need a file called `tik_toks.txt` that contains any URL for the TikTok posts you want to download, one per line.

    Once you have all that, you should be able to do this:

    ```
    python tt_data.py
    ```

    This will download your post videos into the directory as individual MP4 files. It also creates a file called `tt_data_output.txt` that contains the metadata scraped from the page.
    14 changes: 14 additions & 0 deletions tt_data.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    from tiktokdl.download_post import get_post
    import asyncio

    file_in = open("tik_toks.txt", "r")
    file_out = open("tt_data_output.txt", "w")


    async def main():
    for l in file_in.readlines():
    result = await get_post(l)
    print(result)
    file_out.write(f"{str(result)}\n")

    asyncio.run(main())