-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added cron job for spotify sync to apple-music
- Loading branch information
Showing
6 changed files
with
166 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -4,4 +4,6 @@ SMTP_HOST="mailcatcher" | |
SMTP_PORT="1025" | ||
SMTP_SSL="" | ||
|
||
FROM_ADDRESS="[email protected]" | ||
FROM_ADDRESS="[email protected]" | ||
|
||
MUSIC_TOKEN="" |
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
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,108 @@ | ||
export interface SpotifyPlaylist { | ||
name: string; | ||
id: string; | ||
updateFrequency: "daily" | "weekly"; | ||
} | ||
|
||
export const spotifyPlaylists: SpotifyPlaylist[] = [ | ||
// Made for You | ||
{ | ||
name: "Daily Mix 1", | ||
id: "37i9dQZF1E376QwloseAfr", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Daily Mix 2", | ||
id: "37i9dQZF1E34T72I0DkmUy", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Daily Mix 3", | ||
id: "37i9dQZF1E39QHotjSEEJ0", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Daily Mix 4", | ||
id: "37i9dQZF1E37s9s5M96nRp", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Daily Mix 5", | ||
id: "37i9dQZF1E35g41kUcLxdn", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Daily Mix 6", | ||
id: "37i9dQZF1E39gipmPQ7hgQ", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Discover Weekly", | ||
id: "37i9dQZEVXcLG1H4N5dmtG", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "Release Radar", | ||
id: "37i9dQZEVXbhEnWhE7TIAb", | ||
updateFrequency: "weekly", | ||
}, | ||
// Punjabi | ||
{ | ||
name: "Punjabi Pyar", | ||
id: "37i9dQZF1DWSKoG4oVafMt", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "Punjabi 101", | ||
id: "37i9dQZF1DX5cZuAHLNjGz", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "Punjabi Pop", | ||
id: "37i9dQZF1DWWwF1YkSKLlU", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "New Music Friday Punjabi", | ||
id: "37i9dQZF1DX5baCFRgbF3x", | ||
updateFrequency: "weekly", | ||
}, | ||
// Hindi | ||
{ | ||
name: "Bollywood Acoustic", | ||
id: "37i9dQZF1DWSwxyU5zGZYe", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "Radar India", | ||
id: "37i9dQZF1DWTAtTdFMiJYK", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "New Music Hindi", | ||
id: "37i9dQZF1DXd8cOUiye1o2", | ||
updateFrequency: "weekly", | ||
}, | ||
// Hindi Indies | ||
{ | ||
name: "hIndies", | ||
id: "37i9dQZF1DWXSzFkaLsPkN", | ||
updateFrequency: "weekly", | ||
}, | ||
{ | ||
name: "Indie India", | ||
id: "37i9dQZF1DX5q67ZpWyRrZ", | ||
updateFrequency: "weekly", | ||
}, | ||
// Global | ||
{ | ||
name: "Top 50 - Global", | ||
id: "37i9dQZEVXbMDoHDwVN2tF", | ||
updateFrequency: "daily", | ||
}, | ||
{ | ||
name: "Viral 50 - Global", | ||
id: "37i9dQZEVXbLiRSasKsNU9", | ||
updateFrequency: "daily", | ||
}, | ||
]; |
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,19 @@ | ||
import { spotifyPlaylists } from "./_constants"; | ||
|
||
export async function GET(): Promise<Response> { | ||
spotifyPlaylists.forEach(async (playlist) => { | ||
const urlSearchParams = new URLSearchParams({ | ||
playlistId: playlist.id, | ||
}); | ||
console.log("Converting playlist:", playlist.name); | ||
const response = await fetch( | ||
`${import.meta.env.SITE}/api/music/sync?${urlSearchParams.toString()}`, | ||
); | ||
if (response.status === 200) { | ||
console.log("Converted playlist:", playlist.name); | ||
} else { | ||
console.log("Failed to convert playlist:", playlist.name); | ||
} | ||
}); | ||
return new Response("Submitted!", { status: 200 }); | ||
} |
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,26 @@ | ||
import type { APIContext, Props } from "astro"; | ||
|
||
export async function GET({ request }: APIContext<Props>): Promise<Response> { | ||
try { | ||
const playlistId = new URL(request.url).searchParams.get("playlistId"); | ||
|
||
if (!playlistId) { | ||
return new Response("Missing playlistId", { status: 400 }); | ||
} | ||
|
||
await fetch("https://playlistor.io/playlist", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Music-User-Token": import.meta.env.MUSIC_TOKEN, | ||
}, | ||
body: JSON.stringify({ | ||
platform: "apple-music", | ||
playlist: `https://open.spotify.com/playlist/${playlistId}`, | ||
}), | ||
}); | ||
} catch (error) { | ||
return new Response("Something went wrong!", { status: 500 }); | ||
} | ||
return new Response("Submitted!", { status: 200 }); | ||
} |
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,8 @@ | ||
{ | ||
"crons": [ | ||
{ | ||
"path": "/api/music", | ||
"schedule": "0 6 * * *" | ||
} | ||
] | ||
} |