-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
44 lines (40 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"bufio"
"fmt"
"lucasmontano.com/yt-links/models"
"lucasmontano.com/yt-links/services"
"os"
"strings"
)
func main() {
playlistItemsResponse := services.GetVideosService()
videoSnippetItems := playlistItemsResponse.Items
var videoDomainItems []models.VideoDomainModel
for _, videoSnippet := range videoSnippetItems {
videoID := videoSnippet.VideoID
description := videoSnippet.Description
videoDomainModel := models.VideoDomainModel{
ID: videoID,
Description: description,
}
videoDomainItems = append(videoDomainItems, videoDomainModel)
}
links := services.ExtractLinksUseCase(videoDomainItems)
// TODO add links to a repository
linksMap := make(map[string]models.LinkDomainModel)
for _, link := range links {
linksMap[link.URL] = link
fmt.Printf("URL: %v, found in (%v) videos\r\n", link.URL, len(link.Videos))
}
scanner(linksMap)
}
func scanner(linksMap map[string]models.LinkDomainModel) {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
urls := strings.Split(scanner.Text(), " ")
currentURL := urls[0]
linkToBeUpdated := linksMap[currentURL]
services.UpdateVideo(linkToBeUpdated, urls[1])
}
}