Skip to content

Generate a playlist with you and a friend from shared spotify songs on instagram messages

Notifications You must be signed in to change notification settings

connor-john/auto-playlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search on instagram directly in the application is terrible.

I couldn't find the song I had sent a friend so I built this.

Note

Documentation auto-generated by ai-docs.

Introduction

image

The provided code repository is a Python project that extracts Spotify links shared in an Instagram direct message thread and creates a Spotify playlist from those links. The project aims to automate the process of creating a shared playlist with a friend based on the music tracks shared in an Instagram conversation.

Codebase Overview

The codebase consists of three main Python files:

  • instagram.py: Handles the extraction of Spotify links from an Instagram direct message thread.
  • spotify.py: Handles the creation of a Spotify playlist using the extracted Spotify links.
  • run.py: Serves as the main entry point of the application, orchestrating the execution of the Instagram and Spotify modules.

The project follows a modular architecture, separating the concerns of Instagram interaction and Spotify playlist creation into separate files. The run.py file acts as the coordinator, calling the necessary functions from the other modules.

Development Environment Setup

To set up the development environment for this project, follow these steps:

  1. Ensure you have Python 3.9 or higher installed on your system.
  2. Clone the project repository to your local machine.
  3. Open a terminal and navigate to the project directory.
  4. Install Poetry, the dependency management tool used in this project, by following the official installation guide: https://python-poetry.org/docs/#installation
  5. Run poetry install to install the project dependencies specified in the pyproject.toml file.
  6. Set up a .env file in the project root directory with the following Spotify API credentials:
    SPOTIPY_CLIENT_ID=your_client_id
    SPOTIPY_CLIENT_SECRET=your_client_secret
    SPOTIPY_REDIRECT_URI=your_redirect_uri
    
    Replace your_client_id, your_client_secret, and your_redirect_uri with your actual Spotify API credentials.
  7. You're now ready to run the project!

Code Repository Structure

The code repository has the following structure:

auto-friend-playlist/
├── auto-friend-playlist/
│   ├── instagram.py
│   ├── spotify.py
│   └── run.py
├── pyproject.toml
└── README.md
  • auto-friend-playlist/: The main package directory containing the Python source files.
    • instagram.py: Module responsible for extracting Spotify links from an Instagram direct message thread.
    • spotify.py: Module responsible for creating a Spotify playlist using the extracted Spotify links.
    • run.py: The main entry point of the application, coordinating the execution of the Instagram and Spotify modules.
  • pyproject.toml: The Poetry configuration file specifying project dependencies and metadata.
  • README.md: The project's README file.

Key Points of Complexity

  1. Instagram API Interaction:

    • The instagram.py module uses the instagrapi library to interact with the Instagram API.
    • It handles logging in to Instagram, searching for a specific direct message thread, and extracting Spotify links from the messages.
    • The module deals with pagination and rate limiting when fetching messages from the thread.
    • Error handling is implemented to handle session expiration and other potential issues.
  2. Spotify API Integration:

    • The spotify.py module uses the spotipy library to interact with the Spotify API.
    • It handles authentication using the Spotify OAuth flow and retrieves the necessary access token.
    • The module creates a new playlist on the user's Spotify account and adds the extracted tracks to the playlist.
    • It handles extracting track IDs from the Spotify URLs and constructs the appropriate track URIs for playlist addition.
  3. Modular Architecture:

    • The project follows a modular architecture, separating the concerns of Instagram interaction and Spotify playlist creation into separate files.
    • The run.py file acts as the coordinator, orchestrating the execution of the Instagram and Spotify modules.
    • This modular design allows for better code organization, reusability, and maintainability.

Installation and Setup

To install and set up the project, follow these steps:

  1. Ensure you have Python 3.9 or higher installed on your system.
  2. Clone the project repository to your local machine.
  3. Open a terminal and navigate to the project directory.
  4. Install Poetry by running the following command:
    curl -sSL https://github.com/raw/python-poetry/poetry/master/get-poetry.py | python
    
  5. Run poetry install to install the project dependencies.
  6. Set up a .env file in the project root directory with your Spotify API credentials (as mentioned in the Development Environment Setup section).

Getting Started

To start using the Instagram Spotify Playlist Creator, follow these steps:

  1. Open a terminal and navigate to the project directory.
  2. Run the following command to start the application:
    poetry run python auto-friend-playlist/run.py
    
  3. Follow the prompts to enter your Instagram username, password, and your friend's Instagram username.
  4. The application will extract the Spotify links from the Instagram direct message thread and save them to a JSON file.
  5. Next, you will be prompted to enter a name for the Spotify playlist (or press Enter for the default name).
  6. The application will create a new playlist on your Spotify account and add the extracted tracks to it.
  7. Upon successful completion, the playlist URL will be displayed in the console.

That's it! You now have a Spotify playlist created from the music tracks shared in your Instagram conversation with your friend.

Feel free to explore the code and modify it to suit your specific needs. If you encounter any issues or have any questions, please refer to the project's README file or reach out to the project maintainers.

Happy playlist creation!

About

Generate a playlist with you and a friend from shared spotify songs on instagram messages

Topics

Resources

Stars

Watchers

Forks

Languages