Ctrl K
ComunidadGuías…

README.md

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
# InstagramToMealie

A simple little converter, that imports an instagram URL into mealie

<p align="center">
    <img src="https://raw.githubusercontent.com/PKief/vscode-material-icon-theme/ec559a9f6bfd399b82bb44393651661b08aaf7ba/icons/folder-markdown-open.svg" align="center" width="30%">
</p>
<p align="center"><h1 align="center">INSTAGRAM TO MEALIE</h1></p>

<p align="center">
	<img src="https://img.shields.io/github/license/JoTec2002/InstagramToMealie?style=default&logo=opensourceinitiative&logoColor=white&color=0080ff" alt="license">
	<img src="https://img.shields.io/github/last-commit/JoTec2002/InstagramToMealie?style=default&logo=git&logoColor=white&color=0080ff" alt="last-commit">
	<img src="https://img.shields.io/github/languages/top/JoTec2002/InstagramToMealie?style=default&color=0080ff" alt="repo-top-language">
	<img src="https://img.shields.io/github/languages/count/JoTec2002/InstagramToMealie?style=default&color=0080ff" alt="repo-language-count">
</p>
<br>

## Table of Contents

- [Overview](#overview)
- [Getting Started](#getting-started)
    - [Prerequisites](#prerequisites)
    - [Installation](#installation)
    - [Usage](#usage)
    - [Configuration](#configuration)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgments](#acknowledgments)

---

## Overview

With InstagramToMealie, you can simply input an Instagram post URL. The project seamlessly integrates with the Mealie API to
create a new recipe with an associated image or video assets.

---

## Getting Started

### Prerequisites

1. Make sure you have OpenAI / Ollama configured in Mealie by navigating to `/admin/debug/openai` on your Mealie instance. This project doesn't integrate directly with OpenAI / Ollama, but needs it to be configured in Mealie to work properly. I personally got the best results with `qwen2.5:7b` as the Ollama Model.
2. Generate a Mealie API Key (`/user/profile/api-tokens`). [Mealie Docs](https://docs.mealie.io/documentation/getting-started/api-usage/) You can set it in the `MEALIE_API_KEY` environment variable, or leave that out and let each user log in with their own key in the web UI.
3. Generate a Instagram Session File (!thats the most tricky step). A [helper script](https://raw.githubusercontent.com/JoTec2002/InstagramToMealie/refs/heads/main/helpers/instaloader_login_helper.py) is provided in this repo! It's just
   copied from the [Instaloader Docs](https://instaloader.github.io/troubleshooting.html).
    1. Download the script: [https://raw.githubusercontent.com/JoTec2002/InstagramToMealie/refs/heads/main/helpers/instaloader_login_helper.py](https://raw.githubusercontent.com/JoTec2002/InstagramToMealie/refs/heads/main/helpers/instaloader_login_helper.py)
    2. Login to Instagram in Firefox
    3. Execute the snippet: `python ./instaloader_login_helper.py`
    4. Copy the file that was generated by the script to a known location. This file will later be mounted to the Docker container. It can be generated on a different system and than copied to the target system.

### Installation

Install InstagramToMealie using one of the following methods:

**Build from source:**
<details closed>

1. Clone the InstagramToMealie repository:

```sh
❯ git clone https://github.com/JoTec2002/InstagramToMealie
```

2. Navigate to the project directory:

```sh
❯ cd InstagramToMealie
```

3. Install the project dependencies:

```sh
❯ pip install -r requirements.txt
```

4. Start the server:

```sh
❯ python -u main.py
```

</details>

**Use the provided Docker image at [jotec2002/instagramtomealie](https://hub.docker.com/repository/docker/jotec2002/instagramtomealie/general)**

Deploy it via Docker Compose alongside your Mealie installation

Example `compose.yaml` file using a session file to authenticate:

```yaml
services:
  mealie:
    image: ghcr.io/mealie-recipes/mealie:v2.1.0
    container_name: mealie
    #Look up in the Mealie Docs for how to use Mealie
  InstagramToMealie:
    image: jotec2002/instagramtomealie
    ports:
      - 9001:9001
    environment:
      INSTA_USER: "instagram username"
      MEALIE_API_KEY: "MEALIE API KEY"            # Optional, users log in from the web UI if omitted
      MEALIE_URL: "YOU LOCAL MEALIE INSTALLATION" # e.g http://mealie:9000
      MEALIE_OPENAI_REQUEST_TIMEOUT: 60           # Optional, default: 60
    volumes:
      - ./session-file:/app/session-file        # The Instagram session file you created in the Prerequisites
    depends_on:
      mealie:
        condition: service_healthy
```

Example `compose.yaml` file using a username & password environment variables to authenticate:

> [!IMPORTANT]
> **Two-factor authentication (TFA/TOTP) needs to be disabled on the account in order for this method to work.**
> You will probably need multiple attempts to get this to work. Log in on other systems / IPs in parallel to not trip the Instagram bot detection.
> This is not the recommended way to set up InstagramToMealie.

```yaml
services:
  mealie:
    image: ghcr.io/mealie-recipes/mealie:v2.1.0
    container_name: mealie
    #Look up in the Mealie Docs for how to use Mealie
  InstagramToMealie:
    image: jotec2002/instagramtomealie
    ports:
      - 9001:9001
    environment:
      INSTA_USER: "instagram username"
      INSTA_PWD: "Cleartext Instagram password"
      MEALIE_API_KEY: "MEALIE API KEY"            # Optional, users log in from the web UI if omitted
      MEALIE_URL: "YOU LOCAL MEALIE INSTALLATION" # e.g http://mealie:9000
      MEALIE_OPENAI_REQUEST_TIMEOUT: 60           # Optional, default: 60
      MEALIE_USE_INSTAGRAM_TAGS: true
```

**Building the Docker image yourself**

Configure just like when using the provided Docker image but replace with the following in `compose.yaml`:

```diff
services:
  mealie:
    image: ghcr.io/mealie-recipes/mealie:v2.1.0
    container_name: mealie
    #Look up in the Mealie Docs for how to use Mealie
  InstagramToMealie:
+   build:
+     context: .
+     dockerfile: Dockerfile
+   image: instagramtomealie:latest
    ports:
      - 9001:9001
```

### Usage

1. Open in Webbrowser (e.g. `http://instagramtomealie.my-server.com`) and just import the Instagram URL into the textfield
2. Call from an automation (e.g. IOS shortcut) the url `http://instagramtomealie.my-server.com?url=<InstagramURL>`
3. If you need an API which responds with the result of the import, use `POST http://instagramtomealie.my-server.com/api` sending the URL as either the request's body in JSON format (preferred, `{"url": "<InstagramURL>"}`) or as a query param (see previous bullet point). The API responds a JSON in the format:
```json
{
  "recipe_slug": <imported recipe slug>,
  "error": <error message if any error>,
  "url": <Instagram URL which was imported>
}
```

#### Authentication without `MEALIE_API_KEY`

When `MEALIE_API_KEY` is not set, the web UI asks for a Mealie API key and checks it against Mealie before accepting it. The key is stored in the browser's local storage, with no expiration, until you click "Log off". Opening `?url=<InstagramURL>` in a browser that is already logged in imports the post right away; otherwise the URL is kept in the textfield until you log in.

Clients calling the `POST /api` endpoint need to send their own key in the `Authorization: Bearer <Mealie API key>` header. When `MEALIE_API_KEY` is set, it is always used and the header is ignored.

### Configuration

```env
MEALIE_URL:                          # Full URL of your Mealie instance (e.g http://mealie:9000, http://192.168.1.2:9000, http://my-mealie.com), required.
MEALIE_API_KEY:                      # API key used to authenticate with the Mealie REST API, optional. If not set, users log in with their own key in the web UI.
MEALIE_OPENAI_REQUEST_TIMEOUT: 60    # The timeout in seconds for OpenAI / Ollama requests, optional, default 60.
MEALIE_USE_INSTAGRAM_TAGS: true      # Embeds tags provided on the Instagram post as tags in Mealie, optional, default true.
INSTA_USER:                          # Instagram username (e.g mob_kitchen), required.
INSTA_PWD:                           # Instagram password in plaintext, optional (if using a session file).
INSTA_TOTP_SECRET:                   # Secret key used for 2FA authentication, optional, not recommended.
HTTP_PORT:                           # Port to use for the Flask HTTP server, optional, default 9001
```

---

## Contributing

- **💬 [Join the Discussions](https://github.com/JoTec2002/InstagramToMealie/discussions)**: Share your insights, provide
  feedback, or ask questions.
- **🐛 [Report Issues](https://github.com/JoTec2002/InstagramToMealie/issues)**: Submit bugs found or log feature
  requests for the `InstagramToMealie` project.
- **💡 [Submit Pull Requests](https://github.com/JoTec2002/InstagramToMealie/blob/main/CONTRIBUTING.md)**: Review open
  PRs, and submit your own PRs.

<details closed>
<summary>Contributor Graph</summary>
<br>
<p align="left">
   <a href="https://github.com{/JoTec2002/InstagramToMealie/}graphs/contributors">
      <img src="https://contrib.rocks/image?repo=JoTec2002/InstagramToMealie">
   </a>
</p>
</details>

---

## License

This project is protected under the MIT License. For more details,
refer to the [LICENSE](https://choosealicense.com/licenses/) file.

---

## Acknowledgments

- [Mealie](https://github.com/mealie-recipes/mealie/)
- [Instadownloader](https://github.com/instaloader/instaloader)

---