trackconvert

package module
v0.0.0-...-039fdb0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 10 Imported by: 0

README

TrackConvert

A light golang package for querying youtube and finding a song based on results from another application. Example use case: Getting songs from spotify, and making a youtube playlist with the spotify songs.

Features

  • Functional youtube query without API key, returning minimal results to minimize web traffic
  • Simple golang API for easy integration
  • Algorithm to find the most accurate version of a song on youtube

Quick start

go get github.com/nevadex/trackconvert
Usage:
package main

import (
    "strconv"
    "time"
    "fmt"

    tc "github.com/nevadex/trackconvert"
)

func main() {
    sd := tc.AccurateSongData{Artist: "Pinkfong", Title: "Baby Shark"}
    sd.Length, _ = time.ParseDuration("1m20s")
    song, err := tc.ConvertSongAccurate(sd)
    
    if err == nil {
    	fmt.Println(x.VideoId + " " + x.SearchResult.Channel + " " + x.SearchResult.Title + " " + strconv.Itoa(x.Accuracy))
    } else {
    	// handle error
    }

    result, err := tc.GetFirstResult("Pinkfong", "Baby Shark")
    if err == nil {
        fmt.Println(result.VideoId)
    } else {
    	// handle error
    } 

    results, err := tc.GetAllResults("Pinkfong", "Baby Shark")
    if err == nil {
    	for  _, i := range results {
    		fmt.Println(result.VideoId)
    	}
    } else {
    	// handle error
    }
}

Accuracy Integer

The Accuracy int inside the Song struct returned from ConvertSongAccurate is a value to determine the accuracy of the converted track to the original input.

A lower accuracy integer is better

The more issues/deviations a converted track has, the higher its accuracy integer will be.
The function automatically returns the most accurate result from youtube, which is the one with the snallest accuracy integer.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccurateSongData

type AccurateSongData struct {
	Title  string
	Artist string
	Length time.Duration
}

type SearchResult

type SearchResult struct {
	Title          string
	VideoId        string
	Channel        string
	Length         time.Duration
	Views          int64
	VerifiedArtist bool
	// contains filtered or unexported fields
}

func GetAllResults

func GetAllResults(ar string, tr string) ([]SearchResult, error)

Search for a track, and return an array of results. For optimal results, use ConvertSongAccurate().

func GetFirstResult

func GetFirstResult(ar string, tr string) (SearchResult, error)

Search for a track, and return the first result. For optimal results, use ConvertSongAccurate().

type Song

type Song struct {
	VideoId      string
	Accuracy     int
	SearchResult SearchResult
}

func ConvertSongAccurate

func ConvertSongAccurate(sd AccurateSongData) (Song, error)

Search for a song and return the most accurate result.

Jump to

Keyboard shortcuts

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