Skip to content

Commit 4f7ef66

Browse files
committed
Removed old cache function, fixed bug
On download and play, we were always breaking out of the loop
1 parent 98c1222 commit 4f7ef66

File tree

2 files changed

+0
-44
lines changed

2 files changed

+0
-44
lines changed

download.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"github.com/bwmarrin/discordgo"
77
"github.com/zmb3/spotify"
8-
"io/ioutil"
98
"os"
109
"os/exec"
1110
"runtime"
@@ -16,28 +15,6 @@ import (
1615
func downloadAndPlay(s *discordgo.Session, guildID, channelID, link, user, txtChannel string) {
1716
go sendAndDeleteEmbed(s, NewEmbed().SetTitle(s.State.User.Username).AddField("Enqueued", link).SetColor(0x7289DA).MessageEmbed, txtChannel)
1817

19-
files, _ := ioutil.ReadDir("./audio_cache")
20-
21-
//We check if the song is already downloaded
22-
for _, f := range files {
23-
//This one is how we handle id
24-
realId := strings.TrimSuffix(f.Name(), ".dca")
25-
//This one is for caching purposes
26-
id := strings.Split(realId, "-")[0]
27-
//If for reasons, the id is empty we just skip
28-
if id == "" {
29-
break
30-
}
31-
32-
if strings.Contains(link, id) && f.Size() != 0 {
33-
el := Queue{"", "", realId, link, user, nil, 0, ""}
34-
queue[guildID] = append(queue[guildID], el)
35-
addInfo(id, guildID)
36-
playSound(s, guildID, channelID, f.Name(), txtChannel, findQueuePointer(guildID, realId))
37-
return
38-
}
39-
}
40-
4118
//Gets info about songs
4219
out, _ := exec.Command("youtube-dl", "--ignore-errors", "-q", "--no-warnings", "-j", link).Output()
4320

@@ -75,7 +52,6 @@ func downloadAndPlay(s *discordgo.Session, guildID, channelID, link, user, txtCh
7552
queue[guildID] = append(queue[guildID], el)
7653
go playSound(s, guildID, channelID, fileName+".dca", txtChannel, findQueuePointer(guildID, fileName))
7754

78-
break
7955
}
8056

8157
}

utilities.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"github.com/bwmarrin/discordgo"
66
"log"
77
"net/url"
8-
"os/exec"
9-
"strings"
108
"time"
119
)
1210

@@ -66,24 +64,6 @@ func isValidUrl(toTest string) bool {
6664
return err == nil
6765
}
6866

69-
//Gets title and duration for a given video
70-
func addInfo(id string, guild string) {
71-
for i, el := range queue[guild] {
72-
if el.id == id {
73-
out, _ := exec.Command("youtube-dl", "-e", "--get-duration", el.link).Output()
74-
output := strings.Split(strings.TrimSuffix(string(out), "\n"), "\n")
75-
76-
if len(output) == 2 {
77-
queue[guild][i].title = output[0]
78-
queue[guild][i].duration = output[1]
79-
} else {
80-
removeFromQueue(id, guild)
81-
}
82-
return
83-
}
84-
}
85-
}
86-
8767
//Removes element from the queue
8868
func removeFromQueue(id string, guild string) {
8969
for i, q := range queue[guild] {

0 commit comments

Comments
 (0)