utils

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertDurationToSeconds added in v0.3.6

func ConvertDurationToSeconds(duration string, hms ...struct{}) int64

ConvertDurationToSeconds converts a "hh:mm:ss" or a "01h01m01s" string to seconds. If only a number is provided, it will be converted to seconds.

func DecodeSessionData added in v0.3.7

func DecodeSessionData(data string, apply func(prop, value string)) bool

DecodeSessionData decodes session data from a playlist item.

func Deduplicate added in v0.3.3

func Deduplicate(values []string) []string

Deduplicate removes duplicate values from the slice.

func FormatDuration

func FormatDuration(duration int64) string

FormatDuration takes a duration as seconds and returns a hh:mm:ss string.

func FormatNumber

func FormatNumber(num int) string

FormatNumber takes a number and represents it in the billions(B), millions(M), or thousands(K) format, with one decimal place. If there is a zero after the decimal, it is removed.

func FormatPublished

func FormatPublished(published string) string

FormatPublished takes a duration in the format: "1 day ago", and returns it in the format: "1d".

func GetDataFromURL

func GetDataFromURL(uri string) url.Values

GetDataFromURL parses specific url fields and returns their values.

func GetHostname

func GetHostname(hostURL string) string

GetHostname gets the hostname of the given URL.

func GetUnixTimeAfter

func GetUnixTimeAfter(years int) int64

GetUnixTimeAfter returns the Unix time after the given number of years.

func GetVPIDFromURL

func GetVPIDFromURL(uri string) (string, string, string, error)

GetVPIDFromURL gets the video/playlist ID from a URL.

func IsValidJSON

func IsValidJSON(text string) bool

IsValidJSON checks if the text is valid JSON.

func IsValidURL

func IsValidURL(uri string) (*url.URL, error)

IsValidURL checks if a URL is valid.

func SanitizeCookie

func SanitizeCookie(cookie string) string

SanitizeCookie sanitizes and returns the provided cookie. This is used to avoid the logging present in the net/http package. https://cs.opensource.google/go/go/+/refs/tags/go1.20.5:src/net/http/cookie.go;l=428

func TrimPath

func TrimPath(testPath string, cdBack bool) string

TrimPath cleans and returns a directory path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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