@madeinbruno/music-plug 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -2
- package/dist/index.d.ts +103 -0
- package/dist/index.js +163 -0
- package/dist/player.d.ts +75 -0
- package/dist/player.js +227 -0
- package/package.json +48 -4
- package/styles.css +232 -0
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @madeinbruno/music-plug
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
글 속 노래 한 곡을, 듣는 사람이 쓰는 음원 앱에서 듣게 하는 플러그예요. [Music plug](https://musicplug.madeinbruno.com)의 듣기 플러그를 다른 사이트에 붙이는 패키지예요.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
♪ 밤편지 · 아이유 ← 처음 누르면 Music plug 듣기 플러그가 뜬다
|
|
7
|
+
♪ 밤편지 · 아이유 멜론 · 바꾸기 ← 고른 뒤에는 누르면 바로 멜론에서
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
- 처음 누르면 **듣기 플러그**(Music plug 창)가 떠서 어디서 들을지 골라요: YouTube(기본) · 멜론 · 지니 · 벅스 · FLO · VIBE · Spotify · Apple Music · YouTube Music. YouTube는 유튜브 영상이 있으면 이 페이지에서 바로, 없으면 YouTube로 열어요.
|
|
11
|
+
- 고르면 그곳에서 이 곡을 열어요 (폰에서는 앱으로). Music plug가 곡을 찾아 보내요: YouTube·YouTube Music은 그 곡을 바로(시작 시각까지), Apple Music은 곡 페이지, 나머지는 그곳의 검색 결과.
|
|
12
|
+
- 고른 곳은 기억해서 다음부터는 누르면 바로 그곳에서 열어요. 곡 옆의 **바꾸기**로 다시 골라요. madeinbruno.com 아래에서는 Music plug와 같이 기억해요 (쿠키 `mp_service`).
|
|
13
|
+
- YouTube를 고르면 글 안에 유튜브 플레이어를 열어요. 읽어 내려가면 왼쪽 아래에 멈추기·다시 듣기 단추가 떠요. 브라우저가 소리 있는 자동재생을 막아서 한 번은 눌러야 나오고, 유튜브 정책상 플레이어는 보이게 둬요.
|
|
14
|
+
- 곡 정보를 모르면(유튜브에서 제목을 못 받으면) 다른 곳에서 찾을 수 없어서 이 페이지에서 YouTube로만 틀어요.
|
|
15
|
+
- **곡은 유튜브 주소뿐 아니라 여러 곳의 곡 링크로 정할 수 있어요** (`songFromUrl`): YouTube · YouTube Music · 멜론 · 지니 · 벅스 · FLO · VIBE · Spotify · Apple Music. 쓰는 사람은 자기가 쓰는 곳의 곡 링크를 넣고, 듣는 사람은 자기가 쓰는 곳에서 들어요. 듣는 사람이 고른 곳이 곡을 정한 링크와 같은 곳이면 찾지 않고 그 링크를 바로 열어요. 유튜브 링크가 아니면 글 안의 플레이어는 없고, YouTube를 고르면 YouTube에서 그 곡을 찾아 열어요.
|
|
16
|
+
|
|
17
|
+
## 설치
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @madeinbruno/music-plug
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 쓰기 (Next.js 예)
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
// 서버 컴포넌트
|
|
27
|
+
import { songFromUrl } from '@madeinbruno/music-plug';
|
|
28
|
+
import { PlugPlayer } from '@madeinbruno/music-plug/player';
|
|
29
|
+
import '@madeinbruno/music-plug/styles.css'; // 앱에서 한 번만
|
|
30
|
+
|
|
31
|
+
export default async function Post({ music }: { music: string }) {
|
|
32
|
+
const link = await songFromUrl(music); // 곡 링크(유튜브·멜론·Spotify …) → 곡 제목·가수 (하루 캐시). 곡 링크가 아니면 null
|
|
33
|
+
if (!link) return null;
|
|
34
|
+
return (
|
|
35
|
+
<PlugPlayer
|
|
36
|
+
song={link.song} // 못 읽었으면 null
|
|
37
|
+
fallbackLabel="테마 음악"
|
|
38
|
+
youtube={link.youtube} // 유튜브 링크일 때만. 있으면 글 안에서 바로 튼다
|
|
39
|
+
source={link} // 듣는 사람이 같은 곳을 고르면 이 링크를 바로 연다
|
|
40
|
+
avoid=".mib-footer"
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| 내보내는 것 | 설명 |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `PlugPlayer` (`/player`) | 곡 한 줄과 듣기 플러그. `song`(제목·가수, 모르면 `null`), `fallbackLabel`, `youtube`(`id`, `start` 초. 있으면 YouTube를 글 안에서, 없으면 YouTube로 연다), `source`(곡을 정한 링크의 `service`·`url`. 듣는 사람이 같은 곳을 고르면 그 링크를 바로 연다), `avoid`(이 요소가 보이면 멈추기 단추를 숨김), `base`(Music plug 주소, 기본 `https://musicplug.madeinbruno.com`) |
|
|
49
|
+
| `PlugSheet` (`/player`) | 듣기 플러그 창만 따로 |
|
|
50
|
+
| `listenPageUrl(song, youtube?)` | Music plug의 고르는 화면 주소 (`/listen`). 링크로만 걸고 싶을 때. 전에 고른 곳이 있으면 그 화면 없이 바로 그곳으로 가요 |
|
|
51
|
+
| `listenGoUrl(service, song, youtube?)` | 고른 곳에서 이 곡을 여는 주소 (`/listen/go`) |
|
|
52
|
+
| `songFromUrl(link)` | 곡 링크 하나로 그 곡을 읽어요 (서버에서): `{ service, url, song, youtube? }`. 유튜브는 oEmbed로 짐작하고, 그 밖의 곳은 Music plug(`/api/song`)가 그곳의 곡 화면에서 읽어 줘요. 곡 링크가 아니면 `null`, 곡을 못 읽으면 `song`이 `null` |
|
|
53
|
+
| `linkService(link)` | 링크가 어느 곳의 곡 링크인지 주소 모양만 보고 알려 줘요 (입력 칸에서 바로 확인할 때). 곡 링크가 아니면 `null` |
|
|
54
|
+
| `youtubeId(url)`, `youtubeStart(url)` | youtube.com · youtu.be · music.youtube.com · shorts 주소에서 영상 번호와 시작 시각(`t=`) |
|
|
55
|
+
| `songFromYoutube(id)` | 유튜브 oEmbed로 영상 제목·채널을 받아 곡 제목·가수를 짐작 (서버에서). 못 받으면 `null` |
|
|
56
|
+
| `songFromVideo(title, channel)`, `cleanTitle(title)` | 위의 짐작만 따로 ("가수 - 제목", "가수 '제목'", 유튜브 뮤직의 "가수 - Topic" 채널, `(Official MV)` 같은 꼬리표 지우기) |
|
|
57
|
+
| `SERVICES`, `getService(id)` | 들을 수 있는 곳 |
|
|
58
|
+
|
|
59
|
+
곡 줄은 둘러싼 글의 색을 따르고, 듣기 플러그 창은 Music plug 색이에요. 멈추기 단추의 바탕은 `--mp-ground`로 바꿀 수 있어요.
|
|
60
|
+
|
|
61
|
+
## Music plug 쪽
|
|
62
|
+
|
|
63
|
+
듣기 플러그의 본체는 Music plug 앱(`apps/music-plug`)에 있어요.
|
|
64
|
+
- `/listen?t=제목&a=가수[&v=유튜브번호][&start=초][&pick=1]`: 어디서 들을지 고르는 화면. 전에 고른 곳이 있으면 바로 그곳으로 (`pick=1`이면 다시 고른다). 공유받은 플레이리스트의 곡마다 붙은 '듣기'도 여기로 와요.
|
|
65
|
+
- `/api/song?url=곡링크`: 곡 링크 하나로 제목·가수를 읽어 줘요 (`src/server/song`). `songFromUrl`이 불러요.
|
|
66
|
+
- `/listen/go?s=고른곳&…[&remember=1]`: 그곳에서 이 곡을 찾아 보내요 (`src/server/listen.ts`). `remember=1`이면 고른 곳을 기억해요.
|
|
67
|
+
|
|
68
|
+
## 개발
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm --filter @madeinbruno/music-plug test # 곡 정보 짐작 시험
|
|
72
|
+
pnpm --filter @madeinbruno/music-plug build # dist/ 생성
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 배포 (npm)
|
|
76
|
+
|
|
77
|
+
atelier와 같아요 (`.github/workflows/publish-music-plug.yml`). `package.json`의 `version`을 올려 `main`에 푸시하면 Actions가 npm 승인 대기열에 올리고, npmjs.com에서 승인하면 공개돼요.
|
|
78
|
+
|
|
79
|
+
**처음 한 번은 손으로 올려야 해요.** npm의 trusted publishing은 이미 있는 패키지에만 설정할 수 있어서요.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm login
|
|
83
|
+
cd packages/music-plug && pnpm install && pnpm build && npm publish --access public
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
그다음 npmjs.com → `@madeinbruno/music-plug` → Settings → Trusted publishing에 저장소 `codingbotPark/madeinbruno`, 워크플로 `publish-music-plug.yml`을 등록해 두면, 다음 버전부터는 Actions가 올려요.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 들을 수 있는 곳. 앱 Music plug(apps/music-plug/src/server/listen.ts)의 목록과 이름(id)이 같다.
|
|
3
|
+
* 고른 곳은 쿠키 mp_service에 두고, madeinbruno.com 아래에서는 Music plug와 같이 쓴다.
|
|
4
|
+
* - here: YouTube를 이 페이지에서 바로 (글 안에 유튜브 플레이어를 연다). 화면에는 그냥 'YouTube'로 보인다
|
|
5
|
+
* - ytvideo: YouTube (앱·사이트)
|
|
6
|
+
* - youtube: YouTube Music (Music plug의 이름을 따른다)
|
|
7
|
+
*/
|
|
8
|
+
type ServiceId = 'here' | 'ytvideo' | 'melon' | 'genie' | 'bugs' | 'flo' | 'vibe' | 'spotify' | 'apple' | 'youtube';
|
|
9
|
+
type Service = {
|
|
10
|
+
id: ServiceId;
|
|
11
|
+
name: string;
|
|
12
|
+
color: string;
|
|
13
|
+
initial: string;
|
|
14
|
+
};
|
|
15
|
+
declare const SERVICES: Service[];
|
|
16
|
+
declare function getService(id: string | null | undefined): Service | undefined;
|
|
17
|
+
/** Music plug 주소 (듣기 플러그 화면, 고른 곳으로 보내기) */
|
|
18
|
+
declare const MUSIC_PLUG_URL = "https://musicplug.madeinbruno.com";
|
|
19
|
+
type ListenSong = {
|
|
20
|
+
title: string;
|
|
21
|
+
artist: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 고른 곳에서 이 곡을 여는 주소 (Music plug가 받아서 곡을 찾아 보낸다: YouTube·YouTube Music은 그 곡 바로, Apple Music은 곡 페이지, 나머지는 검색 결과).
|
|
25
|
+
* remember면 Music plug가 고른 곳을 기억한다.
|
|
26
|
+
*/
|
|
27
|
+
declare function listenGoUrl(service: ServiceId, song: ListenSong | null, youtube?: {
|
|
28
|
+
id: string;
|
|
29
|
+
start?: number;
|
|
30
|
+
}, { base, remember }?: {
|
|
31
|
+
base?: string | undefined;
|
|
32
|
+
remember?: boolean | undefined;
|
|
33
|
+
}): string;
|
|
34
|
+
/** Music plug의 고르는 화면 주소 (링크로 걸 때) */
|
|
35
|
+
declare function listenPageUrl(song: ListenSong | null, youtube?: {
|
|
36
|
+
id: string;
|
|
37
|
+
start?: number;
|
|
38
|
+
}, { base }?: {
|
|
39
|
+
base?: string | undefined;
|
|
40
|
+
}): string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 유튜브 주소 읽기. 받는 주소: youtube.com/watch?v=…, youtu.be/…, music.youtube.com/watch?v=…, youtube.com/shorts/…, /embed/…, /live/…
|
|
44
|
+
*/
|
|
45
|
+
declare function youtubeId(url: string | null | undefined): string | null;
|
|
46
|
+
/** 시작 시각 (t=90, t=1m30s) → 초 */
|
|
47
|
+
declare function youtubeStart(url: string | null | undefined): number;
|
|
48
|
+
|
|
49
|
+
/** 한 곡. 다른 음원 앱에서 찾을 때 "제목 가수"로 찾는다 */
|
|
50
|
+
type Song = {
|
|
51
|
+
title: string;
|
|
52
|
+
artist: string;
|
|
53
|
+
};
|
|
54
|
+
/** 영상 제목에서 꼬리표 괄호와 'Official MV' 같은 말을 지운다 */
|
|
55
|
+
declare function cleanTitle(title: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* 유튜브 영상 제목·채널로 곡 정보를 짐작한다.
|
|
58
|
+
* - 유튜브 뮤직 곡(채널이 "가수 - Topic")이면 제목이 곧 곡 제목
|
|
59
|
+
* - "가수 - 제목", "가수 '제목'", "가수 「제목」"
|
|
60
|
+
* - 그 밖에는 채널 이름을 가수로
|
|
61
|
+
*/
|
|
62
|
+
declare function songFromVideo(videoTitle: string, channel: string): Song;
|
|
63
|
+
/** 다른 음원 앱에서 찾을 말 */
|
|
64
|
+
declare const songQuery: (song: Song) => string;
|
|
65
|
+
/**
|
|
66
|
+
* 유튜브 영상 하나의 곡 정보 (서버에서). 유튜브 oEmbed로 제목·채널을 받아 짐작한다. 못 받으면 null.
|
|
67
|
+
* Next.js에서는 하루 캐시한다.
|
|
68
|
+
*/
|
|
69
|
+
declare function songFromYoutube(id: string): Promise<Song | null>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 곡 링크. 테마 음악을 유튜브뿐 아니라 쓰는 사람이 쓰는 음원 앱의 곡 링크로도 정할 수 있게 한다.
|
|
73
|
+
* 받는 곳: YouTube · YouTube Music · 멜론 · 지니 · 벅스 · FLO · VIBE · Spotify · Apple Music
|
|
74
|
+
*/
|
|
75
|
+
type SongLink = {
|
|
76
|
+
/** 링크가 가리키는 곳 ('ytvideo'는 YouTube 영상, 'youtube'는 YouTube Music) */
|
|
77
|
+
service: ServiceId;
|
|
78
|
+
/** 곡 주소 (짧은 주소는 풀어서) */
|
|
79
|
+
url: string;
|
|
80
|
+
/** 곡 제목·가수. 못 읽었으면 null */
|
|
81
|
+
song: Song | null;
|
|
82
|
+
/** 유튜브 링크일 때만: 영상 번호와 시작 시각(초). 있으면 글 안에서 바로 틀 수 있다 */
|
|
83
|
+
youtube?: {
|
|
84
|
+
id: string;
|
|
85
|
+
start?: number;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* 이 링크가 어느 곳의 곡 링크인지 (주소 모양만 본다. 화면에서 입력을 바로 확인할 때 쓴다). 곡 링크가 아니면 null.
|
|
90
|
+
* 앱의 공유 버튼이 주는 짧은 주소(kko.to, flomuz.io, spotify.link, naver.me)는 열어 봐야 알아서 그곳의 곡으로 친다.
|
|
91
|
+
*/
|
|
92
|
+
declare function linkService(input: string | null | undefined): ServiceId | null;
|
|
93
|
+
/**
|
|
94
|
+
* 곡 링크 하나로 그 곡을 읽는다 (서버에서). 곡 링크가 아니면 null.
|
|
95
|
+
* - 유튜브·YouTube Music: 유튜브 oEmbed로 제목·채널을 받아 짐작한다 (songFromYoutube)
|
|
96
|
+
* - 그 밖의 곳: Music plug(/api/song)가 그곳의 곡 화면에서 제목·가수를 읽어 준다
|
|
97
|
+
* 곡을 못 읽어도(song이 null) 링크는 돌려주니, 그 링크로는 들을 수 있다. Next.js에서는 하루 캐시한다.
|
|
98
|
+
*/
|
|
99
|
+
declare function songFromUrl(input: string | null | undefined, { base }?: {
|
|
100
|
+
base?: string | undefined;
|
|
101
|
+
}): Promise<SongLink | null>;
|
|
102
|
+
|
|
103
|
+
export { MUSIC_PLUG_URL, SERVICES, type Service, type ServiceId, type Song, type SongLink, cleanTitle, getService, linkService, listenGoUrl, listenPageUrl, songFromUrl, songFromVideo, songFromYoutube, songQuery, youtubeId, youtubeStart };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// src/services.ts
|
|
2
|
+
var SERVICES = [
|
|
3
|
+
{ id: "here", name: "YouTube", color: "#ff0033", initial: "Y" },
|
|
4
|
+
{ id: "ytvideo", name: "YouTube", color: "#ff0033", initial: "Y" },
|
|
5
|
+
{ id: "melon", name: "\uBA5C\uB860", color: "#00cd3c", initial: "M" },
|
|
6
|
+
{ id: "genie", name: "\uC9C0\uB2C8", color: "#2aa8ff", initial: "G" },
|
|
7
|
+
{ id: "bugs", name: "\uBC85\uC2A4", color: "#ff5a3c", initial: "B" },
|
|
8
|
+
{ id: "flo", name: "FLO", color: "#7a6bff", initial: "F" },
|
|
9
|
+
{ id: "vibe", name: "VIBE", color: "#ff4d8d", initial: "V" },
|
|
10
|
+
{ id: "spotify", name: "Spotify", color: "#1ed760", initial: "S" },
|
|
11
|
+
{ id: "apple", name: "Apple Music", color: "#fa586a", initial: "A" },
|
|
12
|
+
{ id: "youtube", name: "YouTube Music", color: "#ff4444", initial: "Y" }
|
|
13
|
+
];
|
|
14
|
+
function getService(id) {
|
|
15
|
+
return SERVICES.find((s) => s.id === id);
|
|
16
|
+
}
|
|
17
|
+
var MUSIC_PLUG_URL = "https://musicplug.madeinbruno.com";
|
|
18
|
+
function tail(song, youtube) {
|
|
19
|
+
const p = new URLSearchParams();
|
|
20
|
+
if (song?.title) p.set("t", song.title);
|
|
21
|
+
if (song?.artist) p.set("a", song.artist);
|
|
22
|
+
if (youtube?.id) p.set("v", youtube.id);
|
|
23
|
+
if (youtube?.start) p.set("start", String(youtube.start));
|
|
24
|
+
return p.toString();
|
|
25
|
+
}
|
|
26
|
+
function listenGoUrl(service, song, youtube, { base = MUSIC_PLUG_URL, remember = false } = {}) {
|
|
27
|
+
return `${base}/listen/go?s=${service}${remember ? "&remember=1" : ""}&${tail(song, youtube)}`;
|
|
28
|
+
}
|
|
29
|
+
function listenPageUrl(song, youtube, { base = MUSIC_PLUG_URL } = {}) {
|
|
30
|
+
return `${base}/listen?${tail(song, youtube)}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/youtube.ts
|
|
34
|
+
function youtubeId(url) {
|
|
35
|
+
if (!url) return null;
|
|
36
|
+
try {
|
|
37
|
+
const u = new URL(url.trim());
|
|
38
|
+
const host = u.hostname.replace(/^(www|m|music)\./, "");
|
|
39
|
+
let id = null;
|
|
40
|
+
if (host === "youtu.be") id = u.pathname.slice(1).split("/")[0];
|
|
41
|
+
else if (host === "youtube.com" || host === "youtube-nocookie.com") {
|
|
42
|
+
id = u.searchParams.get("v") ?? u.pathname.match(/^\/(?:shorts|embed|live)\/([^/]+)/)?.[1] ?? null;
|
|
43
|
+
}
|
|
44
|
+
return id && /^[\w-]{11}$/.test(id) ? id : null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function youtubeStart(url) {
|
|
50
|
+
if (!url) return 0;
|
|
51
|
+
try {
|
|
52
|
+
const t = new URL(url.trim()).searchParams.get("t") ?? "";
|
|
53
|
+
const m = t.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/);
|
|
54
|
+
return m ? Number(m[1] ?? 0) * 3600 + Number(m[2] ?? 0) * 60 + Number(m[3] ?? 0) : 0;
|
|
55
|
+
} catch {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/song.ts
|
|
61
|
+
var TAG = /official|music\s*video|m\/?v|\bmv\b|audio|lyrics?|visuali[sz]er|video|teaser|performance|special|clip|\b4k\b|\bhd\b|\bhq\b|가사|뮤직\s*비디오|공식|full\s*ver/i;
|
|
62
|
+
var BRACKETS = /\s*[([【「『〔{]([^)\]】」』〕}]*)[)\]】」』〕}]/g;
|
|
63
|
+
function cleanTitle(title) {
|
|
64
|
+
return title.replace(BRACKETS, (all, inner) => TAG.test(inner) ? "" : all).replace(/\s*(official\s*)?(music\s*video|m\/v|mv|audio|lyric\s*video)\s*$/i, "").replace(/\s{2,}/g, " ").trim();
|
|
65
|
+
}
|
|
66
|
+
function cleanChannel(name) {
|
|
67
|
+
return name.replace(/\s*-\s*Topic$/i, "").replace(/vevo$/i, "").replace(/\s*(official|공식|channel|채널)\s*$/i, "").trim();
|
|
68
|
+
}
|
|
69
|
+
function songFromVideo(videoTitle, channel) {
|
|
70
|
+
if (/\s-\s*Topic$/i.test(channel)) return { title: cleanTitle(videoTitle), artist: cleanChannel(channel) };
|
|
71
|
+
const t = cleanTitle(videoTitle);
|
|
72
|
+
const dash = t.match(/^(.+?)\s+[-–—]\s+(.+)$/);
|
|
73
|
+
if (dash) return { artist: dash[1].trim(), title: dash[2].trim() };
|
|
74
|
+
const quoted = t.match(/^(.+?)\s*['"‘“「『](.+?)['"’”」』]/);
|
|
75
|
+
if (quoted) return { artist: quoted[1].trim(), title: quoted[2].trim() };
|
|
76
|
+
return { title: t, artist: cleanChannel(channel) };
|
|
77
|
+
}
|
|
78
|
+
var songQuery = (song) => [song.title, song.artist].filter(Boolean).join(" ");
|
|
79
|
+
async function songFromYoutube(id) {
|
|
80
|
+
try {
|
|
81
|
+
const url = `https://www.youtube.com/oembed?url=${encodeURIComponent(`https://www.youtube.com/watch?v=${id}`)}&format=json`;
|
|
82
|
+
const res = await fetch(url, { next: { revalidate: 86400 }, signal: AbortSignal.timeout(3e3) });
|
|
83
|
+
if (!res.ok) return null;
|
|
84
|
+
const data = await res.json();
|
|
85
|
+
if (!data.title) return null;
|
|
86
|
+
return songFromVideo(data.title, data.author_name ?? "");
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/link.ts
|
|
93
|
+
var is = (host, domain) => host === domain || host.endsWith(`.${domain}`);
|
|
94
|
+
function firstUrl(input) {
|
|
95
|
+
const found = input?.match(/https?:\/\/[^\s<>"']+/)?.[0];
|
|
96
|
+
if (!found) return null;
|
|
97
|
+
try {
|
|
98
|
+
return new URL(found);
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function linkService(input) {
|
|
104
|
+
const url = firstUrl(input);
|
|
105
|
+
if (!url) return null;
|
|
106
|
+
const host = url.hostname.toLowerCase();
|
|
107
|
+
const path = url.pathname;
|
|
108
|
+
if (is(host, "youtube.com") || is(host, "youtu.be")) {
|
|
109
|
+
if (!youtubeId(url.href)) return null;
|
|
110
|
+
return is(host, "music.youtube.com") ? "youtube" : "ytvideo";
|
|
111
|
+
}
|
|
112
|
+
if (is(host, "melon.com")) return url.searchParams.has("songId") || /^s/i.test(url.searchParams.get("type") ?? "") ? "melon" : null;
|
|
113
|
+
if (is(host, "kko.to")) return "melon";
|
|
114
|
+
if (is(host, "genie.co.kr")) return url.searchParams.has("xgnm") || !/playlist/i.test(path) ? "genie" : null;
|
|
115
|
+
if (is(host, "bugs.co.kr")) return /\/track\/\d+/.test(path) ? "bugs" : null;
|
|
116
|
+
if (is(host, "music-flo.com")) return /\/detail\/track\//.test(path) ? "flo" : null;
|
|
117
|
+
if (is(host, "flomuz.io")) return "flo";
|
|
118
|
+
if (is(host, "vibe.naver.com")) return /\/track\/\d+/.test(path) ? "vibe" : null;
|
|
119
|
+
if (is(host, "naver.me")) return "vibe";
|
|
120
|
+
if (is(host, "open.spotify.com")) return /\/track\//.test(path) ? "spotify" : null;
|
|
121
|
+
if (is(host, "spotify.link")) return "spotify";
|
|
122
|
+
if (is(host, "music.apple.com")) return url.searchParams.has("i") || /\/song\//.test(path) ? "apple" : null;
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
async function songFromUrl(input, { base = MUSIC_PLUG_URL } = {}) {
|
|
126
|
+
const service = linkService(input);
|
|
127
|
+
const url = firstUrl(input);
|
|
128
|
+
if (!service || !url) return null;
|
|
129
|
+
const id = youtubeId(url.href);
|
|
130
|
+
if (id) {
|
|
131
|
+
const start = youtubeStart(url.href);
|
|
132
|
+
return { service, url: url.href, song: await songFromYoutube(id), youtube: { id, ...start ? { start } : {} } };
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const res = await fetch(`${base}/api/song?url=${encodeURIComponent(url.href)}`, {
|
|
136
|
+
next: { revalidate: 86400 },
|
|
137
|
+
signal: AbortSignal.timeout(1e4)
|
|
138
|
+
});
|
|
139
|
+
if (res.ok) {
|
|
140
|
+
const data = await res.json();
|
|
141
|
+
if (data.title) {
|
|
142
|
+
return { service: data.service ?? service, url: data.url ?? url.href, song: { title: data.title, artist: data.artist ?? "" } };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
}
|
|
147
|
+
return { service, url: url.href, song: null };
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
MUSIC_PLUG_URL,
|
|
151
|
+
SERVICES,
|
|
152
|
+
cleanTitle,
|
|
153
|
+
getService,
|
|
154
|
+
linkService,
|
|
155
|
+
listenGoUrl,
|
|
156
|
+
listenPageUrl,
|
|
157
|
+
songFromUrl,
|
|
158
|
+
songFromVideo,
|
|
159
|
+
songFromYoutube,
|
|
160
|
+
songQuery,
|
|
161
|
+
youtubeId,
|
|
162
|
+
youtubeStart
|
|
163
|
+
};
|
package/dist/player.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 들을 수 있는 곳. 앱 Music plug(apps/music-plug/src/server/listen.ts)의 목록과 이름(id)이 같다.
|
|
5
|
+
* 고른 곳은 쿠키 mp_service에 두고, madeinbruno.com 아래에서는 Music plug와 같이 쓴다.
|
|
6
|
+
* - here: YouTube를 이 페이지에서 바로 (글 안에 유튜브 플레이어를 연다). 화면에는 그냥 'YouTube'로 보인다
|
|
7
|
+
* - ytvideo: YouTube (앱·사이트)
|
|
8
|
+
* - youtube: YouTube Music (Music plug의 이름을 따른다)
|
|
9
|
+
*/
|
|
10
|
+
type ServiceId = 'here' | 'ytvideo' | 'melon' | 'genie' | 'bugs' | 'flo' | 'vibe' | 'spotify' | 'apple' | 'youtube';
|
|
11
|
+
type Service = {
|
|
12
|
+
id: ServiceId;
|
|
13
|
+
name: string;
|
|
14
|
+
color: string;
|
|
15
|
+
initial: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** 한 곡. 다른 음원 앱에서 찾을 때 "제목 가수"로 찾는다 */
|
|
19
|
+
type Song = {
|
|
20
|
+
title: string;
|
|
21
|
+
artist: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 글 속 노래 한 곡의 '음악 듣기'.
|
|
26
|
+
*
|
|
27
|
+
* ♪ 밤편지 · 아이유
|
|
28
|
+
*
|
|
29
|
+
* - 처음 누르면 Music plug 듣기 플러그(PlugSheet)가 떠서 어디서 들을지 고른다:
|
|
30
|
+
* YouTube(기본) · 멜론 · 지니 · 벅스 · FLO · VIBE · Spotify · Apple Music · YouTube Music
|
|
31
|
+
* YouTube는 유튜브 영상이 있으면 이 페이지에서 바로(글 안의 플레이어), 없으면 YouTube로 연다.
|
|
32
|
+
* - 고르면 그곳에서 이 곡을 연다 (Music plug가 곡을 찾아 보낸다. 폰에서는 앱으로). YouTube면 글 안에서 유튜브 플레이어가 열린다.
|
|
33
|
+
* - 고른 곳은 기억해서 다음부터는 누르면 바로 그곳에서 연다. 곡 옆에 옅게 '멜론 · 바꾸기'가 보이고, 바꾸기로 다시 고른다.
|
|
34
|
+
* 기억은 쿠키 mp_service(madeinbruno.com 아래에서는 Music plug와 같이)와 이 브라우저(localStorage)에 둔다.
|
|
35
|
+
* - 곡을 모르면(song이 null) 다른 곳에서 찾을 수 없어서 이 페이지에서 YouTube로만 튼다 (유튜브가 아닌 곡 링크면 그 링크를 연다).
|
|
36
|
+
* - 테마 음악을 정한 곡 링크(source)가 있으면, 듣는 사람이 같은 곳을 골랐을 때 찾지 않고 그 링크를 바로 연다.
|
|
37
|
+
* - 유튜브로 듣는 중에 읽어 내려가 플레이어가 화면 밖으로 나가면 왼쪽 아래에 멈추기·다시 듣기 단추가 뜬다 (avoid로 준 요소가 보일 때는 숨긴다).
|
|
38
|
+
*
|
|
39
|
+
* 스타일은 '@madeinbruno/music-plug/styles.css' (클래스는 모두 mp-). 곡 줄은 둘러싼 글의 색을 따르고, 듣기 플러그는 Music plug 색이다.
|
|
40
|
+
*/
|
|
41
|
+
type PlugPlayerProps = {
|
|
42
|
+
/** 곡 제목·가수. 모르면 null */
|
|
43
|
+
song: Song | null;
|
|
44
|
+
/** 곡을 모를 때 보일 이름 (기본: '음악 듣기') */
|
|
45
|
+
fallbackLabel?: string;
|
|
46
|
+
/** 유튜브 영상. 있으면 YouTube를 고를 때 글 안에서 바로 틀고, 없으면 YouTube로 연다 */
|
|
47
|
+
youtube?: {
|
|
48
|
+
id: string;
|
|
49
|
+
start?: number;
|
|
50
|
+
};
|
|
51
|
+
/** 이 곡을 정한 곡 링크 (songFromUrl이 준 service·url). 듣는 사람이 같은 곳을 고르면 그 링크를 바로 연다 */
|
|
52
|
+
source?: {
|
|
53
|
+
service: ServiceId;
|
|
54
|
+
url: string;
|
|
55
|
+
};
|
|
56
|
+
/** 유튜브 플레이어가 화면 밖일 때 뜨는 멈추기 단추를, 이 요소가 보이면 숨긴다 (예: '.mib-footer') */
|
|
57
|
+
avoid?: string;
|
|
58
|
+
/** Music plug 주소 (기본 https://musicplug.madeinbruno.com) */
|
|
59
|
+
base?: string;
|
|
60
|
+
className?: string;
|
|
61
|
+
};
|
|
62
|
+
declare function PlugPlayer({ song, fallbackLabel, youtube, source, avoid, base, className }: PlugPlayerProps): react.JSX.Element;
|
|
63
|
+
/**
|
|
64
|
+
* Music plug 듣기 플러그: 어디서 들을지 고르는 창. Music plug의 /listen 화면과 같은 모양.
|
|
65
|
+
* 바깥을 누르거나 Esc로 닫는다.
|
|
66
|
+
*/
|
|
67
|
+
declare function PlugSheet({ song, services, current, onChoose, onClose, }: {
|
|
68
|
+
song: Song | null;
|
|
69
|
+
services: Service[];
|
|
70
|
+
current: ServiceId | null;
|
|
71
|
+
onChoose: (s: Service) => void;
|
|
72
|
+
onClose: () => void;
|
|
73
|
+
}): react.JSX.Element;
|
|
74
|
+
|
|
75
|
+
export { PlugPlayer, type PlugPlayerProps, PlugSheet };
|
package/dist/player.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/player.tsx
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
// src/logos.ts
|
|
7
|
+
var YT = "M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z";
|
|
8
|
+
var LOGO_PATHS = {
|
|
9
|
+
here: YT,
|
|
10
|
+
ytvideo: YT,
|
|
11
|
+
spotify: "M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.779-.179-.899-.539-.12-.421.18-.78.54-.9 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.301 1.02zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.419 1.56-.299.421-1.02.599-1.559.3z",
|
|
12
|
+
apple: "M23.994 6.124a9.23 9.23 0 00-.24-2.19c-.317-1.31-1.062-2.31-2.18-3.043a5.022 5.022 0 00-1.877-.726 10.496 10.496 0 00-1.564-.15c-.04-.003-.083-.01-.124-.013H5.986c-.152.01-.303.017-.455.026-.747.043-1.49.123-2.193.4-1.336.53-2.3 1.452-2.865 2.78-.192.448-.292.925-.363 1.408-.056.392-.088.785-.1 1.18 0 .032-.007.062-.01.093v12.223c.01.14.017.283.027.424.05.815.154 1.624.497 2.373.65 1.42 1.738 2.353 3.234 2.801.42.127.856.187 1.293.228.555.053 1.11.06 1.667.06h11.03a12.5 12.5 0 001.57-.1c.822-.106 1.596-.35 2.295-.81a5.046 5.046 0 001.88-2.207c.186-.42.293-.87.37-1.324.113-.675.138-1.358.137-2.04-.002-3.8 0-7.595-.003-11.393zm-6.423 3.99v5.712c0 .417-.058.827-.244 1.206-.29.59-.76.962-1.388 1.14-.35.1-.706.157-1.07.173-.95.045-1.773-.6-1.943-1.536a1.88 1.88 0 011.038-2.022c.323-.16.67-.25 1.018-.324.378-.082.758-.153 1.134-.24.274-.063.457-.23.51-.516a.904.904 0 00.02-.193c0-1.815 0-3.63-.002-5.443a.725.725 0 00-.026-.185c-.04-.15-.15-.243-.304-.234-.16.01-.318.035-.475.066-.76.15-1.52.303-2.28.456l-2.325.47-1.374.278c-.016.003-.032.01-.048.013-.277.077-.377.203-.39.49-.002.042 0 .086 0 .13-.002 2.602 0 5.204-.003 7.805 0 .42-.047.836-.215 1.227-.278.64-.77 1.04-1.434 1.233-.35.1-.71.16-1.075.172-.96.036-1.755-.6-1.92-1.544-.14-.812.23-1.685 1.154-2.075.357-.15.73-.232 1.108-.31.287-.06.575-.116.86-.177.383-.083.583-.323.6-.714v-.15c0-2.96 0-5.922.002-8.882 0-.123.013-.25.042-.37.07-.285.273-.448.546-.518.255-.066.515-.112.774-.165.733-.15 1.466-.296 2.2-.444l2.27-.46c.67-.134 1.34-.27 2.01-.403.22-.043.442-.088.663-.106.31-.025.523.17.554.482.008.073.012.148.012.223.002 1.91.002 3.822 0 5.732z",
|
|
13
|
+
youtube: "M12 0C5.376 0 0 5.376 0 12s5.376 12 12 12 12-5.376 12-12S18.624 0 12 0zm0 19.104c-3.924 0-7.104-3.18-7.104-7.104S8.076 4.896 12 4.896s7.104 3.18 7.104 7.104-3.18 7.104-7.104 7.104zm0-13.332c-3.432 0-6.228 2.796-6.228 6.228S8.568 18.228 12 18.228s6.228-2.796 6.228-6.228S15.432 5.772 12 5.772zM9.684 15.54V8.46L15.816 12l-6.132 3.54z"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/services.ts
|
|
17
|
+
var SERVICES = [
|
|
18
|
+
{ id: "here", name: "YouTube", color: "#ff0033", initial: "Y" },
|
|
19
|
+
{ id: "ytvideo", name: "YouTube", color: "#ff0033", initial: "Y" },
|
|
20
|
+
{ id: "melon", name: "\uBA5C\uB860", color: "#00cd3c", initial: "M" },
|
|
21
|
+
{ id: "genie", name: "\uC9C0\uB2C8", color: "#2aa8ff", initial: "G" },
|
|
22
|
+
{ id: "bugs", name: "\uBC85\uC2A4", color: "#ff5a3c", initial: "B" },
|
|
23
|
+
{ id: "flo", name: "FLO", color: "#7a6bff", initial: "F" },
|
|
24
|
+
{ id: "vibe", name: "VIBE", color: "#ff4d8d", initial: "V" },
|
|
25
|
+
{ id: "spotify", name: "Spotify", color: "#1ed760", initial: "S" },
|
|
26
|
+
{ id: "apple", name: "Apple Music", color: "#fa586a", initial: "A" },
|
|
27
|
+
{ id: "youtube", name: "YouTube Music", color: "#ff4444", initial: "Y" }
|
|
28
|
+
];
|
|
29
|
+
function getService(id) {
|
|
30
|
+
return SERVICES.find((s) => s.id === id);
|
|
31
|
+
}
|
|
32
|
+
var MUSIC_PLUG_URL = "https://musicplug.madeinbruno.com";
|
|
33
|
+
function tail(song, youtube) {
|
|
34
|
+
const p = new URLSearchParams();
|
|
35
|
+
if (song?.title) p.set("t", song.title);
|
|
36
|
+
if (song?.artist) p.set("a", song.artist);
|
|
37
|
+
if (youtube?.id) p.set("v", youtube.id);
|
|
38
|
+
if (youtube?.start) p.set("start", String(youtube.start));
|
|
39
|
+
return p.toString();
|
|
40
|
+
}
|
|
41
|
+
function listenGoUrl(service, song, youtube, { base = MUSIC_PLUG_URL, remember = false } = {}) {
|
|
42
|
+
return `${base}/listen/go?s=${service}${remember ? "&remember=1" : ""}&${tail(song, youtube)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/player.tsx
|
|
46
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
47
|
+
var KEY = "musicplug.service";
|
|
48
|
+
var SHARED_DOMAIN = "madeinbruno.com";
|
|
49
|
+
function readChoice() {
|
|
50
|
+
const cookie = document.cookie.match(/(?:^|;\s*)mp_service=([^;]+)/)?.[1];
|
|
51
|
+
let stored = null;
|
|
52
|
+
try {
|
|
53
|
+
stored = localStorage.getItem(KEY);
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
return getService(cookie)?.id ?? getService(stored)?.id ?? null;
|
|
57
|
+
}
|
|
58
|
+
function saveChoice(id) {
|
|
59
|
+
try {
|
|
60
|
+
localStorage.setItem(KEY, id);
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
const host = location.hostname;
|
|
64
|
+
const shared = host === SHARED_DOMAIN || host.endsWith(`.${SHARED_DOMAIN}`) ? `; domain=.${SHARED_DOMAIN}` : "";
|
|
65
|
+
document.cookie = `mp_service=${id}; path=/; max-age=31536000; samesite=lax${shared}`;
|
|
66
|
+
}
|
|
67
|
+
function PlugPlayer({ song, fallbackLabel = "\uC74C\uC545 \uB4E3\uAE30", youtube, source, avoid, base = MUSIC_PLUG_URL, className }) {
|
|
68
|
+
const [choice, setChoice] = useState(null);
|
|
69
|
+
const [sheet, setSheet] = useState(false);
|
|
70
|
+
const [open, setOpen] = useState(false);
|
|
71
|
+
const [playing, setPlaying] = useState(false);
|
|
72
|
+
const [chip, setChip] = useState(false);
|
|
73
|
+
const frame = useRef(null);
|
|
74
|
+
useEffect(() => setChoice(readChoice()), []);
|
|
75
|
+
const known = Boolean(song?.title);
|
|
76
|
+
const services = SERVICES.filter((s) => s.id === "here" ? Boolean(youtube) : s.id === "ytvideo" ? !youtube : known);
|
|
77
|
+
const isYoutube = (id) => id === "here" || id === "ytvideo";
|
|
78
|
+
const remembered = services.find((s) => s.id === choice || isYoutube(choice) && isYoutube(s.id)) ?? null;
|
|
79
|
+
function play(s) {
|
|
80
|
+
if (s.id === "here") {
|
|
81
|
+
setOpen(true);
|
|
82
|
+
setPlaying(true);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const direct = source && source.service === s.id && !youtube ? source.url : null;
|
|
86
|
+
window.open(direct ?? listenGoUrl(s.id, song, youtube, { base }), "_blank", "noopener");
|
|
87
|
+
}
|
|
88
|
+
function choose(s) {
|
|
89
|
+
saveChoice(s.id);
|
|
90
|
+
setChoice(s.id);
|
|
91
|
+
setSheet(false);
|
|
92
|
+
play(s);
|
|
93
|
+
}
|
|
94
|
+
function tap() {
|
|
95
|
+
if (!known && youtube) return play(SERVICES[0]);
|
|
96
|
+
if (!known && source) return void window.open(source.url, "_blank", "noopener");
|
|
97
|
+
if (remembered) play(remembered);
|
|
98
|
+
else setSheet(true);
|
|
99
|
+
}
|
|
100
|
+
const command = (func) => frame.current?.contentWindow?.postMessage(JSON.stringify({ event: "command", func, args: [] }), "https://www.youtube-nocookie.com");
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (!open) return;
|
|
103
|
+
const seen = /* @__PURE__ */ new Map();
|
|
104
|
+
const io = new IntersectionObserver((entries) => {
|
|
105
|
+
for (const e of entries) seen.set(e.target, e.isIntersecting);
|
|
106
|
+
setChip(![...seen.values()].some(Boolean));
|
|
107
|
+
});
|
|
108
|
+
const targets = [frame.current, avoid ? document.querySelector(avoid) : null].filter((el) => el !== null);
|
|
109
|
+
for (const el of targets) {
|
|
110
|
+
seen.set(el, false);
|
|
111
|
+
io.observe(el);
|
|
112
|
+
}
|
|
113
|
+
return () => io.disconnect();
|
|
114
|
+
}, [open, avoid]);
|
|
115
|
+
const label = song && [song.title, song.artist].filter(Boolean).join(" \xB7 ") || fallbackLabel;
|
|
116
|
+
return /* @__PURE__ */ jsxs("div", { className: ["mp-plug", className].filter(Boolean).join(" "), children: [
|
|
117
|
+
/* @__PURE__ */ jsxs("div", { className: "mp-plug__row", children: [
|
|
118
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "mp-plug__song", onClick: tap, children: [
|
|
119
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u266A" }),
|
|
120
|
+
" ",
|
|
121
|
+
label
|
|
122
|
+
] }),
|
|
123
|
+
known && remembered && /* @__PURE__ */ jsxs("span", { className: "mp-plug__where", children: [
|
|
124
|
+
remembered.name,
|
|
125
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
126
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => setSheet(true), children: "\uBC14\uAFB8\uAE30" })
|
|
127
|
+
] })
|
|
128
|
+
] }),
|
|
129
|
+
open && youtube && /* @__PURE__ */ jsx("div", { className: "mp-plug__frame", children: /* @__PURE__ */ jsx(
|
|
130
|
+
"iframe",
|
|
131
|
+
{
|
|
132
|
+
ref: frame,
|
|
133
|
+
src: `https://www.youtube-nocookie.com/embed/${youtube.id}?autoplay=1&playsinline=1&rel=0&enablejsapi=1${youtube.start ? `&start=${youtube.start}` : ""}`,
|
|
134
|
+
title: label,
|
|
135
|
+
allow: "autoplay; encrypted-media; picture-in-picture",
|
|
136
|
+
allowFullScreen: true
|
|
137
|
+
}
|
|
138
|
+
) }),
|
|
139
|
+
open && chip && /* @__PURE__ */ jsxs(
|
|
140
|
+
"button",
|
|
141
|
+
{
|
|
142
|
+
type: "button",
|
|
143
|
+
className: "mp-plug__chip",
|
|
144
|
+
onClick: () => {
|
|
145
|
+
command(playing ? "pauseVideo" : "playVideo");
|
|
146
|
+
setPlaying(!playing);
|
|
147
|
+
},
|
|
148
|
+
children: [
|
|
149
|
+
"\u266A ",
|
|
150
|
+
playing ? "\uBA48\uCD94\uAE30" : "\uB2E4\uC2DC \uB4E3\uAE30"
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
sheet && /* @__PURE__ */ jsx(PlugSheet, { song, services, current: remembered?.id ?? null, onChoose: choose, onClose: () => setSheet(false) })
|
|
155
|
+
] });
|
|
156
|
+
}
|
|
157
|
+
function PlugSheet({
|
|
158
|
+
song,
|
|
159
|
+
services,
|
|
160
|
+
current,
|
|
161
|
+
onChoose,
|
|
162
|
+
onClose
|
|
163
|
+
}) {
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
const onKey = (e) => e.key === "Escape" && onClose();
|
|
166
|
+
window.addEventListener("keydown", onKey);
|
|
167
|
+
const prev = document.body.style.overflow;
|
|
168
|
+
document.body.style.overflow = "hidden";
|
|
169
|
+
return () => {
|
|
170
|
+
window.removeEventListener("keydown", onKey);
|
|
171
|
+
document.body.style.overflow = prev;
|
|
172
|
+
};
|
|
173
|
+
}, [onClose]);
|
|
174
|
+
return /* @__PURE__ */ jsx("div", { className: "mp-sheet", role: "dialog", "aria-modal": "true", "aria-label": "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694", onClick: (e) => e.target === e.currentTarget && onClose(), children: /* @__PURE__ */ jsxs("div", { className: "mp-sheet__panel", children: [
|
|
175
|
+
/* @__PURE__ */ jsxs("div", { className: "mp-sheet__head", children: [
|
|
176
|
+
/* @__PURE__ */ jsxs("span", { className: "mp-sheet__brand", children: [
|
|
177
|
+
/* @__PURE__ */ jsx(Symbol, {}),
|
|
178
|
+
" Music plug"
|
|
179
|
+
] }),
|
|
180
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "mp-sheet__close", onClick: onClose, "aria-label": "\uB2EB\uAE30", children: "\xD7" })
|
|
181
|
+
] }),
|
|
182
|
+
song?.title && /* @__PURE__ */ jsxs("div", { className: "mp-sheet__song", children: [
|
|
183
|
+
/* @__PURE__ */ jsx("p", { className: "mp-sheet__song-title", children: song.title }),
|
|
184
|
+
song.artist && /* @__PURE__ */ jsx("p", { className: "mp-sheet__sub", children: song.artist })
|
|
185
|
+
] }),
|
|
186
|
+
/* @__PURE__ */ jsx("p", { className: "mp-sheet__ask", children: "\uC5B4\uB514\uC11C \uB4E4\uC744\uAE4C\uC694?" }),
|
|
187
|
+
/* @__PURE__ */ jsx("ul", { className: "mp-sheet__grid", children: services.map((s) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
|
|
188
|
+
"button",
|
|
189
|
+
{
|
|
190
|
+
type: "button",
|
|
191
|
+
"aria-current": (current ? s.id === current : s.id === "here" || s.id === "ytvideo") ? "true" : void 0,
|
|
192
|
+
onClick: () => onChoose(s),
|
|
193
|
+
children: [
|
|
194
|
+
/* @__PURE__ */ jsx(Mark, { service: s }),
|
|
195
|
+
/* @__PURE__ */ jsx("span", { children: s.name }),
|
|
196
|
+
(s.id === "here" || s.id === "ytvideo") && /* @__PURE__ */ jsx("span", { className: "mp-sheet__tag", children: "\uAE30\uBCF8" })
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
) }, s.id)) }),
|
|
200
|
+
/* @__PURE__ */ jsx("p", { className: "mp-sheet__note", children: "\uACE0\uB978 \uACF3\uC740 \uAE30\uC5B5\uD574 \uB450\uACE0 \uB2E4\uC74C\uBD80\uD130 \uBC14\uB85C \uADF8\uACF3\uC5D0\uC11C \uC5F4\uC5B4\uC694. \uACE1 \uC606\uC758 \u2018\uBC14\uAFB8\uAE30\u2019\uB85C \uB2E4\uC2DC \uACE0\uB97C \uC218 \uC788\uC5B4\uC694." })
|
|
201
|
+
] }) });
|
|
202
|
+
}
|
|
203
|
+
function Mark({ service }) {
|
|
204
|
+
const logo = LOGO_PATHS[service.id];
|
|
205
|
+
return /* @__PURE__ */ jsx("svg", { width: "26", height: "26", viewBox: "0 0 24 24", "aria-hidden": "true", className: "mp-sheet__mark", children: logo ? /* @__PURE__ */ jsx("path", { d: logo, fill: service.color }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
206
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "12", fill: service.color }),
|
|
207
|
+
/* @__PURE__ */ jsx("text", { x: "12", y: "16.8", textAnchor: "middle", fontSize: "13.5", fontWeight: "800", fill: "#0b0b0d", children: service.initial })
|
|
208
|
+
] }) });
|
|
209
|
+
}
|
|
210
|
+
function Symbol() {
|
|
211
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 64 64", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("g", { transform: "translate(0 3.5)", children: [
|
|
212
|
+
/* @__PURE__ */ jsx("rect", { x: "21.5", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
|
|
213
|
+
/* @__PURE__ */ jsx("rect", { x: "37", y: "8.5", width: "5.5", height: "13", rx: "2.75", fill: "#f2f2ee" }),
|
|
214
|
+
/* @__PURE__ */ jsx("rect", { x: "12", y: "19", width: "40", height: "29", rx: "5", fill: "#f2f2ee" }),
|
|
215
|
+
/* @__PURE__ */ jsxs("g", { fill: "#141417", children: [
|
|
216
|
+
/* @__PURE__ */ jsx("rect", { x: "17.9", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" }),
|
|
217
|
+
/* @__PURE__ */ jsx("rect", { x: "24.1", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
|
|
218
|
+
/* @__PURE__ */ jsx("rect", { x: "30.3", y: "24.5", width: "3.4", height: "18", rx: "1.7" }),
|
|
219
|
+
/* @__PURE__ */ jsx("rect", { x: "36.5", y: "27.25", width: "3.4", height: "12.5", rx: "1.7" }),
|
|
220
|
+
/* @__PURE__ */ jsx("rect", { x: "42.7", y: "30.25", width: "3.4", height: "6.5", rx: "1.7" })
|
|
221
|
+
] })
|
|
222
|
+
] }) });
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
PlugPlayer,
|
|
226
|
+
PlugSheet
|
|
227
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madeinbruno/music-plug",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "글 속 노래를 듣는 사람이 쓰는 음원 앱(멜론·지니·벅스·FLO·VIBE·Spotify·Apple Music·YouTube Music)에서, 없으면 YouTube로 바로 듣게 하는 플러그",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "codingbotPark <pbk575@gmail.com>",
|
|
7
|
+
"homepage": "https://madeinbruno.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/codingbotPark/madeinbruno.git",
|
|
11
|
+
"directory": "packages/music-plug"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"*.css"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./player": {
|
|
25
|
+
"types": "./dist/player.d.ts",
|
|
26
|
+
"import": "./dist/player.js"
|
|
27
|
+
},
|
|
28
|
+
"./styles.css": "./styles.css"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"styles.css"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"check": "tsc --noEmit",
|
|
38
|
+
"test": "tsup && node --test --experimental-strip-types src/*.test.ts",
|
|
39
|
+
"prepublishOnly": "pnpm build"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/react": "^19",
|
|
46
|
+
"react": "19.2.3",
|
|
47
|
+
"tsup": "^8.5.0",
|
|
48
|
+
"typescript": "^5"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/styles.css
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/* @madeinbruno/music-plug 스타일. 쓰는 쪽에서 한 번만 불러온다: import '@madeinbruno/music-plug/styles.css'
|
|
2
|
+
클래스 이름은 모두 mp- 로 시작한다.
|
|
3
|
+
- 곡 줄(.mp-plug)은 둘러싼 글의 색(currentColor)을 따라서 밝은·어두운 화면 어디서나 맞는다.
|
|
4
|
+
멈추기 단추의 바탕은 --mp-ground로 바꿀 수 있다 (기본: 흰색 반투명).
|
|
5
|
+
- 듣기 플러그(.mp-sheet)는 Music plug 색(검은 바탕, 노란 고른 표시)이다. */
|
|
6
|
+
|
|
7
|
+
.mp-plug {
|
|
8
|
+
--mp-ground: rgba(255, 255, 255, 0.92);
|
|
9
|
+
font-size: 14px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.mp-plug button,
|
|
13
|
+
.mp-sheet button {
|
|
14
|
+
padding: 0;
|
|
15
|
+
border: 0;
|
|
16
|
+
background: none;
|
|
17
|
+
color: inherit;
|
|
18
|
+
font: inherit;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.mp-plug__row {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-wrap: wrap;
|
|
25
|
+
align-items: baseline;
|
|
26
|
+
gap: 4px 10px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.mp-plug__song {
|
|
30
|
+
text-align: left;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.mp-plug__where {
|
|
34
|
+
opacity: 0.55;
|
|
35
|
+
font-size: 13px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.mp-plug__where button {
|
|
39
|
+
text-decoration: underline;
|
|
40
|
+
text-underline-offset: 3px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.mp-plug__frame {
|
|
44
|
+
margin-top: 10px;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
border-radius: 2px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.mp-plug__frame iframe {
|
|
50
|
+
display: block;
|
|
51
|
+
width: 100%;
|
|
52
|
+
aspect-ratio: 16 / 9;
|
|
53
|
+
border: 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.mp-plug__chip {
|
|
57
|
+
position: fixed;
|
|
58
|
+
bottom: 16px;
|
|
59
|
+
left: 16px;
|
|
60
|
+
z-index: 40;
|
|
61
|
+
max-width: 60vw;
|
|
62
|
+
padding: 6px 14px !important;
|
|
63
|
+
border: 1px solid currentColor !important;
|
|
64
|
+
border-radius: 999px;
|
|
65
|
+
background: var(--mp-ground) !important;
|
|
66
|
+
opacity: 0.85;
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
text-overflow: ellipsis;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* ───────── 듣기 플러그 (Music plug) ───────── */
|
|
73
|
+
|
|
74
|
+
.mp-sheet {
|
|
75
|
+
--mp-bg: #0b0b0d;
|
|
76
|
+
--mp-panel: #141417;
|
|
77
|
+
--mp-line: #2c2c33;
|
|
78
|
+
--mp-ink: #f2f2ee;
|
|
79
|
+
--mp-sub: #9a9aa5;
|
|
80
|
+
--mp-core: #ffe14a;
|
|
81
|
+
position: fixed;
|
|
82
|
+
inset: 0;
|
|
83
|
+
z-index: 60;
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: flex-end;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
background: rgba(0, 0, 0, 0.45);
|
|
88
|
+
font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Segoe UI', sans-serif;
|
|
89
|
+
animation: mp-fade 140ms ease-out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@media (min-width: 640px) {
|
|
93
|
+
.mp-sheet {
|
|
94
|
+
align-items: center;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.mp-sheet__panel {
|
|
99
|
+
box-sizing: border-box;
|
|
100
|
+
width: 100%;
|
|
101
|
+
max-width: 420px;
|
|
102
|
+
max-height: 88vh;
|
|
103
|
+
overflow-y: auto;
|
|
104
|
+
padding: 20px 20px 24px;
|
|
105
|
+
border-radius: 20px 20px 0 0;
|
|
106
|
+
background: var(--mp-bg);
|
|
107
|
+
color: var(--mp-ink);
|
|
108
|
+
animation: mp-rise 180ms ease-out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@media (min-width: 640px) {
|
|
112
|
+
.mp-sheet__panel {
|
|
113
|
+
border-radius: 20px;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.mp-sheet__head {
|
|
118
|
+
display: flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
justify-content: space-between;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.mp-sheet__brand {
|
|
124
|
+
display: inline-flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
gap: 8px;
|
|
127
|
+
font-size: 14px;
|
|
128
|
+
font-weight: 700;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.mp-sheet__close {
|
|
132
|
+
font-size: 24px !important;
|
|
133
|
+
line-height: 1;
|
|
134
|
+
color: var(--mp-sub) !important;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.mp-sheet__song {
|
|
138
|
+
margin-top: 18px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.mp-sheet__song p {
|
|
142
|
+
margin: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.mp-sheet__song-title {
|
|
146
|
+
font-size: 20px;
|
|
147
|
+
font-weight: 700;
|
|
148
|
+
letter-spacing: -0.01em;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.mp-sheet__sub {
|
|
152
|
+
color: var(--mp-sub);
|
|
153
|
+
font-size: 13px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.mp-sheet__ask {
|
|
157
|
+
margin: 22px 0 10px;
|
|
158
|
+
font-size: 15px;
|
|
159
|
+
font-weight: 600;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.mp-sheet__grid {
|
|
163
|
+
display: grid;
|
|
164
|
+
grid-template-columns: 1fr 1fr;
|
|
165
|
+
gap: 8px;
|
|
166
|
+
margin: 0;
|
|
167
|
+
padding: 0;
|
|
168
|
+
list-style: none;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.mp-sheet__grid button {
|
|
172
|
+
box-sizing: border-box;
|
|
173
|
+
display: flex !important;
|
|
174
|
+
align-items: center;
|
|
175
|
+
gap: 10px;
|
|
176
|
+
width: 100%;
|
|
177
|
+
padding: 11px 12px !important;
|
|
178
|
+
border: 1px solid var(--mp-line) !important;
|
|
179
|
+
border-radius: 12px;
|
|
180
|
+
background: var(--mp-panel) !important;
|
|
181
|
+
font-size: 14px !important;
|
|
182
|
+
text-align: left;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.mp-sheet__grid button:hover {
|
|
186
|
+
border-color: var(--mp-sub) !important;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.mp-sheet__grid button[aria-current='true'] {
|
|
190
|
+
border-color: var(--mp-core) !important;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.mp-sheet__mark {
|
|
194
|
+
flex-shrink: 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* 아직 고른 곳이 없을 때 골라져 있는 곳 (YouTube) */
|
|
198
|
+
.mp-sheet__tag {
|
|
199
|
+
margin-left: auto;
|
|
200
|
+
padding: 1px 7px;
|
|
201
|
+
border-radius: 999px;
|
|
202
|
+
background: var(--mp-line);
|
|
203
|
+
color: var(--mp-sub);
|
|
204
|
+
font-size: 11px;
|
|
205
|
+
font-weight: 700;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.mp-sheet__note {
|
|
209
|
+
margin: 14px 0 0;
|
|
210
|
+
color: var(--mp-sub);
|
|
211
|
+
font-size: 12px;
|
|
212
|
+
line-height: 1.6;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@keyframes mp-fade {
|
|
216
|
+
from {
|
|
217
|
+
opacity: 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
@keyframes mp-rise {
|
|
222
|
+
from {
|
|
223
|
+
transform: translateY(16px);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@media (prefers-reduced-motion: reduce) {
|
|
228
|
+
.mp-sheet,
|
|
229
|
+
.mp-sheet__panel {
|
|
230
|
+
animation: none;
|
|
231
|
+
}
|
|
232
|
+
}
|