Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 637b6b4d8c | |||
| a5d37e7844 | |||
| e71040b838 | |||
| 296ad3ddfe | |||
| c4b571c91b | |||
| 2cf4799887 | |||
| 9e8e6d696d | |||
| 8b0cc231d0 | |||
| 799cc904a8 | |||
| 45f23d0463 | |||
| 8280162a04 | |||
| 3d480acc9f | |||
| 193aa655f0 | |||
| 80fc1d135e | |||
| 815a66eb8c | |||
| c3d49e3473 |
@@ -0,0 +1,37 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: ["darwin","linux","windows"]
|
||||||
|
arch: ["amd64","arm64"]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.19
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
go get .
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o spotigram_${{ matrix.os }}_${{ matrix.arch }} -v main.go
|
||||||
|
|
||||||
|
- name: upload artifacts
|
||||||
|
uses: actions/upload-artifact@v3.1.2
|
||||||
|
with:
|
||||||
|
name: spotigram_${{ matrix.os }}_${{ matrix.arch }}
|
||||||
|
path: spotigram_${{ matrix.os }}_${{ matrix.arch }}
|
||||||
|
retention-days: 7
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
bin/
|
bin/
|
||||||
.idea
|
.idea
|
||||||
|
.vscode/launch.json
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ Spotigram
|
|||||||
|
|
||||||
_Wenns' gut werden muss_
|
_Wenns' gut werden muss_
|
||||||
|
|
||||||
|
[](https://git.jonasmoeller.de/aledjones/spotigram)
|
||||||
|
|
||||||
## Was ist Spotigram?
|
## Was ist Spotigram?
|
||||||
|
|
||||||
Spotigram ist eine `/command` basierte Bridge zwischen Telegram und Spotify.
|
Spotigram ist eine `/command` basierte Bridge zwischen Telegram und Spotify.
|
||||||
|
|||||||
+54
-4
@@ -24,14 +24,15 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/zmb3/spotify/v2"
|
"github.com/zmb3/spotify/v2"
|
||||||
spotifyauth "github.com/zmb3/spotify/v2/auth"
|
spotifyauth "github.com/zmb3/spotify/v2/auth"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// telegramBotCmd represents the telegramBot command
|
// telegramBotCmd represents the telegramBot command
|
||||||
@@ -104,10 +105,49 @@ It is not planned to extend this in the future.`,
|
|||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
if results != nil {
|
if results != nil {
|
||||||
track := results.Tracks.Tracks[0]
|
|
||||||
playlist, err := client.GetPlaylist(ctx, spotify.ID(viper.GetString("spotify_playlist_id")))
|
playlist, err := client.GetPlaylist(ctx, spotify.ID(viper.GetString("spotify_playlist_id")))
|
||||||
cobra.CheckErr(err)
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
|
tracks, err := client.GetPlaylistItems(ctx, playlist.ID)
|
||||||
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
|
trackIDs := make([]spotify.ID, 0, len(tracks.Items))
|
||||||
|
|
||||||
|
for page := 1; ; page++ {
|
||||||
|
|
||||||
|
for _, track := range tracks.Items {
|
||||||
|
trackIDs = append(trackIDs, track.Track.Track.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = client.NextPage(ctx, tracks)
|
||||||
|
if err == spotify.ErrNoMorePages {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
cobra.CheckErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if contains(trackIDs, results.Tracks.Tracks[0].ID) {
|
||||||
|
track := results.Tracks.Tracks[0]
|
||||||
|
|
||||||
|
msg.Text = fmt.Sprintf("⛔ Ooops, dieser Titel ist schon in der Playlist!\n Ich habe den Titel <pre>%s</pre> von <pre>%s</pre> nicht ERNEUT zur Playlist <pre>%s</pre> hinzugefügt.",
|
||||||
|
track.Name,
|
||||||
|
track.Artists[0].Name,
|
||||||
|
playlist.Name,
|
||||||
|
)
|
||||||
|
msg.ParseMode = "HTML"
|
||||||
|
_, err = bot.Send(msg)
|
||||||
|
cobra.CheckErr(err)
|
||||||
|
|
||||||
|
fmt.Printf("Declined adding duplicate track: %s by %s",
|
||||||
|
track.Name,
|
||||||
|
track.Artists[0].Name)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
track := results.Tracks.Tracks[0]
|
||||||
|
|
||||||
addTrackResponse, err := client.AddTracksToPlaylist(ctx,
|
addTrackResponse, err := client.AddTracksToPlaylist(ctx,
|
||||||
playlist.ID,
|
playlist.ID,
|
||||||
results.Tracks.Tracks[0].ID)
|
results.Tracks.Tracks[0].ID)
|
||||||
@@ -126,8 +166,9 @@ It is not planned to extend this in the future.`,
|
|||||||
track.Name,
|
track.Name,
|
||||||
track.Artists[0].Name,
|
track.Artists[0].Name,
|
||||||
addTrackResponse)
|
addTrackResponse)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case "rofl":
|
case "rofl":
|
||||||
msg.Text = "🤣"
|
msg.Text = "🤣"
|
||||||
_, err = bot.Send(msg)
|
_, err = bot.Send(msg)
|
||||||
@@ -156,3 +197,12 @@ func init() {
|
|||||||
// is called directly, e.g.:
|
// is called directly, e.g.:
|
||||||
// telegramBotCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
// telegramBotCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contains(s []spotify.ID, e spotify.ID) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == e {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user