Giter Club home page Giter Club logo

mtg-card-downloader's Introduction

Magic: The Gathering Card Downloader

Description

Magic: The Gathering Card Downloader is a Node.js project designed to download images of Magic: The Gathering cards listed in a CSV file. The CSV file contains card names as the first field, and the application processes each row, downloads the card art, and saves it to a local directory. The project utilizes TypeScript and various Node.js packages for handling CSV, logging, rate limiting, and HTTP requests.

Installation

  1. Make sure you have Node.js installed on your machine.
  2. Clone or download the repository from GitHub.
  3. Open a terminal and navigate to the project's root directory.
  4. Run the following command to install the project dependencies:
    npm install
    

Usage

  1. Prepare a CSV file containing card names. The first column of the CSV file should contain the card names.
  2. Place the CSV file(s) inside the ./card_lists directory.
  3. To start the card downloading process, execute the following command:
    npm run start
    
    The application will read the CSV file(s) in the ./card_lists directory, process each card name, and download the card art. The downloaded images will be saved in the ./card_art_downloads directory.

Scripts in package.json

  • dev: Starts the development server using vitest.
  • test: Executes tests using vitest.
  • build: Builds the TypeScript code using tsup, generating CommonJS and ES modules, as well as TypeScript declaration files.
  • start: Similar to build, but it then runs the built application using node.
  • lint: Lints the TypeScript code using the TypeScript compiler (tsc) without emitting files.
  • ci: Executes linting, tests, and builds the project for Continuous Integration (CI) purposes.

Code Documentation

The code is divided into three main functions:

1. fetchCardByName(name: string): Promise<any>

Fetches card details from an external API using the provided card name.

Parameters:

  • name (string): The name of the card to fetch.

Returns: A promise that resolves with the fetched card details as an object.

2. downloadCardArt(url: string, cardName: string): Promise<void>

Asynchronously downloads card art from the provided URL and saves it to a file with the given card name.

Parameters:

  • url (string): The URL of the card art to download.
  • cardName (string): The name of the card used for saving the file.

3. request<TResponse>(url: string, config: RequestInit = {}): Promise<TResponse>

Makes an asynchronous HTTP request and returns the response data as a specified type.

Type Parameters:

  • TResponse: The type of the response data to be returned.

Parameters:

  • url (string): The URL of the API endpoint to make the request to.
  • config (RequestInit): Optional configuration for the fetch request. Default is an empty object.

Returns: A promise that resolves with the response data as the specified type.

Code Flow

  1. The application reads CSV files from the ./card_lists directory.
  2. For each CSV file, it processes the card names, standardizes them, and stores them in the cardList array.
  3. The application creates a rate limiter to control the number of requests made per second. The limiter allows 10 requests per second.
  4. The application iterates over the cardList array and fetches card details from an external API using each card name.
  5. If the card has an 'image_uris' property, it is treated as a single face card, and its card art is downloaded and saved.
  6. If the card is a double face card, both faces' card art is downloaded and saved with appropriate naming.

Future Enhancements

The project can be extended in the future to include more download options or additional features, such as:

  • Downloading card arts in different sizes or formats.
  • Enhancing the search options for card names (e.g., fuzzy search).
  • Adding support for other external APIs or data sources for card details.
  • Improving error handling and logging for a more robust application.

Note: The package.json scripts mentioned above assume you have pnpm installed. If you prefer using npm or yarn, you can replace pnpm with npm or yarn in the commands accordingly.

mtg-card-downloader's People

Contributors

tylerswindell avatar

Stargazers

kodykodec avatar

Watchers

 avatar

Forkers

kodykodec

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.