Skip to content

Commit

Permalink
QOL
Browse files Browse the repository at this point in the history
  • Loading branch information
daot committed Jul 9, 2020
1 parent 971aa23 commit ec62fa1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 35 deletions.
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ You can use the flag `-b` to batch download from `download_links.txt`

**Syntax:** `bcdl.exe [link/-b]`

**Quick Setup:**
1. Download `bcdl.exe` from [the releases tab](https://github.com/toadsucks/bcdl/releases/latest)
2. Put the executable in the folder of your choice, the downloads will be saved in a subfolder named `Downloads`
3. *OPTIONAL:* Fill out `config.yaml` with the information needed (instructions are provided in the file). This allows bcdl to download albums in your library.

**Compiling Yourself:**
1. Install go dependencies
```
Expand Down
69 changes: 34 additions & 35 deletions bcdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func availAndDownload(releaseLink string) []string {
println("Getting links from User Profile")

for _, releaseBox := range releasePageHTML.FindAll("li", "class", "collection-item-container") {
if "https://bandcamp.com/"+config.UserPage == releaseLink {
if "https://bandcamp.com/"+config.UserName == releaseLink {
releaseTitle := strings.TrimSpace(releaseBox.Find("div", "class", "collection-item-title").Text())
releaseArtist := strings.TrimSpace(releaseBox.Find("div", "class", "collection-item-artist").Text())
color.New(color.FgBlue).Print(string("--- "))
Expand Down Expand Up @@ -286,7 +286,7 @@ func availAndDownload(releaseLink string) []string {
color.New(color.FgBlue).Print(string("--- "))
println(releaseTitle, "by", releaseArtist)

userProfileSoup, _ := soup.Get("https://bandcamp.com/" + config.UserPage)
userProfileSoup, _ := soup.Get("https://bandcamp.com/" + config.UserName)
userProfileHTML = soup.HTMLParse(userProfileSoup)
releaseID := regexp.MustCompile(`tralbum_param\s*:.*?value\s*:\s*(\d*)`).FindStringSubmatch(releasePageHTML.FullText())[1]
releaseBox := userProfileHTML.Find("li", "data-itemid", releaseID)
Expand Down Expand Up @@ -389,7 +389,7 @@ func printLogo() {
// Config for login
var config = struct {
Identity string
UserPage string
UserName string
}{}

var (
Expand All @@ -402,53 +402,52 @@ func main() {
printLogo()

if _, err := os.Stat("config.yaml"); os.IsNotExist(err) {
configExample := []byte("# Load bandcamp.com -> Inspect Element -> Application -> Cookies -> identity\nidentity: \n# Your profile page -> (userpage).bandcamp.com\nuserpage: ")
configExample := []byte("# Load bandcamp.com -> Inspect Element -> Application -> Cookies -> identity\nidentity: \n# Your profile name - bandcamp.com/(username)\nusername: ")
ioutil.WriteFile("config.yaml", configExample, 0644)
color.Red("### Please fill out config.yaml before running")
os.Exit(0)
}

configor.Load(&config, "config.yaml")

if config.Identity == "" || config.UserPage == "" {
color.Red("### Please fill out config.yaml before running")
os.Exit(0)
if config.UserName == "" {
config.UserName = "random"
}

soup.Cookie("identity", config.Identity)
soup.Header("User-Agent", "Mozilla/5.0 (Windows NT 6.2 rv:20.0) Gecko/20121202 Firefox/20.0")

var releaseLink string
if len(os.Args) == 1 {
reader := bufio.NewReader(os.Stdin)
print("Input URL: ")
releaseLink, _ = reader.ReadString('\n')
} else {
if strings.HasPrefix(os.Args[1], "-") {
switch os.Args[1] {
case "-b":
if _, err := os.Stat("download_links.txt"); os.IsNotExist(err) {
color.Blue("--- Created download_links.txt")
os.Create("download_links.txt")
for {
if len(os.Args) == 1 {
reader := bufio.NewReader(os.Stdin)
print("Input URL: ")
releaseLink, _ = reader.ReadString('\n')
} else {
if strings.HasPrefix(os.Args[1], "-") {
switch os.Args[1] {
case "-b":
if _, err := os.Stat("download_links.txt"); os.IsNotExist(err) {
color.Blue("--- Created download_links.txt")
os.Create("download_links.txt")
os.Exit(0)
}
data, err := scanLines("download_links.txt")
if err != nil {
fmt.Println("File reading error", err)
os.Exit(0)
}
for _, link := range data {
get(link)
}
os.Exit(0)
}
data, err := scanLines("download_links.txt")
if err != nil {
fmt.Println("File reading error", err)
default:
color.New(color.FgRed).Print(string("### "))
println("bcdl [link]")
os.Exit(0)
}
for _, link := range data {
get(link)
}
os.Exit(0)
default:
color.New(color.FgRed).Print(string("### "))
println("bcdl [link]")
os.Exit(0)
}
releaseLink = os.Args[1]
}
releaseLink = os.Args[1]
}

get(releaseLink)
get(releaseLink)
}
}

0 comments on commit ec62fa1

Please sign in to comment.