-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d8a4e6
commit 7c07d03
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
.idea/ | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |