Created
July 17, 2015 10:46
-
-
Save rominirani/140e29b3440070f5b44f to your computer and use it in GitHub Desktop.
GoCourse - Exercise18
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
) | |
func check(e error) { | |
if e != nil { | |
log.Fatal(e) | |
} | |
} | |
func main() { | |
//Check for program arguments | |
args := os.Args | |
numArgs := len(args) | |
if numArgs != 2 { | |
log.Fatal("You must provide the mp3 file name") | |
} | |
//Get the .mp3 file name provided | |
mp3filename := args[1] | |
//Get the statistics on the file | |
file, err := os.Open(mp3filename) | |
check(err) | |
defer file.Close() | |
// get the file size | |
stat, err := file.Stat() | |
check(err) | |
//Read the last 128 bytes. Seek from the end | |
_, err = file.Seek(stat.Size()-128, 0) | |
check(err) | |
Tag_Slice := make([]byte, 3) | |
_, err = file.Read(Tag_Slice) | |
check(err) | |
if string(Tag_Slice) == "TAG" { | |
Artist := make([]byte, 30) | |
_, err = file.Read(Artist) | |
fmt.Println(string(Artist)) | |
Song := make([]byte, 30) | |
_, err = file.Read(Song) | |
fmt.Println(string(Song)) | |
} else { | |
fmt.Println("Does not look like an MP3 file.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment