File size: 4,736 Bytes
2d2e00c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const express = require('express');
const router = express.Router();

/**
 * @swagger
 * /api/charts:
 *   get:
 *     summary: Get charts (global or by country)
 *     parameters:
 *       - in: query
 *         name: country
 *         schema:
 *           type: string
 *         description: Country code
 *     responses:
 *       200:
 *         description: Charts data
 *       500:
 *         description: Charts data unavailable
 */
router.get('/charts', async (req, res) => {
  try {
    const { country } = req.query;
    const ytmusic = req.app.locals.ytmusic;
    
    const data = await ytmusic.getCharts(country);
    res.json(data);
  } catch (error) {
    console.error('Charts error:', error);
    const errorMsg = error.message || 'Charts service temporarily unavailable';
    res.status(500).json({
      error: `Charts data unavailable: ${errorMsg}`,
      message: 'YouTube Music charts are currently not accessible. This may be due to regional restrictions or service limitations.',
      fallback: 'Try using the search endpoint instead: /api/search?q=trending&filter=songs'
    });
  }
});

/**
 * @swagger
 * /api/moods:
 *   get:
 *     summary: Get mood/genre categories
 *     responses:
 *       200:
 *         description: Mood categories
 *       500:
 *         description: Mood categories unavailable
 */
router.get('/moods', async (req, res) => {
  try {
    const ytmusic = req.app.locals.ytmusic;
    const data = await ytmusic.getMoodCategories();
    res.json(data);
  } catch (error) {
    console.error('Moods error:', error);
    const errorMsg = error.message || 'Mood categories service temporarily unavailable';
    res.status(500).json({
      error: `Mood categories unavailable: ${errorMsg}`,
      message: 'YouTube Music mood categories are currently not accessible.',
      fallback: 'Try using the search endpoint instead: /api/search?q=relaxing&filter=playlists'
    });
  }
});

/**
 * @swagger
 * /api/moods/{categoryId}:
 *   get:
 *     summary: Get playlists for a mood/genre category
 *     parameters:
 *       - in: path
 *         name: categoryId
 *         required: true
 *         schema:
 *           type: string
 *         description: Category ID
 *     responses:
 *       200:
 *         description: Mood playlists
 *       500:
 *         description: Mood playlists unavailable
 */
router.get('/moods/:categoryId', async (req, res) => {
  try {
    const { categoryId } = req.params;
    const ytmusic = req.app.locals.ytmusic;
    
    const data = await ytmusic.getMoodPlaylists(categoryId);
    res.json(data);
  } catch (error) {
    console.error('Mood playlists error:', error);
    const errorMsg = error.message || 'Mood playlists service temporarily unavailable';
    res.status(500).json({
      error: `Mood playlists unavailable: ${errorMsg}`,
      message: `Mood playlists for category '${req.params.categoryId}' are currently not accessible.`,
      fallback: 'Try using the search endpoint instead: /api/search?q=mood&filter=playlists'
    });
  }
});

/**
 * @swagger
 * /api/watch_playlist:
 *   get:
 *     summary: Get watch playlist (radio/shuffle)
 *     parameters:
 *       - in: query
 *         name: videoId
 *         schema:
 *           type: string
 *         description: Video ID
 *       - in: query
 *         name: playlistId
 *         schema:
 *           type: string
 *         description: Playlist ID
 *       - in: query
 *         name: radio
 *         schema:
 *           type: boolean
 *           default: false
 *         description: Radio mode
 *       - in: query
 *         name: shuffle
 *         schema:
 *           type: boolean
 *           default: false
 *         description: Shuffle mode
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 25
 *         description: Maximum number of tracks
 *     responses:
 *       200:
 *         description: Watch playlist data
 *       400:
 *         description: Missing params
 */
router.get('/watch_playlist', async (req, res) => {
  try {
    const { videoId, playlistId, radio = false, shuffle = false, limit = 25 } = req.query;
    
    if (!videoId && !playlistId) {
      return res.status(400).json({ error: 'Provide either videoId or playlistId' });
    }

    const ytmusic = req.app.locals.ytmusic;
    const data = await ytmusic.getWatchPlaylist(
      videoId, 
      playlistId, 
      radio === 'true', 
      shuffle === 'true', 
      parseInt(limit)
    );
    
    res.json(data);
  } catch (error) {
    console.error('Watch playlist error:', error);
    res.status(500).json({ error: `Watch playlist unavailable: ${error.message}` });
  }
});

module.exports = router;