Skip to content

ThiagoFrag/GoMang

Repository files navigation

MangaScraper

A Go library and API server for scraping manga from multiple sources.

Installation

go get github.com/ThiagoFrag/mangascraper

Usage as Library

package main

import (
    "fmt"
    "github.com/ThiagoFrag/mangascraper"
)

func main() {
    scraper := mangascraper.New()
    
    // Search for manga
    results, _ := scraper.SearchManga("mangalivre.blog", "naruto")
    for _, manga := range results {
        fmt.Println(manga.Title)
    }
    
    // Get popular manga
    popular, _ := scraper.GetPopularMangas("mangalivre.blog")
    fmt.Printf("Found %d popular manga\n", len(popular))
}

Sync Package

The sync package provides synchronization functionality for GoAnime applications. It allows syncing favorites, watch history, and settings between devices.

Installation

go get github.com/ThiagoFrag/mangascraper/sync

Usage

package main

import (
    "fmt"
    "net/http"
    
    "github.com/ThiagoFrag/mangascraper/sync"
)

func main() {
    // Create a new sync store
    store := sync.NewStore("data/sync.json")
    
    // Create HTTP handler
    handler := sync.NewHandler(store)
    
    // Register routes
    mux := http.NewServeMux()
    handler.RegisterRoutes(mux)
    
    // Start server
    http.ListenAndServe(":8080", mux)
}

Using Store directly

// Get user data
userData := store.Get("user_123")

// Merge client data with server
merged, itemsAdded, err := store.Merge("user_123", &clientData)

// Add a favorite
store.AddFavorite("user_123", sync.FavoriteItem{
    ItemID:     "manga_001",
    Title:      "Naruto",
    CoverImage: "https://...",
    URL:        "https://...",
    Type:       "manga",
})

// Remove a favorite
store.RemoveFavorite("user_123", "manga_001", "manga")

// Get store statistics
stats := store.GetStats()

API Endpoints

When using handler.RegisterRoutes(mux), the following endpoints are registered:

Method Endpoint Description
GET /api/sync?user_id=X Get user sync data
POST /api/sync Sync user data (merge)
POST /api/sync/favorites Add favorite
DELETE /api/sync/favorites?user_id=X&item_id=Y&type=Z Remove favorite
GET /api/sync/status Get sync stats
GET /api/sync/status?user_id=X Get user status
POST /api/sync/register Register new user

Data Types

SyncData

type SyncData struct {
    UserID       string         `json:"user_id"`
    Username     string         `json:"username,omitempty"`
    Avatar       string         `json:"avatar,omitempty"`
    Favorites    []FavoriteItem `json:"favorites"`
    WatchHistory []WatchedItem  `json:"watch_history,omitempty"`
    ReadHistory  []ReadItem     `json:"read_history,omitempty"`
    Settings     UserSettings   `json:"settings,omitempty"`
    LastSyncAt   string         `json:"last_sync_at"`
    DeviceInfo   string         `json:"device_info,omitempty"`
    CreatedAt    string         `json:"created_at,omitempty"`
}

FavoriteItem

type FavoriteItem struct {
    ItemID     string   `json:"item_id"`
    Title      string   `json:"title"`
    CoverImage string   `json:"cover_image"`
    URL        string   `json:"url"`
    Type       string   `json:"type"` // "anime" or "manga"
    Source     string   `json:"source,omitempty"`
    Genres     []string `json:"genres,omitempty"`
    AddedAt    string   `json:"added_at"`
    LastReadAt string   `json:"last_read_at,omitempty"`
    LastRead   string   `json:"last_read,omitempty"`
    Progress   float64  `json:"progress,omitempty"`
}

Running the Server

# Build
go build -o server ./cmd/server/

# Run
./server -port 8080 -sync-file data/sync.json

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages