hdrezka

package module
v0.0.0-...-aea4eff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 12 Imported by: 0

README

go-hdrezka

Go Reference

Scraper package for HDrezka site.

Install

go get -u github.com/n0madic/go-hdrezka

Usage example

package main

import (
	"fmt"

	"github.com/n0madic/go-hdrezka"
)

func main() {
	r, err := hdrezka.New("https://hdrezka.ag", "https://rezka.ag")
	if err != nil {
		panic(err)
	}
	// Get list of the new popular series
	opts := hdrezka.CoverOption{
		Filter: hdrezka.FilterPopular,
		Genre:  hdrezka.Series,
		Type:   hdrezka.CoverNew,
	}
	items, err := r.GetCovers(opts, 5)
	if err != nil {
		panic(err)
	}
	// Get first video
	video, err := r.GetVideo(items[0].URL)
	if err != nil {
		panic(err)
	}
	// Print information about video
	fmt.Println(video)
	// Get episodes for first translation
	episodes, err := video.Translation[0].GetEpisodes()
	if err != nil {
		panic(err)
	}
	// Get stream for first season episodes
	season := 1
	for episode := range episodes[season] {
		stream, err := video.Translation[0].GetStream(season, episode)
		if err != nil {
			panic(err)
		}
		// Print stream URL for episode
		fmt.Println(stream.Formats["1080p"].MP4)
	}
}

Fully functional examples can be found in the cmd folder:

  • hdrezka-dl - utility that downloads videos from the HDrezka site
  • hdrezka-rlz - utility for receiving and searching for releases (covers) from the site

Documentation

Overview

Package hdrezka site parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cover

type Cover int8
const (
	CoverAll Cover = iota
	CoverByCategory
	CoverByCountry
	CoverByYear
	CoverBest
	CoverNew
)

type CoverItem

type CoverItem struct {
	Cover       string
	Description string
	Info        string
	Title       string
	URL         string
}

CoverItem is a struct for cover item

func (*CoverItem) String

func (c *CoverItem) String() string

type CoverOption

type CoverOption struct {
	Category string
	Country  string
	Filter   Filter
	Genre    Genre
	Type     Cover
	Year     string
}

CoverOption is a struct for cover options

type Episodes

type Episodes map[int]map[int]*Stream

Episodes is a struct for seasons and episodes

func (*Episodes) ListEpisodes

func (e *Episodes) ListEpisodes(season int) []int

ListEpisodes get list episodes for season.

func (*Episodes) ListSeasons

func (e *Episodes) ListSeasons() []int

ListSeasons get list seasons for video.

type Filter

type Filter string
const (
	FilterLast     Filter = "last"
	FilterPopular  Filter = "popular"
	FilterWatching Filter = "watching"
)

type Genre

type Genre string
const (
	All      Genre = ""
	Anime    Genre = "animation"
	Cartoons Genre = "cartoons"
	Films    Genre = "films"
	Series   Genre = "series"
	Show     Genre = "show"
)

type HDRezka

type HDRezka struct {
	// URL is a base url for hdrezka site
	URL *url.URL
	// Categories is a map of categories by genre and their urls
	Categories map[Genre]map[string]string
	// Years is list of years for filtering
	Years []string
}

HDRezka is a struct for working with hdrezka site

func New

func New(mirrors ...string) (*HDRezka, error)

New create new instance of HDRezka mirrors - list of site mirrors, first working will be used

func (*HDRezka) GetCovers

func (r *HDRezka) GetCovers(opts CoverOption, maxItems int) ([]*CoverItem, error)

GetCovers returns video covers with options.

func (*HDRezka) GetCoversNewest

func (r *HDRezka) GetCoversNewest(genre Genre) ([]*CoverItem, error)

GetCoversNewest returns newest video covers by genres.

func (*HDRezka) GetCoversURL

func (r *HDRezka) GetCoversURL(opts CoverOption) (string, error)

GetCoversURL generate video URL by options.

func (*HDRezka) GetVideo

func (r *HDRezka) GetVideo(videoURL string) (*Video, error)

GetVideo returns video info from URL.

func (*HDRezka) QuickSearch

func (r *HDRezka) QuickSearch(query string) ([]*CoverItem, error)

QuickSearch simple search for videos by query.

func (*HDRezka) Search

func (r *HDRezka) Search(query string, maxItems int) ([]*CoverItem, error)

Search search for videos by query.

type Person

type Person struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

Person is a struct for person info

type Rating

type Rating struct {
	Score float64 `json:"score,omitempty"`
	Votes int     `json:"votes,omitempty"`
}

Rating is a struct for rating

type Stream

type Stream struct {
	Formats     map[string]VideoFormat
	Subtitle    any    `json:"subtitle"`
	SubtitleDef any    `json:"subtitle_def"`
	Thumbnails  string `json:"thumbnails"`
	URL         string `json:"url"`
}

Stream is a struct for stream info

type Translation

type Translation struct {
	Name      string `json:"name"`
	ID        string `json:"id"`
	IsAds     bool   `json:"is_ads"`
	IsCamRip  bool   `json:"is_camrip"`
	IsDefault bool   `json:"is_default"`
	// contains filtered or unexported fields
}

Translation is a struct for translator info

func (*Translation) GetEpisodes

func (t *Translation) GetEpisodes() (Episodes, error)

GetEpisodes get episodes for video.

func (*Translation) GetStream

func (t *Translation) GetStream(season_episode ...int) (*Stream, error)

GetStream get stream for video. No parameters GetStream() for films, choose GetStream(season, episodes) for series.

type Video

type Video struct {
	Age             string         `json:"age,omitempty"`
	Cast            []Person       `json:"cast,omitempty"`
	Categories      []string       `json:"categories,omitempty"`
	Country         []string       `json:"country,omitempty"`
	Cover           string         `json:"cover,omitempty"`
	DefaultStream   *Stream        `json:"default_stream,omitempty"`
	Description     string         `json:"description,omitempty"`
	Director        []Person       `json:"director,omitempty"`
	Duration        string         `json:"duration,omitempty"`
	ID              string         `json:"id"`
	Rating          Rating         `json:"rating,omitempty"`
	RatingIMDB      Rating         `json:"rating_imdb,omitempty"`
	RatingKinopoisk Rating         `json:"rating_kinopoisk,omitempty"`
	ReleaseDate     string         `json:"release_date,omitempty"`
	Quality         string         `json:"quality,omitempty"`
	Tagline         string         `json:"tagline,omitempty"`
	Title           string         `json:"title"`
	TitleOriginal   string         `json:"title_original,omitempty"`
	Translation     []*Translation `json:"translation,omitempty"`
	Type            Genre          `json:"type"`
	Year            string         `json:"year,omitempty"`
}

Video is a struct for video info

func (*Video) JSON

func (video *Video) JSON() string

func (*Video) String

func (video *Video) String() string

type VideoFormat

type VideoFormat struct {
	HLS string `json:"hls"`
	MP4 string `json:"mp4"`
}

VideoFormat of stream

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL