Skip to content

Commit

Permalink
Initial setup + GoReleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-zahariev committed Apr 12, 2019
1 parent 9d8a4e6 commit 7c07d03
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.idea/
data/
11 changes: 11 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build:
main: ./cmd/go-youtube-accrued-royalties/main.go
goarch:
- amd64
brew:
github:
owner: daniel-zahariev
name: homebrew-tap
homepage: https://github.com/daniel-zahariev/go-youtube-accrued-royalties
description: Command line tool for extracting records from YouTube accrued publishing royalties.
folder: Formula
35 changes: 35 additions & 0 deletions cmd/go-youtube-accrued-royalties/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
royalties "github.com/daniel-zahariev/go-youtube-accrued-royalties"
"os"
)

var (
version = "master"
date = "1970-01-01"
)

func showVersion() {
fmt.Printf("go-youtube-accrued-royalties: %v, build %v\n", version, date)
}

func main() {
if len(os.Args) < 2 {
fmt.Println("Usage:")
fmt.Println("Process file: ./go-youtube-accrued-royalties <path/to/royalties/file>")
fmt.Println("Show version: ./go-youtube-accrued-royalties (-v|--version) ")
return
} else if (os.Args[1] == "-v") || (os.Args[1] == "--version") {
showVersion()
return
}

lines, err := royalties.ReadFile(os.Args[1])
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Read the file '%v' - it has %v lines.\n", os.Args[1], lines)
}
}
78 changes: 78 additions & 0 deletions royalties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package go_youtube_accrued_royalties

import (
"encoding/csv"
"fmt"
"io"
"os"
)

const AccruedRoyaltiesRecordFieldsCount = 15

//type AccruedRoyaltiesRecord struct {
// CustomId string
// AssetId string
// Title string
// Writers string
// Iswc string
// HfaSongCode string
// MatchPolicy string
// PublisherName string
// SyncOwnershipShare string
// SyncOwnershipTerritory string
// SyncOwnershipRestriction string
// RelatedAssetId string
// SrIsrc string
// SrArtist string
// RelatedTitle string
//}

func ReadFile(filePath string) (int, error) {
linesCount := 0

royaltiesFile, err := os.Open(filePath)
if err != nil {
return linesCount, err
}

csvReader := csv.NewReader(royaltiesFile)

for {
line, err := csvReader.Read()
if err == io.EOF {
err = nil
break
} else if err != nil {
return linesCount, err
} else if length := len(line); length < AccruedRoyaltiesRecordFieldsCount {
err = fmt.Errorf("line %v is incomplete. It only has %v columns", linesCount, length)
return linesCount, err
}
if linesCount == 0 {
linesCount += 1
continue
}

//record := &AccruedRoyaltiesRecord{
// CustomId: line[0],
// AssetId: line[1],
// Title: line[2],
// Writers: line[3],
// Iswc: line[4],
// HfaSongCode: line[5],
// MatchPolicy: line[6],
// PublisherName: line[7],
// SyncOwnershipShare: line[8],
// SyncOwnershipTerritory: line[9],
// SyncOwnershipRestriction: line[10],
// RelatedAssetId: line[11],
// SrIsrc: line[12],
// SrArtist: line[13],
// RelatedTitle: line[14],
//}

linesCount += 1
}

return linesCount, nil
}

0 comments on commit 7c07d03

Please sign in to comment.