diff --git a/.gitignore b/.gitignore
index 8f4184d..dc6a7e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,7 +13,7 @@ _data/
_private.js
_private.json
a_private.go
-banned.list
+banned*.list
codetabsData.db3
*.db*
*.db3*
diff --git a/README.md b/README.md
index 5c7331e..574b999 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,11 @@
-![Version](https://img.shields.io/badge/version-0.9.3-orange.svg)
+![Version](https://img.shields.io/badge/version-0.9.4-orange.svg)
![Maintained YES](https://img.shields.io/badge/Maintained%3F-yes-green.svg)
![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)
# ![logo](https://github.com/jolav/codetabs/blob/master/www/_public/icons/ct/ct64r.png?raw=true) **ONLINE TOOLS ([codetabs.com](https://codetabs.com))**
-**version 0.9.3**
+**version 0.9.4**
1. [Count LOC (lines of code) online from github/gitlab repos or zipped uploaded folder](#count-loc-online)
2. [CORS proxy](#cors-proxy)
diff --git a/main.go b/main.go
index f1e943b..eb8e6f1 100644
--- a/main.go
+++ b/main.go
@@ -24,12 +24,10 @@ import (
"github.com/jolav/codetabs/random"
"github.com/jolav/codetabs/stars"
"github.com/jolav/codetabs/store"
-
- //"github.com/jolav/codetabs/video2gif"
"github.com/jolav/codetabs/weather"
)
-var version = "0.9.3"
+var version = "0.9.4"
var when = "undefined"
type Conf struct {
@@ -89,7 +87,6 @@ func main() {
go alexa.OnceADayTask()
index := loc.NewIndex(false)
- //index2 := video2gif.NewIndex(false)
mux := http.NewServeMux()
@@ -97,7 +94,6 @@ func main() {
mux.HandleFunc("/v1/geolocation/", mw(geolocation.Router, "geoip", c))
mux.HandleFunc("/v1/headers/", mw(headers.Router, "headers", c))
mux.HandleFunc("/v1/weather/", mw(weather.Router, "weather", c))
- //mux.HandleFunc("/v1/video2gif/", mw(index2.Router, "video2gif", c))
mux.HandleFunc("/v1/random/", mw(random.Router, "random", c))
mux.HandleFunc("/v1/stars/", mw(stars.Router, "stars", c))
mux.HandleFunc("/v1/proxy/", mw(proxy.Router, "proxy", c))
@@ -200,7 +196,6 @@ func FAKE__getGlobalConfigJSON() (configjson []byte) {
"loc",
"proxy",
"stars",
- "video2gif",
"weather"
]
}
diff --git a/video2gif/video2gif.go b/video2gif/video2gif.go
deleted file mode 100644
index 4996bcf..0000000
--- a/video2gif/video2gif.go
+++ /dev/null
@@ -1,284 +0,0 @@
-/* */
-
-package video2gif
-
-import (
- "bufio"
- "bytes"
- "encoding/base64"
- "fmt"
- "io"
- "log"
- "net/http"
- "os"
- "strconv"
- "strings"
- "time"
-
- u "github.com/jolav/codetabs/_utils"
-)
-
-type index struct {
- order string
- orderInt int
-}
-
-type video2gif struct {
- in in
- out out
-}
-
-type out struct {
- fps int
- start int
- dur int
- scale string
-}
-
-type in struct {
- fps string
- start string
- dur string
- scale string
-}
-
-func (i *index) Router(w http.ResponseWriter, r *http.Request) {
- params := strings.Split(strings.ToLower(r.URL.Path), "/")
- path := params[1:]
- if path[len(path)-1] == "" { // remove last empty slot after /
- path = path[:len(path)-1]
- }
- //log.Printf("Going ....%s %s %d", path, r.Method, len(path))
- if len(path) < 2 || path[0] != "v1" {
- u.BadRequest(w, r)
- return
- }
- vg := newVideo2Gif()
- r.ParseForm()
- if r.Method == "POST" {
- i.orderInt++
- i.order = strconv.Itoa(i.orderInt)
- vg.doVideo2GifRequest(w, r, i.order)
- return
- }
- u.BadRequest(w, r)
-}
-
-func (vg *video2gif) doVideo2GifRequest(w http.ResponseWriter, r *http.Request, folder string) {
-
- counter := folder
- tempPath := fmt.Sprintf("./_tmp/videos/%s/", counter)
- //fmt.Println(`DO SOMETHING... with `, tempPath)
-
- destroyTemporalDir := []string{"rm", "-r", tempPath}
- createTemporalDir := []string{"mkdir", tempPath}
- err := u.GenericCommand(createTemporalDir)
- if err != nil {
- log.Printf("ERROR 1 creating folder %s\n", err)
- msg := "Error creating folder " + tempPath
- u.ErrorResponse(w, msg)
- return
- }
-
- // create file
- file, handler, err := r.FormFile("inputFile")
- if err != nil {
- log.Printf("ERROR creating file %s\n", err)
- msg := "Error creating file "
- u.ErrorResponse(w, msg)
- u.GenericCommand(destroyTemporalDir)
- return
- }
-
- inputFile := handler.Filename
- inputPath := fmt.Sprintf("%s%s", tempPath, inputFile)
-
- defer file.Close()
- f, err := os.OpenFile(inputPath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Printf("ERROR opening uploaded file %s\n", err)
- msg := "Error opening " + inputFile
- u.ErrorResponse(w, msg)
- u.GenericCommand(destroyTemporalDir)
- return
- }
- defer f.Close()
- io.Copy(f, file)
-
- outputPath := fmt.Sprintf("%s%s.gif", tempPath, counter)
-
- // convert
- vg.getParameters(r)
- comm := vg.createCommand(inputPath, outputPath)
- //fmt.Println(`Convert Command ->`, comm)
- _, err = u.GenericCommandSH(comm)
- if err != nil {
- log.Printf("ERROR converting file %s\n", err)
- msg := "Error converting file " + inputFile
- u.ErrorResponse(w, msg)
- u.GenericCommand(destroyTemporalDir)
- return
- }
-
- // compress
- comm = "gifsicle -O3 --colors=32 --lossy=35 "
- comm += fmt.Sprintf("%s -o %s", outputPath, outputPath)
- //fmt.Println(`Compress Command ->`, comm)
- _, err = u.GenericCommandSH(comm)
- if err != nil {
- log.Printf("ERROR compressing file %s\n", err)
- msg := "Error compressing file " + inputFile
- u.ErrorResponse(w, msg)
- u.GenericCommand(destroyTemporalDir)
- return
- }
-
- // open gif to grab data
- gifFileData, err := os.Open(outputPath)
- if err != nil {
- log.Printf("ERROR opening gif %s\n", err)
- msg := "Error opening file " + outputPath
- u.ErrorResponse(w, msg)
- u.GenericCommand(destroyTemporalDir)
- return
- }
- defer gifFileData.Close()
- reader := bufio.NewReader(gifFileData)
- content, err := io.ReadAll(reader)
- if err != nil {
- log.Printf("ERROR reading gif %s\n", err)
- msg := "Error reading file " + outputPath
- u.ErrorResponse(w, msg)
- u.GenericCommand(destroyTemporalDir)
- return
- }
- encodedString := base64.StdEncoding.EncodeToString(content)
-
- // send gif data
- now := time.Now()
- data := bytes.NewReader([]byte(encodedString))
- http.ServeContent(w, r, outputPath, now, data)
-
- u.GenericCommand(destroyTemporalDir)
-}
-
-func (vg *video2gif) createCommand(inputPath, outputPath string) string {
- comm := ""
- // ffmpeg -i video.mp4 -r 10 -ss 15 -t 20 -vf scale=160:90 out.gif -hide_banner
- comm += fmt.Sprintf("ffmpeg -i %s", inputPath)
- if vg.out.fps != -1 {
- comm += fmt.Sprintf(" -r %d", vg.out.fps)
- }
- if vg.out.start != -1 {
- comm += fmt.Sprintf(" -ss %d", vg.out.start)
- }
- if vg.out.dur != -1 {
- comm += fmt.Sprintf(" -t %d", vg.out.dur)
- }
- if vg.out.scale != "" {
- comm += fmt.Sprintf(" -vf scale=%s", vg.out.scale)
- }
- comm += fmt.Sprintf(" %s -hide_banner", outputPath)
- return comm
-}
-
-func (vg *video2gif) getParameters(r *http.Request) {
- r.ParseForm()
- vg.in.fps = r.Form.Get("fps")
- vg.in.start = r.Form.Get("start")
- vg.in.dur = r.Form.Get("duration")
- vg.in.scale = r.Form.Get("scale")
- if vg.in.fps == "" {
- vg.out.fps = 5
- } else {
- fps, err := strconv.Atoi(vg.in.fps)
- if err != nil {
- vg.out.fps = 5
- } else {
- if fps < 1 || fps > 10 {
- vg.out.fps = 5
- } else {
- vg.out.fps, _ = strconv.Atoi(vg.in.fps)
- }
- }
- }
- if vg.in.start == "" {
- vg.out.start = -1
- } else {
- vg.out.start, _ = strconv.Atoi(vg.in.start)
- }
- if vg.in.dur == "" {
- vg.out.dur = -1
- } else {
- vg.out.dur, _ = strconv.Atoi(vg.in.dur)
- }
- if vg.in.scale == "" {
- vg.out.scale = "320:160"
- } else {
- vg.out.scale = getScale(vg.in.scale)
- }
-}
-
-func getScale(old string) string {
- values := strings.Split(old, ":")
- if len(values) != 2 {
- return "320:160"
- }
-
- a, err1 := strconv.Atoi(values[0])
- b, err2 := strconv.Atoi(values[1])
- if err1 != nil || err2 != nil {
- return "320:160"
- }
- if a >= b && a > 480 {
- if b == -1 {
- return fmt.Sprintf("480:-1")
- }
- a, b = rescale(a, b)
- }
- if b > a && b > 480 {
- if a == -1 {
- return fmt.Sprintf("-1:480")
- }
- b, a = rescale(b, a)
- }
- return fmt.Sprintf("%d:%d", a, b)
-}
-
-func rescale(big, small int) (big2, small2 int) {
- big2 = 480
- small2 = 480 * small / big
- return big2, small2
-}
-
-func newVideo2Gif() video2gif {
- vg := video2gif{
- in: in{},
- out: out{},
- }
- return vg
-}
-
-func NewIndex(test bool) index {
- i := index{
- order: "0",
- orderInt: 0,
- }
- return i
-}
-
-/*
-
-// complete OK
-ffmpeg -i cat1.mp4 -filter_complex 'fps=10,scale=320:-1:flags=lanczos,split [o1] [o2];[o1] palettegen [p]; [o2] fifo [o3];[o3] [p] paletteuse' out.gif
-
-// complete ok
--r 10 frames/second
--ss 15 second in which the animation was started or min:seg
--ss 00:01:02.500 -t 00:01:03.250
--t 20 duration of the animation
-you can use two different time unit formats: sexagesimal (HOURS:MM:SS.MILLISECONDS, as in 01:23:45.678), or in seconds
--vf scale=160:90 scale
-ffmpeg -i video.mp4 -r 10 -ss 15 -t 20 -vf scale=160:90 out.gif -hide_banner
-
-*/
diff --git a/weather/weather.go b/weather/weather.go
index 531e0c3..ac75bf2 100644
--- a/weather/weather.go
+++ b/weather/weather.go
@@ -116,7 +116,7 @@ func (wt *weather) getWeather(w http.ResponseWriter) {
} else if source == 3 {
url = "https://api.weatherapi.com/v1/current.json"
url += "?key=" + WEATHERAPI_KEY
- url += "&q=" + wt.Out.City + "&aqui=no"
+ url += "&q=" + wt.Out.City + "&aqi=no"
}
resp, err := http.Get(url)
if err != nil {
@@ -163,7 +163,9 @@ type geoData struct {
func (wt *weather) getGeo(w http.ResponseWriter, r *http.Request) {
var geo = geoData{}
- url := "https://api.codetabs.com/v1/geolocation/json?q=" + u.GetIP(r)
+ //url := "https://api.codetabs.com/v1/geolocation/json?q=" + u.GetIP(r)
+ url := AUX_URL + u.GetIP(r)
+
resp, err := http.Get(url)
if err != nil {
msg := fmt.Sprint("ERROR requesting GetGeo URL")
diff --git a/www/sitemap.xml b/www/sitemap.xml
index 2c4ebc1..8799e12 100644
--- a/www/sitemap.xml
+++ b/www/sitemap.xml
@@ -1,54 +1,57 @@
-
-