app.js 18.7 KB
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

// 모듈 불러오기
var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');
var app = express(); // express 객체 저장
var async = require('async');

var crawlReol = require('./crawling/Reol');
var crawlYonezu = require('./crawling/Yonezu');
var crawlYorusika = require('./crawling/Yorusika');
var crawlGuckkasten = require('./crawling/Guckkasten');
var crawlMot = require('./crawling/Mot');

var singer;

//body-parser 미들웨어 사용
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

// http://서버주소/keyboard
app.get('/keyboard', function(req,res){
    var data = {
        'type' : 'buttons', 
        'buttons' : ['일본', '한국']};
    res.json(data);
    
});

//8080포트로 서버 접속
http.createServer(app).listen(9000, () => {
    console.log('Server running..');
});

// http://서버주소/message
app.post('/message', function(req,res){
    //유저가 입력한 데이터
    var msg = req.body.content;
    console.log('전달받은 메시지 : ' + msg);
    var send = {};
    var task = [
        // 앨범 정보를 읽어오는 함수 //
        function(callback){
            switch(msg){
                case 'Reol-Discography' :
                    singer = 'Reol';
                    crawlReol.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){
                        callback(null,Reol);
                    });
                    break;
                case '米津玄師-Discography' :
                    singer = 'Yonezu';
                    crawlYonezu.crawl_yonezu('https://namu.wiki/w/%EC%9A%94%EB%84%A4%EC%A6%88%20%EC%BC%84%EC%8B%9C/%EB%94%94%EC%8A%A4%EC%BD%94%EA%B7%B8%EB%9E%98%ED%94%BC#s-3.2.9',function(yonezu){
                        callback(null,yonezu)
                    });
                    break;
                case 'ヨルシカ-Discography' :
                    singer = 'yorusika';
                    crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){
                        callback(null,yorusika);
                    });
                    break;
                case 'Guckkasten-Discography':
                    singer = 'guckkasten';
                    crawlGuckkasten.crawl_guckkasten(function (guckkasten) {
                        callback(null, guckkasten);
                    });
                    break;
                case 'Mot-Discography':
                    singer = 'mot';
                    crawlMot.crawl_mot(function (mot) {
                        callback(null, mot);
                    });
                    break;     

                default:
                    if(singer == 'Reol'){
                        crawlReol.crawl_Reol('https://namu.wiki/w/%EB%A0%88%EC%98%A4%EB%A3%A8/%EC%9D%8C%EB%B0%98#toc',function(Reol){
                            callback(null,Reol);
                        })
                    }
                    else if(singer == "Yonezu"){
                        crawlYonezu.crawl_yonezu('https://namu.wiki/w/%EC%9A%94%EB%84%A4%EC%A6%88%20%EC%BC%84%EC%8B%9C/%EB%94%94%EC%8A%A4%EC%BD%94%EA%B7%B8%EB%9E%98%ED%94%BC#s-3.2.9',function(yonezu){
                            callback(null,yonezu)
                        });
                    }
                    else if(singer=='yorusika'){    
                        crawlYorusika.crawl_yorusika('http://yorushika.com/discography/', function(yorusika){
                            callback(null,yorusika);
                        });
                    }
                    else if(singer=='guckkasten'){
                        crawlGuckkasten.crawl_guckkasten(function(guckkasten){
                            callback(null,guckkasten);
                        });
                    }
                    else if(singer=='mot'){
                        crawlMot.crawl_mot(function (mot) {
                            callback(null, mot);
                        });
                    }
                    else
                        callback(null,null);
                    break;
            }
            
        },

        // 사용자의 msg를 받아 res를 보냄 // 
        function(discography, callback){
            var index;
            if(msg[1] != '.'){
                index = parseInt(msg[0])*10 + parseInt(msg[1]) -1;
            }
            else
                index = parseInt(msg[0])-1;
            switch (msg) {
                case '일본':
                    send = {
                        'message': {
                            'text': '등록된 가수 목록입니다.'
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['Reol', '米津玄師', 'ヨルシカ']
                        }

                    };
                    break;

                case '한국':
                    send = {
                        'message': {
                            'text': '등록된 가수 목록입니다.'
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['Mot', 'Guckkasten']
                        }
                    };
                    break;
          // ---------- contents -------------- // 
                ///////////////
                ///// Reol //// 
                ///////////////            
                case 'Reol' :
                    send = {
                        'message' : {
                            'text' : '이름 : Reol(れをる) \n성별 : 여성 \n생년월일 : 1993년 11월 9일 \n혈액형 : AB형',
                            'photo' : {
                                    'url' : 'https://www.reol.jp/images/profile/reol_Aphoto_2.png',
                                    'width' : 1000,
                                    'height' : 667
                            },
                            'message_button' : {
                                'label' : '공식 홈페이지',
                                'url' : "https://www.reol.jp/"
                            }
                        },
                        keyboard : {
                            'type' : 'buttons',
                            'buttons' : ['Reol-Discography']
                        }
                    };
                    break;
                case 'Reol-Discography' :
                    send = {
                        'message': {
                            'text': 'Album List',
                            'photo': {
                                'url': 'https://yt3.ggpht.com/a-/AN66SAydQt1STVdFCVvwEyZitr-v4dNGDKdyIt-oSA=s288-mo-c-c0xffffffff-rj-k-no',
                                'width': 300,
                                'height': 300
                            },
                            'message_button' : {
                                'label' : 'Youtube channel Link',
                                'url' : "https://www.youtube.com/channel/UCB6pJFaFByws3dQj4AdLdyA/"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',  
                            'buttons': discography[0].json_album
                        }
                    }
                    break;
                ///////////////
                /// 米津玄師 ///
                ///////////////
                case '米津玄師':
                    send = {
                        'message': {
                            'text': '이름 : 米津玄師(Yonezu Kenshi) \n성별 : 남성 \n생년월일 : 1991년 3월 10일 \n혈액형 : O형',
                            'photo': {
                                'url': 'https://images-na.ssl-images-amazon.com/images/I/71d9NrTiMzL.png',
                                'width': 500,
                                'height': 500
                            },
                            'message_button': {
                                'label': '공식 홈페이지',
                                'url': "http://reissuerecords.net/"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['米津玄師-Discography']
                        }
                    };
                    break;
                case '米津玄師-Discography':
                    send = {
                        'message': {
                            'text': 'Album List',
                            'photo': {
                                'url': 'https://yt3.ggpht.com/a-/AN66SAwKDZ2RTvreg5m1Ub6Wd6glpKCYMGrVG4mpqw=s288-mo-c-c0xffffffff-rj-k-no',
                                'width': 300,
                                'height': 300
                            },
                            'message_button' : {
                                'label' : 'Youtube channel Link',
                                'url' : "https://www.youtube.com/channel/UCUCeZaZeJbEYAAzvMgrKOPQ/"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': discography[0].json_album
                        }

                    };
                    break;
                //////////////
                // ヨルシカ //
                /////////////
                case 'ヨルシカ':
                    send = {
                        'message': {
                            'text': '설명 : 2인조 밴드\n멤버 : n-buna, suis \n역할 : 작사, 작곡, 편곡 - n-buna\n           보컬 - suis\n서포트 멤버 : \n  下鶴光康(Guitar)\n  キタニタツヤ(Bass)\n  Masack(Drums)',
                            'photo': {
                                'url': 'http://yorushika.com/wp-content/uploads/2018/05/biography_image2.jpg',
                                'width': 1000,
                                'height': 667
                            },
                            'message_button': {
                                'label': '공식 홈페이지',
                                'url': "http://yorushika.com/"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['ヨルシカ-Discography']
                        }
                    };
                    break;
                case 'ヨルシカ-Discography':
                    send = {
                        'message': {
                            'text': 'Album List',
                            'photo': {
                                'url': 'https://yt3.ggpht.com/a-/AN66SAzKliDeZQJhb9JshzY4hJY_pJSbM1gfYoqY=s288-mo-c-c0xffffffff-rj-k-no',
                                'width': 300,
                                'height': 300
                            },
                            'message_button' : {
                                'label' : 'Youtube channel Link',
                                'url' : "https://www.youtube.com/channel/UCRIgIJQWuBJ0Cv_VlU3USNA"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': discography[0].json_album
                        }

                    };
                    break; 
                ////////////////
                // Guckkasten //
                ////////////////
                case 'Guckkasten':
                    send = {
                        'message': {
                            'text': '설명 : 4인조 밴드\n멤버 :\n  하현우(Vocal, Guitar)\n  전규호(Guitar)\n  이정길(Drum)\n  김기범(Bass)\n장르 : 싸이키델릭 록\n데뷔 : 2007년\n소속사 : 인터파크',
                            'photo': {
                                'url': 'http://ticketimage.interpark.com/interparkenter/guckkasten/about/guckkasten_about_pc_image(540x420px).jpg',
                                'width': 540,
                                'height': 420
                            },
                            'message_button': {
                                'label': '공식 홈페이지',
                                'url': "http://www.interparkenter.com/guckkasten/Main"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['Guckkasten-Discography']
                        }
                    };
                    break;
                case 'Guckkasten-Discography':
                    send = {
                        'message': {
                            'text': 'Album List'
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': discography[0].json_album
                        }

                    };
                    break; 
                /////////////
                //// Mot ////
                /////////////
                case 'Mot':
                    send = {
                        'message': {
                            'text': '설명 : 5인조 밴드\n현멤버(3집 이후) :\n  이이언(Vocal)\n  유웅렬(Guitar)\n  조남열(Drum)\n  송인섭(Bass)\n  이하윤(Keyboard)\n구멤버(1, 2집) :\n  이이언(Vocal)\n   지이(Guitar)\n장르 : Indie Rock\n 데뷔 : 2004년',
                            'photo': {
                                'url': 'https://thestrings.kr/wp-content/uploads/2017/10/m_main.jpg',
                                'width': 1000,
                                'height': 677
                            },
                            'message_button': {
                                'label': '공식 Facebook',
                                'url': "https://www.facebook.com/bandmot.official"
                            }
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['Mot-Discography']
                        }
                    };
                    break;
                case 'Mot-Discography':
                    send = {
                        'message': {
                            'text': 'Album List'
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': discography[0].json_album
                        }

                    };
                    break; 

                // 앨범 정보 읽기 //

                case discography[0].json_album[index]:
                    var album = '앨범 : ' + discography[0].json_album[index].substr(3);
                    if (singer == 'Reol') {
                        send = {
                            'message': {
                                'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
                            },
                            keyboard: {
                                'type': 'buttons',
                                'buttons': ['Reol-Discography', '초기화면']
                            }
                        }
                    }
                    else if (singer == 'Yonezu') {
                        send = {
                            'message': {
                                'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
                            },
                            keyboard: {
                                'type': 'buttons',
                                'buttons': ['米津玄師-Discography', '초기화면']
                            }
                        }
                    }
                    else if (singer == 'yorusika'){
                        send = {
                            'message': {
                                'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
                            },
                            keyboard: {
                                'type': 'buttons',
                                'buttons': ['ヨルシカ-Discography', '초기화면']
                            }
                        }
                    }
                    else if (singer == 'guckkasten'){
                        send = {
                            'message': {
                                'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
                            },
                            keyboard: {
                                'type': 'buttons',
                                'buttons': ['Guckkasten-Discography', '초기화면']
                            }
                        }
                    }
                    else if (singer == 'mot'){
                        send = {
                            'message': {
                                'text': album + '\n발매년도 : ' + discography[0].json_year[index] + '\n수록곡 : \n' + discography[0].json_track[index]
                            },
                            keyboard: {
                                'type': 'buttons',
                                'buttons': ['Mot-Discography', '초기화면']
                            }
                        }
                    }
                    break;
                
                // 초기 설정으로 돌아가기 //

                case '초기화면' : 
                    send = {
                        'message' : {
                            'text' : '초기화면으로 돌아갑니다.'
                        },                
                        keyboard : {
                            'type' : 'buttons',
                            'buttons' : ['일본', '한국']
                        }
                    }
                    break;
                default:
                    send = {
                        'message': {
                            'text': '잘못된 입력입니다. \n초기화면으로 이동합니다.'
                        },
                        keyboard: {
                            'type': 'buttons',
                            'buttons': ['일본', '한국']
                        }
                    }
                    break;
            }
            callback(null ,send);
        }
    ];

    // async의 waterfall을 통해 함수를 순차적으로 실행 // 
    async.waterfall(task, function(err,result){
        console.log(send);
        res.json(send);
    });
});