Best JavaScript code snippet using qawolf
external-tool.js
Source:external-tool.js
...698 });699 }700 });701 /*return Api('url', url, {referer: 'http://www.99kubo.tv/',}).then(raw_data => {702 const body = findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0];703 if (body.attribs.class === 'vod-type') {704 const type_id = url.match(/list-select-id-(\d+)/);705 if (!type_id) {706 return handleError(new HoError('unknown kubo type'));707 }708 return findTag(findTag(findTag(body, 'div', 'container ff-bg')[1], 'ul')[0], 'li').map(l => {709 const a = findTag(findTag(l, 'h2')[0], 'a')[0];710 const img = findTag(findTag(findTag(l, 'p')[0], 'a')[0], 'img')[0];711 let tags = new Set();712 if (type_id[1] === '1') {713 tags = new Set(['é»å½±', 'movie']);714 } else if (type_id[1] === '3') {715 tags = new Set(['åç«', 'animation']);716 } else {717 tags = new Set(['é»è¦å', 'tv show']);718 if (type_id[1] === '41') {719 tags.add('ç¶èç¯ç®');720 }721 }722 let count = 0;723 let date = '1970-01-01';724 findTag(findTag(l, 'h4')[0], 'a').forEach(a => {725 const tag = findTag(a)[0];726 if (tag !== 'å
§è©³') {727 tags.add(tag)728 }729 });730 return {731 name: findTag(a)[0],732 id: a.attribs.href.match(/\d+/)[0],733 thumb: img.attribs['data-original'],734 tags,735 count,736 date,737 };738 });739 } else {740 return findTag(findTag(findTag(findTag(findTag(body, 'div', 'container ff-bg')[0], 'div', 'row ff-row')[0], 'div', 'col-md-10')[0], 'ul')[0], 'li').map(l => {741 const img = findTag(findTag(findTag(findTag(findTag(l, 'dl')[0], 'dt')[0], 'p', 'image')[0], 'a')[0], 'img')[0];742 const dd = findTag(findTag(l, 'dl')[0], 'dd')[0];743 const a = findTag(findTag(dd, 'h3')[0], 'a')[0];744 let count = 0;745 let date = '1970-01-01';746 let tags = new Set();747 findTag(dd, 'p').forEach(p => {748 findTag(p).forEach((g, i) => {749 if (g.includes('å°å/年份')) {750 findTag(findTag(p, 'span')[i])[0].split('/').forEach(t => tags.add(t));751 } else if (g.includes('æ¼å¡') || g.includes('å°æ¼')) {752 findTag(findTag(p, 'span')[i], 'a').forEach(t => {753 if (findTag(t)[0]) {754 tags.add(findTag(t)[0])755 }756 });757 } else if (g.includes('æ´æ°æé')) {758 const match = findTag(findTag(p, 'span')[i])[0].match(/^\d\d\d\d\/\d\d\/\d\d/);759 if (match) {760 date = match[0];761 }762 }763 });764 });765 return {766 id: a.attribs.href.match(/\d+/)[0],767 name: findTag(a)[0],768 thumb: img.attribs['data-original'],769 date,770 tags,771 count,772 }773 });774 }775 });*/776 case 'dm5':777 return (0, _apiTool2.default)('url', url, {778 referer: 'http://www.dm5.com/',779 post: post,780 is_dm5: true781 }).then(function (raw_data) {782 var list = [];783 var data = _htmlparser2.default.parseDOM(raw_data);784 if ((0, _utility.findTag)(data, 'html').length > 0) {785 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(data, 'html')[0], 'body')[0], 'section', 'box container pb40 overflow-Show')[0], 'div', 'box-body')[0], 'ul', 'mh-list col7')[0], 'li').forEach(function (l) {786 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(l, 'div', 'mh-item')[0], 'div', 'mh-tip-wrap')[0], 'div', 'mh-item-tip')[0], 'a')[0];787 list.push({788 id: a.attribs.href.match(/\/([^\/]+)/)[1],789 name: opencc.convertSync(a.attribs.title),790 thumb: (0, _utility.findTag)((0, _utility.findTag)(l, 'div', 'mh-item')[0], 'p', 'mh-cover')[0].attribs.style.match(/url\(([^\)]+)/)[1],791 tags: ['漫ç«', 'comic']792 });793 });794 } else {795 data.forEach(function (l) {796 list.push({797 id: l.attribs.href.match(/\/([^\/]+)/)[1],798 name: opencc.convertSync((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(l, 'p')[0], 'span')[0])[0]),799 thumb: 'dm5.png',800 tags: ['漫ç«', 'comic']801 });802 });803 }804 return list;805 });806 case 'bls':807 return (0, _apiTool2.default)('url', 'https://www.bls.gov/bls/newsrels.htm#latest-releases').then(function (raw_data) {808 var date = new Date(url);809 if (isNaN(date.getTime())) {810 return (0, _utility.handleError)(new _utility.HoError('date invalid'));811 }812 date = new Date(new Date(date).setDate(date.getDate() - 1));813 var docDate = (0, _utility.completeZero)(date.getMonth() + 1, 2) + '/' + (0, _utility.completeZero)(date.getDate(), 2) + '/' + date.getFullYear();814 console.log(docDate);815 var list = [];816 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'section')[0], 'div', 'wrapper-outer')[0], 'div', 'wrapper')[0], 'div', 'container')[0], 'div', 'main-content-full-width')[0], 'div', 'bodytext')[0], 'div', 'bls')[0], 'ul')[0], 'li').forEach(function (l) {817 if ((0, _utility.findTag)(l)[0] === docDate) {818 var a = (0, _utility.findTag)(l, 'a')[0];819 list.push({820 url: (0, _utility.addPre)(a.attribs.href, 'https://www.bls.gov'),821 name: (0, _utility.toValidName)((0, _utility.findTag)(a)[0]),822 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()823 });824 }825 });826 return list;827 });828 case 'cen':829 return (0, _apiTool2.default)('url', 'https://www.census.gov/economic-indicators/').then(function (raw_data) {830 var date = new Date(url);831 if (isNaN(date.getTime())) {832 return (0, _utility.handleError)(new _utility.HoError('date invalid'));833 }834 date = new Date(new Date(date).setDate(date.getDate() - 1));835 var docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();836 console.log(docDate);837 var list = [];838 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'econ-content-container')[0], 'table', 'indicator-table')[0], 'tbody')[0], 'tr').forEach(function (r) {839 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(r, 'td', 'indicator_dates')[0], 'div')[0], 'p')[0], 'span')[0])[0] === docDate) {840 var div = (0, _utility.findTag)((0, _utility.findTag)(r, 'td', 'indicator_data')[0], 'div')[0];841 list.push({842 url: (0, _utility.addPre)((0, _utility.findTag)((0, _utility.findTag)(div, 'p', 'supplemental_links')[0], 'a')[0].attribs.href, 'http://www.census.gov'),843 name: (0, _utility.toValidName)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(div, 'h3')[0], 'a')[0])[0]),844 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()845 });846 }847 });848 return list;849 });850 case 'bea':851 return (0, _apiTool2.default)('url', 'https://www.bea.gov/news/current-releases').then(function (raw_data) {852 var date = new Date(url);853 if (isNaN(date.getTime())) {854 return (0, _utility.handleError)(new _utility.HoError('date invalid'));855 }856 date = new Date(new Date(date).setDate(date.getDate() - 1));857 var docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();858 console.log(docDate);859 var list = [];860 var trs = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div')[0], 'div')[0], 'div', 'row')[0], 'section')[0], 'div', 'region region-content')[0], 'div')[0], 'div')[0], 'div', 'view-content')[0], 'div')[0], 'table')[0], 'tbody')[0], 'tr');861 var _iteratorNormalCompletion2 = true;862 var _didIteratorError2 = false;863 var _iteratorError2 = undefined;864 try {865 for (var _iterator2 = (0, _getIterator3.default)(trs), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {866 var tr = _step2.value;867 var vs = (0, _utility.findTag)((0, _utility.findTag)(tr, 'td')[1]);868 var _iteratorNormalCompletion3 = true;869 var _didIteratorError3 = false;870 var _iteratorError3 = undefined;871 try {872 for (var _iterator3 = (0, _getIterator3.default)(vs), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {873 var v = _step3.value;874 var mv = v.match(/^[a-zA-Z]+ \d\d?, \d\d\d\d/);875 if (mv && mv[0] === docDate) {876 var a = (0, _utility.findTag)((0, _utility.findTag)(tr, 'td')[0], 'a')[0];877 list.push({878 url: (0, _utility.addPre)(a.attribs.href, 'http://www.bea.gov'),879 name: (0, _utility.toValidName)((0, _utility.findTag)(a)[0]),880 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()881 });882 break;883 }884 }885 } catch (err) {886 _didIteratorError3 = true;887 _iteratorError3 = err;888 } finally {889 try {890 if (!_iteratorNormalCompletion3 && _iterator3.return) {891 _iterator3.return();892 }893 } finally {894 if (_didIteratorError3) {895 throw _iteratorError3;896 }897 }898 }899 }900 } catch (err) {901 _didIteratorError2 = true;902 _iteratorError2 = err;903 } finally {904 try {905 if (!_iteratorNormalCompletion2 && _iterator2.return) {906 _iterator2.return();907 }908 } finally {909 if (_didIteratorError2) {910 throw _iteratorError2;911 }912 }913 }914 return list;915 });916 case 'ism':917 return (0, _apiTool2.default)('url', 'https://www.ismworld.org/supply-management-news-and-reports/reports/ism-report-on-business/', { cookie: 'HttpOnly;Path=/;Domain=www.ismworld.org;sso-check=true' }).then(function (raw_data) {918 var date = new Date(url);919 if (isNaN(date.getTime())) {920 return (0, _utility.handleError)(new _utility.HoError('date invalid'));921 }922 date = new Date(new Date(date).setDate(date.getDate() - 1));923 var docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();924 console.log(docDate);925 var list = [];926 if (date.getDate() === 27) {927 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'rootOfObserver')[0], 'main')[0], 'div', 'component')[1], 'div', 'container')[0], 'div', 'cardCollection')[0], 'div', 'row justify-content-center')[0], 'div', 'col-md-4 card__col').forEach(function (c, i) {928 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(c, 'div', 'card')[0], 'div', 'card__content')[0], 'div', 'card__text')[0], 'center')[0], 'p')[0], 'a').forEach(function (a) {929 list.push({930 url: (0, _utility.addPre)(a.attribs.href, 'https://www.ismworld.org'),931 name: i === 0 ? (0, _utility.toValidName)('Manufacturing ISM') : (0, _utility.toValidName)('Non-Manufacturing ISM'),932 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()933 });934 });935 });936 }937 return list;938 });939 case 'cbo':940 return (0, _apiTool2.default)('url', 'https://www.conference-board.org/data/consumerconfidence.cfm').then(function (raw_data) {941 var date = new Date(url);942 if (isNaN(date.getTime())) {943 return (0, _utility.handleError)(new _utility.HoError('date invalid'));944 }945 date = new Date(new Date(date).setDate(date.getDate() - 1));946 var docDate = date.getDate() + ' ' + _constants.MONTH_SHORTS[date.getMonth()] + '. ' + date.getFullYear();947 console.log(docDate);948 var list = [];949 var body = (0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0];950 if (body) {951 var con = (0, _utility.findTag)(body, 'div', 'container tcb-wrapper')[0];952 if (con) {953 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(con, 'div', 'wrap')[0], 'div', 'content')[0], 'p', 'date')[0])[0] === docDate) {954 list.push({955 url: 'https://www.conference-board.org/data/consumerconfidence.cfm',956 name: (0, _utility.toValidName)('Consumer Confidence Survey'),957 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()958 });959 }960 }961 }962 return (0, _apiTool2.default)('url', 'https://www.conference-board.org/data/bcicountry.cfm?cid=1').then(function (raw_data) {963 docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();964 console.log(docDate);965 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'container fixedheader')[0], 'div', 'wrap')[0], 'div', 'content')[0], 'p', 'date')[0])[0].match(/[a-zA-Z]+ \d\d?, \d\d\d\d$/)[0] === docDate) {966 list.push({967 url: 'https://www.conference-board.org/data/bcicountry.cfm?cid=1',968 name: (0, _utility.toValidName)('US Business Cycle Indicators'),969 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()970 });971 }972 return list;973 });974 });975 case 'sem':976 return (0, _apiTool2.default)('url', 'https://www.semi.org/en/news-resources/press/semi/rss.xml').then(function (raw_data) {977 var date = new Date(url);978 if (isNaN(date.getTime())) {979 return (0, _utility.handleError)(new _utility.HoError('date invalid'));980 }981 date = new Date(new Date(date).setDate(date.getDate() - 1));982 var docDate = (0, _utility.completeZero)(date.getDate(), 2) + ' ' + _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getFullYear();983 console.log(docDate);984 var list = [];985 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'rss')[0], 'channel')[0], 'item').forEach(function (e) {986 if ((0, _utility.findTag)((0, _utility.findTag)(e, 'pubdate')[0])[0].match(/^[a-zA-Z]+, (\d\d [a-zA-Z]+ \d\d\d\d)/)[1] === docDate) {987 list.push({988 url: (0, _utility.addPre)((0, _utility.findTag)(e)[0], 'http://www.semi.org'),989 name: (0, _utility.toValidName)((0, _utility.findTag)((0, _utility.findTag)(e, 'title')[0])[0]),990 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()991 });992 }993 });994 return list;995 });996 case 'oec':997 return (0, _apiTool2.default)('url', 'https://www.oecd.org/newsroom/', { referer: 'https://www.oecd.org/newsroom/' }).then(function (raw_data) {998 var date = new Date(url);999 if (isNaN(date.getTime())) {1000 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1001 }1002 date = new Date(new Date(date).setDate(date.getDate() - 1));1003 var docDate = date.getDate() + ' ' + _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getFullYear();1004 console.log(docDate);1005 var list = [];1006 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'section container')[0], 'div', 'row')[0], 'div', 'col-sm-9 leftnav-content-wrapper')[0], 'div', 'newsroom-lists')[0], 'div', 'news-col block')[1], 'ul', 'block-list')[0], 'li', 'news-event-item linked ').forEach(function (l) {1007 if ((0, _utility.findTag)((0, _utility.findTag)(l, 'p')[0])[0] === docDate) {1008 list.push({1009 url: (0, _utility.addPre)((0, _utility.findTag)(l, 'a')[0].attribs.href, 'http://www.oecd.org'),1010 name: (0, _utility.toValidName)((0, _utility.findTag)((0, _utility.findTag)(l, 'span')[0])[0]),1011 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1012 });1013 }1014 });1015 return list;1016 });1017 case 'dol':1018 return (0, _apiTool2.default)('url', 'https://www.dol.gov/newsroom/releases').then(function (raw_data) {1019 var date = new Date(url);1020 if (isNaN(date.getTime())) {1021 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1022 }1023 date = new Date(new Date(date).setDate(date.getDate() - 1));1024 var docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();1025 console.log(docDate);1026 var list = [];1027 var divs = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'dialog-off-canvas-main-canvas')[0], 'div')[0], 'main', 'cd-main-content')[0], 'div', 'layout-content inner-content-page')[0], 'div', 'block-opa-theme-content')[0], 'div', 'views-element-container')[0], 'div')[0], 'div');1028 for (var i in divs) {1029 var div = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(divs[i], 'div', 'image-left-teaser')[0], 'div', 'row dol-feed-block')[0], 'div', 'left-teaser-text')[0];1030 var a = (0, _utility.findTag)(div, 'a')[0];1031 if (a && (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(a, 'h3')[0], 'span')[0])[0] === 'Unemployment Insurance Weekly Claims Report' && (0, _utility.findTag)((0, _utility.findTag)(div, 'p')[0])[0].match(/[a-zA-Z]+ \d+, \d\d\d\d$/)[0] === docDate) {1032 list.push({1033 url: (0, _utility.addPre)(a.attribs.href.trim(), 'https://www.dol.gov'),1034 name: (0, _utility.toValidName)('Unemployment Insurance Weekly Claims Report'),1035 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1036 });1037 }1038 }1039 return list;1040 });1041 case 'rea':1042 return (0, _apiTool2.default)('url', 'https://www.nar.realtor/newsroom').then(function (raw_data) {1043 var date = new Date(url);1044 if (isNaN(date.getTime())) {1045 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1046 }1047 date = new Date(new Date(date).setDate(date.getDate() - 1));1048 var docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();1049 console.log(docDate);1050 var list = [];1051 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'page-wrapper')[0], 'main')[0], 'div', 'content-push push')[0], 'div', 'layout-constrain')[0], 'div', 'region-content')[0], 'div', 'layout-content-aside has-aside')[0], 'div', 'secondary-content')[0], 'div', 'pane-node-field-below-paragraph pane pane--nodefield-below-paragraph')[0], 'div', 'pane__content')[0], 'div', 'field field--below-paragraph')[0], 'div', 'field-items')[0], 'div', 'field-item even')[0], 'div')[0], 'div', 'layout--flex-grid layout--fg-9-3')[0], 'div', 'flex-column')[0], 'div')[0], 'div', 'field field--search-query')[0], 'div', 'field-items')[0], 'div', 'field-item even')[0], 'div', 'field_search_query_content_list')[0], 'div').forEach(function (d) {1052 var content = (0, _utility.findTag)((0, _utility.findTag)(d, 'article')[0], 'div', 'card-view__content')[0];1053 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(content, 'div', 'card-view__footer')[0], 'div', 'node__date')[0], 'span')[0])[0] === docDate) {1054 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(content, 'div', 'card-view__header')[0], 'h3', 'card-view__title')[0], 'a')[0];1055 list.push({1056 url: (0, _utility.addPre)(a.attribs.href, 'https://www.nar.realtor'),1057 name: (0, _utility.toValidName)((0, _utility.findTag)(a)[0]),1058 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1059 });1060 }1061 });1062 return list;1063 });1064 case 'sca':1065 return (0, _apiTool2.default)('url', 'http://www.sca.isr.umich.edu/').then(function (raw_data) {1066 var date = new Date(url);1067 if (isNaN(date.getTime())) {1068 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1069 }1070 date = new Date(new Date(date).setDate(date.getDate() - 1));1071 var docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();1072 console.log(docDate);1073 var list = [];1074 if (date.getDate() === 15 || date.getDate() === 28) {1075 list.push({1076 url: 'http://www.sca.isr.umich.edu/',1077 name: (0, _utility.toValidName)('Michigan Consumer Sentiment Index'),1078 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1079 });1080 }1081 return list;1082 });1083 case 'fed':1084 return (0, _apiTool2.default)('url', 'http://www.federalreserve.gov/feeds/speeches_and_testimony.xml').then(function (raw_data) {1085 var date = new Date(url);1086 if (isNaN(date.getTime())) {1087 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1088 }1089 date = new Date(new Date(date).setDate(date.getDate() - 1));1090 var docDate = '' + date.getFullYear() + (0, _utility.completeZero)(date.getMonth() + 1, 2) + (0, _utility.completeZero)(date.getDate(), 2);1091 console.log(docDate);1092 var list = [];1093 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'rss')[0], 'channel')[0], 'item').forEach(function (t) {1094 var link = (0, _utility.findTag)(t)[0];1095 if (link.match(/\d\d\d\d\d\d\d\d/)[0] === docDate) {1096 list.push({1097 url: (0, _utility.addPre)(link, 'http://www.federalreserve.gov'),1098 name: (0, _utility.toValidName)((0, _utility.findTag)((0, _utility.findTag)(t, 'title')[0])[0]),1099 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1100 });1101 }1102 });1103 return (0, _apiTool2.default)('url', 'https://www.federalreserve.gov/releases/g17/Current/default.htm').then(function (raw_data) {1104 docDate = _constants.MONTH_NAMES[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();1105 console.log(docDate);1106 var content = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'content')[0];1107 if ((0, _utility.findTag)((0, _utility.findTag)(content, 'div', 'dates')[0])[0].match(/[a-zA-Z]+ \d\d?, \d\d\d\d$/)[0] === docDate) {1108 var as = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(content, 'h3')[0], 'span')[0], 'a');1109 var _iteratorNormalCompletion4 = true;1110 var _didIteratorError4 = false;1111 var _iteratorError4 = undefined;1112 try {1113 for (var _iterator4 = (0, _getIterator3.default)(as), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {1114 var i = _step4.value;1115 if ((0, _utility.findTag)(i)[0].match(/pdf/i)) {1116 list.push({1117 url: (0, _utility.addPre)(i.attribs.href, 'https://www.federalreserve.gov/releases/g17/Current'),1118 name: (0, _utility.toValidName)('INDUSTRIAL PRODUCTION AND CAPACITY UTILIZATION'),1119 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1120 });1121 }1122 }1123 } catch (err) {1124 _didIteratorError4 = true;1125 _iteratorError4 = err;1126 } finally {1127 try {1128 if (!_iteratorNormalCompletion4 && _iterator4.return) {1129 _iterator4.return();1130 }1131 } finally {1132 if (_didIteratorError4) {1133 throw _iteratorError4;1134 }1135 }1136 }1137 }1138 return (0, _apiTool2.default)('url', 'https://www.federalreserve.gov/releases/g19/Current/default.htm').then(function (raw_data) {1139 var body = (0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0];1140 body = body ? body : (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'body')[0];1141 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(body, 'div', 'content')[0], 'div', 'dates')[0])[1].match(/[a-zA-Z]+ \d\d?, \d\d\d\d$/)[0] === docDate) {1142 list.push({1143 url: 'https://www.federalreserve.gov/releases/g19/Current/default.htm',1144 name: (0, _utility.toValidName)('Consumer Credit'),1145 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1146 });1147 }1148 return list;1149 });1150 });1151 });1152 case 'sea':1153 return (0, _apiTool2.default)('url', 'https://www.seaj.or.jp/english/statistics/index.html').then(function (raw_data) {1154 var date = new Date(url);1155 if (isNaN(date.getTime())) {1156 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1157 }1158 date = new Date(new Date(date).setDate(date.getDate() - 1));1159 var docDate = date.getFullYear() + '-' + (0, _utility.completeZero)(date.getMonth() + 1, 2) + '-' + (0, _utility.completeZero)(date.getDate(), 2);1160 console.log(docDate);1161 var list = [];1162 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'pagecontent')[0], 'div', 'row column-content')[0], 'main', 'col-md-9 order-md-last')[0], 'section')[1], 'section')[0], 'div', 'table-responsive')[0], 'table')[0], 'tbody')[0], 'tr').forEach(function (t) {1163 if ((0, _utility.findTag)((0, _utility.findTag)(t, 'td')[2])[0] === docDate) {1164 var urlS = (0, _utility.findTag)((0, _utility.findTag)(t, 'td')[1], 'a')[0].attribs.href;1165 urlS = urlS.match(/^(http|https):\/\//) ? urlS : 'http://' + (0, _path.join)('www.seaj.or.jp/english/statistics', urlS);1166 list.push({1167 url: urlS,1168 name: (0, _utility.toValidName)((0, _utility.findTag)((0, _utility.findTag)(t, 'td')[0])[0] + ' ' + (0, _utility.findTag)((0, _utility.findTag)(t, 'td')[0])[1]),1169 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1170 });1171 }1172 });1173 return list;1174 });1175 case 'tri':1176 return (0, _apiTool2.default)('url', 'http://www.tri.org.tw').then(function (raw_data) {1177 var date = new Date(url);1178 if (isNaN(date.getTime())) {1179 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1180 }1181 var docDate = date.getFullYear() - 1911 + '.' + (date.getMonth() + 1) + '.' + date.getDate();1182 console.log(docDate);1183 var list = [];1184 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'main')[0], 'div', 'content')[0], 'div', 'content01')[0], 'div', 'content02L')[0], 'div', 'content01LText')[0], 'div')[1], 'div', 'consumerText')[0], 'a')[0];1185 if ((0, _utility.findTag)(a)[0].match(/\d\d\d\.\d\d?\.\d\d?/)[0] === docDate) {1186 list.push({1187 url: (0, _utility.addPre)(a.attribs.href, 'http://www.tri.org.tw'),1188 name: (0, _utility.toValidName)('æ¶è²»è
ä¿¡å¿ææ¸èª¿æ¥å ±å'),1189 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1190 });1191 }1192 return list;1193 });1194 case 'ndc':1195 return (0, _apiTool2.default)('url', 'https://index.ndc.gov.tw/n/json/data/news', {1196 post: {},1197 referer: 'https://index.ndc.gov.tw/n/zh_tw/data/news'1198 }).then(function (raw_data) {1199 var date = new Date(url);1200 if (isNaN(date.getTime())) {1201 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1202 }1203 date = new Date(new Date(date).setDate(date.getDate() - 1));1204 var docDate = date.getFullYear() + '-' + (0, _utility.completeZero)(date.getMonth() + 1, 2) + '-' + (0, _utility.completeZero)(date.getDate(), 2);1205 console.log(docDate);1206 var list = [];1207 var json_data = (0, _utility.getJson)(raw_data);1208 if (json_data === false) {1209 return (0, _utility.handleError)(new _utility.HoError('json parse error!!!'));1210 }1211 var _iteratorNormalCompletion5 = true;1212 var _didIteratorError5 = false;1213 var _iteratorError5 = undefined;1214 try {1215 for (var _iterator5 = (0, _getIterator3.default)(json_data), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {1216 var i = _step5.value;1217 if (i.date === docDate) {1218 var list_match = i.content.match(/href="([^"]+pdf)".*?title="(.*?\d\d\d\d?å¹´\d\d?æ[^"]+)/g);1219 if (list_match) {1220 var _iteratorNormalCompletion6 = true;1221 var _didIteratorError6 = false;1222 var _iteratorError6 = undefined;1223 try {1224 for (var _iterator6 = (0, _getIterator3.default)(list_match), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {1225 var j = _step6.value;1226 var item_match = j.match(/href="([^"]+pdf)".*?title="(.*?\d\d\d\d?å¹´\d\d?æ[^"]+)/);1227 if (item_match) {1228 list.push({1229 url: (0, _utility.addPre)(item_match[1], 'http://index.ndc.gov.tw').replace(/&/g, '&'),1230 name: (0, _utility.toValidName)(item_match[2]),1231 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1232 });1233 }1234 }1235 } catch (err) {1236 _didIteratorError6 = true;1237 _iteratorError6 = err;1238 } finally {1239 try {1240 if (!_iteratorNormalCompletion6 && _iterator6.return) {1241 _iterator6.return();1242 }1243 } finally {1244 if (_didIteratorError6) {1245 throw _iteratorError6;1246 }1247 }1248 }1249 }1250 }1251 }1252 } catch (err) {1253 _didIteratorError5 = true;1254 _iteratorError5 = err;1255 } finally {1256 try {1257 if (!_iteratorNormalCompletion5 && _iterator5.return) {1258 _iterator5.return();1259 }1260 } finally {1261 if (_didIteratorError5) {1262 throw _iteratorError5;1263 }1264 }1265 }1266 return list;1267 });1268 case 'sta':1269 return (0, _apiTool2.default)('url', 'https://www.stat.gov.tw/lp.asp?ctNode=489&CtUnit=1818&BaseDSD=29').then(function (raw_data) {1270 var date = new Date(url);1271 if (isNaN(date.getTime())) {1272 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1273 }1274 date = new Date(new Date(date).setDate(date.getDate() - 1));1275 var docDate = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate();1276 console.log(docDate);1277 var list = [];1278 var findDoc = function findDoc(title, raw_data) {1279 var html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];1280 var html2 = (0, _utility.findTag)(html, 'html')[0];1281 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html2 ? html2 : html, 'body')[0], 'div', 'wrap')[0], 'table', 'layout')[0], 'tr')[0], 'td', 'center')[0], 'div', 'lp')[0], 'div', 'list')[0], 'table')[0], 'tr').forEach(function (t) {1282 var timeTd = (0, _utility.findTag)(t, 'td');1283 if (timeTd.length > 0) {1284 if ((0, _utility.findTag)(timeTd[1])[0] === docDate) {1285 list.push({1286 url: (0, _utility.addPre)((0, _utility.findTag)(timeTd[0], 'a')[0].attribs.href, 'https://www.stat.gov.tw'),1287 name: (0, _utility.toValidName)(title),1288 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1289 });1290 }1291 }1292 });1293 };1294 findDoc('ç©å¹ææ¸', raw_data);1295 return (0, _apiTool2.default)('url', 'https://www.stat.gov.tw/lp.asp?ctNode=497&CtUnit=1818&BaseDSD=29').then(function (raw_data) {1296 findDoc('ç¶æ¿æé·ç', raw_data);1297 return (0, _apiTool2.default)('url', 'https://www.stat.gov.tw/lp.asp?ctNode=527&CtUnit=1818&BaseDSD=29&MP=4').then(function (raw_data) {1298 findDoc('åå±å¡å·¥èªè³èçç¢å', raw_data);1299 return (0, _apiTool2.default)('url', 'https://www.stat.gov.tw/lp.asp?ctNode=2294&CtUnit=1818&BaseDSD=29&mp=4').then(function (raw_data) {1300 var pDate = new Date(new Date(date).setMonth(date.getMonth() - 1));1301 var docDate1 = pDate.getFullYear() - 1911 + '\u5E74' + (pDate.getMonth() + 1) + '\u6708';1302 console.log(docDate1);1303 var html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];1304 var html2 = (0, _utility.findTag)(html, 'html')[0];1305 var lis = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html2 ? html2 : html, 'body')[0], 'div', 'wrap')[0], 'table', 'layout')[0], 'tr')[0], 'td', 'center')[0], 'div', 'lp')[0], 'div', 'list')[0], 'ul')[0], 'li');1306 var link = null;1307 var _iteratorNormalCompletion7 = true;1308 var _didIteratorError7 = false;1309 var _iteratorError7 = undefined;1310 try {1311 for (var _iterator7 = (0, _getIterator3.default)(lis), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {1312 var l = _step7.value;1313 var a = (0, _utility.findTag)(l, 'a')[0];1314 var dateMatch = (0, _utility.findTag)(a)[0].match(/^\d\d\då¹´\d\d?æ/);1315 if (dateMatch && dateMatch[0] === docDate1) {1316 link = (0, _utility.addPre)(a.attribs.href, 'https://www.stat.gov.tw');1317 break;1318 }1319 }1320 } catch (err) {1321 _didIteratorError7 = true;1322 _iteratorError7 = err;1323 } finally {1324 try {1325 if (!_iteratorNormalCompletion7 && _iterator7.return) {1326 _iterator7.return();1327 }1328 } finally {1329 if (_didIteratorError7) {1330 throw _iteratorError7;1331 }1332 }1333 }1334 return link ? (0, _apiTool2.default)('url', link).then(function (raw_data) {1335 var html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];1336 var html2 = (0, _utility.findTag)(html, 'html')[0];1337 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html2 ? html2 : html, 'body')[0], 'div', 'wrap')[0], 'table', 'layout')[0], 'tr')[0], 'td', 'center')[0], 'div', 'cp')[0], 'div', 'article')[0], 'div', 'p_date')[0])[0].match(/\d\d\d\d\/\d\d?\/\d\d?$/)[0] === docDate) {1338 list.push({1339 url: link,1340 name: (0, _utility.toValidName)('失æ¥ç'),1341 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1342 });1343 }1344 return list;1345 }) : list;1346 });1347 });1348 });1349 });1350 case 'mof':1351 return (0, _apiTool2.default)('url', 'https://www.mof.gov.tw/multiplehtml/384fb3077bb349ea973e7fc6f13b6974').then(function (raw_data) {1352 var date = new Date(url);1353 if (isNaN(date.getTime())) {1354 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1355 }1356 var docDate = date.getFullYear() + '-' + (0, _utility.completeZero)(date.getMonth() + 1, 2) + '-' + (0, _utility.completeZero)(date.getDate(), 2);1357 console.log(docDate);1358 var list = [];1359 var application = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'function-cabinet')[0], 'div', 'container')[0], 'div', 'row')[0], 'div', 'left-content')[0], 'div', 'left-content-text')[0], 'div', ' paging-content')[0], 'div', 'application')[0];1360 if (application) {1361 var _iteratorNormalCompletion8 = true;1362 var _didIteratorError8 = false;1363 var _iteratorError8 = undefined;1364 try {1365 for (var _iterator8 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(application, 'table')[0], 'tbody')[0], 'tr')), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {1366 var l = _step8.value;1367 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(l, 'td')[2], 'span')[0])[0] === docDate) {1368 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(l, 'td')[1], 'span')[0], 'a')[0];1369 var name = (0, _utility.findTag)(a)[0];1370 if (name.match(/æµ·éé²åºå£è²¿æ/)) {1371 list.push({1372 url: (0, _utility.addPre)(a.attribs.href, 'https://www.mof.gov.tw'),1373 name: (0, _utility.toValidName)(name),1374 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1375 });1376 break;1377 }1378 }1379 }1380 } catch (err) {1381 _didIteratorError8 = true;1382 _iteratorError8 = err;1383 } finally {1384 try {1385 if (!_iteratorNormalCompletion8 && _iterator8.return) {1386 _iterator8.return();1387 }1388 } finally {1389 if (_didIteratorError8) {1390 throw _iteratorError8;1391 }1392 }1393 }1394 }1395 return list;1396 });1397 case 'moe':1398 return (0, _apiTool2.default)('url', 'https://www.stat.gov.tw/lp.asp?ctNode=2299&CtUnit=1818&BaseDSD=29').then(function (raw_data) {1399 var date = new Date(url);1400 if (isNaN(date.getTime())) {1401 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1402 }1403 date = new Date(new Date(date).setDate(date.getDate() - 1));1404 var docDate = date.getFullYear() + '-' + (0, _utility.completeZero)(date.getMonth() + 1, 2) + '-' + (0, _utility.completeZero)(date.getDate(), 2);1405 console.log(docDate);1406 var list = [];1407 var pDate = new Date(new Date(date).setMonth(date.getMonth() - 1));1408 var docDate1 = pDate.getFullYear() - 1911 + '\u5E74' + (pDate.getMonth() + 1) + '\u6708';1409 console.log(docDate1);1410 var html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];1411 if (!html) {1412 console.log(raw_data);1413 return (0, _utility.handleError)(new _utility.HoError('empty html'));1414 }1415 var html2 = (0, _utility.findTag)(html, 'html')[0];1416 var lis = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html2 ? html2 : html, 'body')[0], 'div', 'wrap')[0], 'table', 'layout')[0], 'tr')[0], 'td', 'center')[0], 'div', 'lp')[0], 'div', 'list')[0], 'ul')[0], 'li');1417 var dUrl = false;1418 var _iteratorNormalCompletion9 = true;1419 var _didIteratorError9 = false;1420 var _iteratorError9 = undefined;1421 try {1422 for (var _iterator9 = (0, _getIterator3.default)(lis), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {1423 var l = _step9.value;1424 var a = (0, _utility.findTag)(l, 'a')[0];1425 var aMatch = a.attribs.title.match(/^\d\d\då¹´\d\d?æ/);1426 if (aMatch && aMatch[0] === docDate1) {1427 dUrl = (0, _utility.addPre)(a.attribs.href, 'http://www.moea.gov.tw');1428 break;1429 }1430 }1431 } catch (err) {1432 _didIteratorError9 = true;1433 _iteratorError9 = err;1434 } finally {1435 try {1436 if (!_iteratorNormalCompletion9 && _iterator9.return) {1437 _iterator9.return();1438 }1439 } finally {1440 if (_didIteratorError9) {1441 throw _iteratorError9;1442 }1443 }1444 }1445 ;1446 var industrial = function industrial() {1447 return dUrl ? (0, _apiTool2.default)('url', dUrl).then(function (raw_data) {1448 var matchT = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'form', 'form1')[0], 'main')[0], 'div', 'Float_layer')[0], 'div', 'divContent')[0], 'div', 'divContainer')[0], 'div', 'divDetail')[0], 'div', 'divRightContent')[0], 'div', 'div_Content')[0], 'div', 'container')[0], 'div')[0], 'div', 'divPageDetail')[0], 'div', 'div-top-info')[0], 'div', 'div-top-info-flex')[0], 'div', 'div-top-left-info')[0], 'div', 'div-sub-info')[0], 'div', 'div-begin-date')[0])[0].match(/\d\d\d\d-\d\d-\d\d/);1449 console.log(matchT);1450 if (matchT && matchT[0] === docDate) {1451 list.push({1452 url: dUrl,1453 name: (0, _utility.toValidName)('å·¥æ¥çç¢'),1454 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1455 });1456 }1457 }) : _promise2.default.resolve();1458 };1459 return industrial().then(function () {1460 return (0, _apiTool2.default)('url', 'https://www.stat.gov.tw/lp.asp?ctNode=2300&CtUnit=1818&BaseDSD=29').then(function (raw_data) {1461 html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];1462 if (!html) {1463 console.log(raw_data);1464 return (0, _utility.handleError)(new _utility.HoError('empty html'));1465 }1466 var html2 = (0, _utility.findTag)(html, 'html')[0];1467 lis = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html2 ? html2 : html, 'body')[0], 'div', 'wrap')[0], 'table', 'layout')[0], 'tr')[0], 'td', 'center')[0], 'div', 'lp')[0], 'div', 'list')[0], 'ul')[0], 'li');1468 dUrl = false;1469 var _iteratorNormalCompletion10 = true;1470 var _didIteratorError10 = false;1471 var _iteratorError10 = undefined;1472 try {1473 for (var _iterator10 = (0, _getIterator3.default)(lis), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {1474 var l = _step10.value;1475 var a = (0, _utility.findTag)(l, 'a')[0];1476 var aMatch = a.attribs.title.match(/^\d\d\då¹´\d\d?æ/);1477 if (aMatch && aMatch[0] === docDate1) {1478 dUrl = (0, _utility.addPre)(a.attribs.href, 'http://www.moea.gov.tw');1479 break;1480 }1481 }1482 } catch (err) {1483 _didIteratorError10 = true;1484 _iteratorError10 = err;1485 } finally {1486 try {1487 if (!_iteratorNormalCompletion10 && _iterator10.return) {1488 _iterator10.return();1489 }1490 } finally {1491 if (_didIteratorError10) {1492 throw _iteratorError10;1493 }1494 }1495 }1496 ;1497 var output = function output() {1498 return dUrl ? (0, _apiTool2.default)('url', dUrl).then(function (raw_data) {1499 var matchT = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'form', 'form1')[0], 'main')[0], 'div', 'Float_layer')[0], 'div', 'divContent')[0], 'div', 'divContainer')[0], 'div', 'divDetail')[0], 'div', 'divRightContent')[0], 'div', 'div_Content')[0], 'div', 'container')[0], 'div')[0], 'div', 'divPageDetail')[0], 'div', 'div-top-info')[0], 'div', 'div-top-info-flex')[0], 'div', 'div-top-left-info')[0], 'div', 'div-sub-info')[0], 'div', 'div-begin-date')[0])[0].match(/\d\d\d\d-\d\d-\d\d/);1500 console.log(matchT);1501 if (matchT && matchT[0] === docDate) {1502 list.push({1503 url: dUrl,1504 name: (0, _utility.toValidName)('å¤é·è¨å®çµ±è¨'),1505 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1506 });1507 }1508 }) : _promise2.default.resolve();1509 };1510 return output().then(function () {1511 return list;1512 });1513 });1514 });1515 });1516 case 'cbc':1517 return (0, _apiTool2.default)('url', 'https://www.cbc.gov.tw/tw/sp-news-list-1.html').then(function (raw_data) {1518 var date = new Date(url);1519 if (isNaN(date.getTime())) {1520 return (0, _utility.handleError)(new _utility.HoError('date invalid'));1521 }1522 date = new Date(new Date(date).setDate(date.getDate() - 1));1523 var docDate = date.getFullYear() + '-' + (0, _utility.completeZero)(date.getMonth() + 1, 2) + '-' + (0, _utility.completeZero)(date.getDate(), 2);1524 console.log(docDate);1525 var list = [];1526 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'wrapper')[0], 'div', 'center')[0], 'div', 'container')[0], 'section', 'lp')[0], 'div', 'list')[0], 'ul')[0], 'li').forEach(function (l) {1527 if ((0, _utility.findTag)((0, _utility.findTag)(l, 'time')[0])[0] === docDate) {1528 var a = (0, _utility.findTag)(l, 'a')[0];1529 list.push({1530 url: (0, _utility.addPre)(a.attribs.href, 'https://www.cbc.gov.tw/tw'),1531 name: (0, _utility.toValidName)(a.attribs.title),1532 date: date.getMonth() + 1 + '_' + date.getDate() + '_' + date.getFullYear()1533 });1534 }1535 });1536 return list;1537 });1538 default:1539 return (0, _utility.handleError)(new _utility.HoError('unknown external type'));1540 }1541 },1542 save2Drive: function save2Drive(type, obj, parent) {1543 var mkFolder = function mkFolder(folderPath) {1544 return !(0, _fs.existsSync)(folderPath) ? new _promise2.default(function (resolve, reject) {1545 return (0, _mkdirp2.default)(folderPath, function (err) {1546 return err ? reject(err) : resolve();1547 });1548 }) : _promise2.default.resolve();1549 };1550 var filePath = (0, _utility.getFileLocation)(type, (0, _mongoTool.objectID)());1551 console.log(filePath);1552 var driveName = '';1553 switch (type) {1554 case 'bls':1555 console.log(obj);1556 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {1557 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'wrapper-basic')[0], 'div', 'main-content-full-width')[0], 'div', 'bodytext')[0], 'h4')[1], 'a')[0];1558 if (!(0, _utility.findTag)(a)[0].match(/PDF/i)) {1559 return (0, _utility.handleError)(new _utility.HoError('cannot find release'));1560 }1561 var url = (0, _utility.addPre)(a.attribs.href, 'https://www.bls.gov');1562 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);1563 console.log(driveName);1564 return mkFolder((0, _path.dirname)(filePath)).then(function () {1565 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {1566 return (0, _apiToolGoogle2.default)('upload', {1567 type: 'auto',1568 name: driveName,1569 filePath: filePath,1570 parent: parent,1571 rest: function rest() {1572 return updateDocDate(type, obj.date);1573 },1574 errhandle: function errhandle(err) {1575 return (0, _utility.handleError)(err);1576 }1577 });1578 });1579 });1580 });1581 case 'cen':1582 console.log(obj);1583 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(obj.url);1584 console.log(driveName);1585 return mkFolder((0, _path.dirname)(filePath)).then(function () {1586 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {1587 return (0, _apiToolGoogle2.default)('upload', {1588 type: 'auto',1589 name: driveName,1590 filePath: filePath,1591 parent: parent,1592 rest: function rest() {1593 return updateDocDate(type, obj.date);1594 },1595 errhandle: function errhandle(err) {1596 return (0, _utility.handleError)(err);1597 }1598 });1599 });1600 });1601 case 'bea':1602 console.log(obj);1603 var ext1 = (0, _path.extname)(obj.url);1604 if (ext1 === '.pdf') {1605 driveName = obj.name + ' ' + obj.date + ext1;1606 console.log(driveName);1607 return mkFolder((0, _path.dirname)(filePath)).then(function () {1608 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {1609 return (0, _apiToolGoogle2.default)('upload', {1610 type: 'auto',1611 name: driveName,1612 filePath: filePath,1613 parent: parent,1614 rest: function rest() {1615 return updateDocDate(type, obj.date);1616 },1617 errhandle: function errhandle(err) {1618 return (0, _utility.handleError)(err);1619 }1620 });1621 });1622 });1623 }1624 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {1625 var hs = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div')[0], 'div')[0], 'div', 'row')[0], 'div', 'test')[0], 'div', 'region region-content')[0], 'article')[0], 'div', 'row')[0], 'div', 'container')[0], 'div', 'tab-content')[0], 'div', 'menu1')[0], 'div', 'row')[0], 'div')[0], 'h3');1626 var _iteratorNormalCompletion11 = true;1627 var _didIteratorError11 = false;1628 var _iteratorError11 = undefined;1629 try {1630 for (var _iterator11 = (0, _getIterator3.default)(hs), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {1631 var h = _step11.value;1632 var a = (0, _utility.findTag)(h, 'a')[0];1633 if ((0, _utility.findTag)(a)[0].match(/^Full Release/)) {1634 var _ret4 = function () {1635 var url = (0, _utility.addPre)(a.attribs.href, 'http://www.bea.gov');1636 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);1637 console.log(driveName);1638 return {1639 v: mkFolder((0, _path.dirname)(filePath)).then(function () {1640 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {1641 return (0, _apiToolGoogle2.default)('upload', {1642 type: 'auto',1643 name: driveName,1644 filePath: filePath,1645 parent: parent,1646 rest: function rest() {1647 return updateDocDate(type, obj.date);1648 },1649 errhandle: function errhandle(err) {1650 return (0, _utility.handleError)(err);1651 }1652 });1653 });1654 })1655 };1656 }();1657 if ((typeof _ret4 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret4)) === "object") return _ret4.v;1658 }1659 }1660 } catch (err) {1661 _didIteratorError11 = true;1662 _iteratorError11 = err;1663 } finally {1664 try {1665 if (!_iteratorNormalCompletion11 && _iterator11.return) {1666 _iterator11.return();1667 }1668 } finally {1669 if (_didIteratorError11) {1670 throw _iteratorError11;1671 }1672 }1673 }1674 });1675 case 'ism':1676 console.log(obj);1677 if (obj.url.match(/\.pdf$/)) {1678 driveName = obj.name + ' ' + obj.date + '.pdf';1679 console.log(driveName);1680 return mkFolder((0, _path.dirname)(filePath)).then(function () {1681 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {1682 return (0, _apiToolGoogle2.default)('upload', {1683 type: 'auto',1684 name: driveName,1685 filePath: filePath,1686 parent: parent,1687 rest: function rest() {1688 return updateDocDate(type, obj.date);1689 },1690 errhandle: function errhandle(err) {1691 return (0, _utility.handleError)(err);1692 }1693 });1694 });1695 });1696 } else {1697 driveName = obj.name + ' ' + obj.date + '.txt';1698 console.log(driveName);1699 return (0, _apiToolGoogle2.default)('upload', {1700 type: 'auto',1701 name: driveName,1702 body: obj.url,1703 parent: parent,1704 rest: function rest() {1705 return updateDocDate(type, obj.date);1706 },1707 errhandle: function errhandle(err) {1708 return (0, _utility.handleError)(err);1709 }1710 });1711 }1712 case 'cbo':1713 console.log(obj);1714 driveName = obj.name + ' ' + obj.date + '.txt';1715 console.log(driveName);1716 return (0, _apiToolGoogle2.default)('upload', {1717 type: 'auto',1718 name: driveName,1719 body: obj.url,1720 parent: parent,1721 rest: function rest() {1722 return updateDocDate(type, obj.date);1723 },1724 errhandle: function errhandle(err) {1725 return (0, _utility.handleError)(err);1726 }1727 });1728 case 'sem':1729 console.log(obj);1730 driveName = obj.name + ' ' + obj.date + '.txt';1731 console.log(driveName);1732 return (0, _apiToolGoogle2.default)('upload', {1733 type: 'auto',1734 name: driveName,1735 body: obj.url,1736 parent: parent,1737 rest: function rest() {1738 return updateDocDate(type, obj.date);1739 },1740 errhandle: function errhandle(err) {1741 return (0, _utility.handleError)(err);1742 }1743 });1744 case 'oec':1745 console.log(obj);1746 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {1747 var _iteratorNormalCompletion12 = true;1748 var _didIteratorError12 = false;1749 var _iteratorError12 = undefined;1750 try {1751 for (var _iterator12 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'section container')[0], 'div', 'row')[0], 'div', 'col-sm-9 leftnav-content-wrapper')[0], 'div', 'doc-type-container')[0], 'div', 'block')[0], 'div', 'webEditContent')[0], 'p')), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {1752 var p = _step12.value;1753 var s = (0, _utility.findTag)(p, 'strong')[0];1754 if (s) {1755 var a = (0, _utility.findTag)(s, 'a')[0];1756 if (!a) {1757 var ss = (0, _utility.findTag)(s, 'strong')[0];1758 if (ss) {1759 a = (0, _utility.findTag)(ss, 'a')[0];1760 }1761 }1762 if (a) {1763 if ((0, _utility.findTag)(a)[0].match(/pdf/i)) {1764 var _ret5 = function () {1765 var url = (0, _utility.addPre)(a.attribs.href, 'http://www.oecd.org');1766 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);1767 console.log(driveName);1768 return {1769 v: mkFolder((0, _path.dirname)(filePath)).then(function () {1770 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {1771 return (0, _apiToolGoogle2.default)('upload', {1772 type: 'auto',1773 name: driveName,1774 filePath: filePath,1775 parent: parent,1776 rest: function rest() {1777 return updateDocDate(type, obj.date);1778 },1779 errhandle: function errhandle(err) {1780 return (0, _utility.handleError)(err);1781 }1782 });1783 });1784 })1785 };1786 }();1787 if ((typeof _ret5 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret5)) === "object") return _ret5.v;1788 }1789 }1790 }1791 }1792 } catch (err) {1793 _didIteratorError12 = true;1794 _iteratorError12 = err;1795 } finally {1796 try {1797 if (!_iteratorNormalCompletion12 && _iterator12.return) {1798 _iterator12.return();1799 }1800 } finally {1801 if (_didIteratorError12) {1802 throw _iteratorError12;1803 }1804 }1805 }1806 });1807 case 'dol':1808 console.log(obj);1809 driveName = obj.name + ' ' + obj.date + '.pdf';1810 console.log(driveName);1811 return mkFolder((0, _path.dirname)(filePath)).then(function () {1812 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {1813 return (0, _apiToolGoogle2.default)('upload', {1814 type: 'auto',1815 name: driveName,1816 filePath: filePath,1817 parent: parent,1818 rest: function rest() {1819 return updateDocDate(type, obj.date);1820 },1821 errhandle: function errhandle(err) {1822 return (0, _utility.handleError)(err);1823 }1824 });1825 });1826 });1827 case 'rea':1828 console.log(obj);1829 driveName = obj.name + ' ' + obj.date + '.txt';1830 console.log(driveName);1831 return (0, _apiToolGoogle2.default)('upload', {1832 type: 'auto',1833 name: driveName,1834 body: obj.url,1835 parent: parent,1836 rest: function rest() {1837 return updateDocDate(type, obj.date);1838 },1839 errhandle: function errhandle(err) {1840 return (0, _utility.handleError)(err);1841 }1842 });1843 case 'sca':1844 console.log(obj);1845 driveName = obj.name + ' ' + obj.date + '.txt';1846 console.log(driveName);1847 return (0, _apiToolGoogle2.default)('upload', {1848 type: 'auto',1849 name: driveName,1850 body: obj.url,1851 parent: parent,1852 rest: function rest() {1853 return updateDocDate(type, obj.date);1854 },1855 errhandle: function errhandle(err) {1856 return (0, _utility.handleError)(err);1857 }1858 });1859 case 'fed':1860 console.log(obj);1861 var ext = (0, _path.extname)(obj.url);1862 if (ext === '.pdf') {1863 driveName = obj.name + ' ' + obj.date + ext;1864 console.log(driveName);1865 return mkFolder((0, _path.dirname)(filePath)).then(function () {1866 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {1867 return (0, _apiToolGoogle2.default)('upload', {1868 type: 'auto',1869 name: driveName,1870 filePath: filePath,1871 parent: parent,1872 rest: function rest() {1873 return updateDocDate(type, obj.date);1874 },1875 errhandle: function errhandle(err) {1876 return (0, _utility.handleError)(err);1877 }1878 });1879 });1880 });1881 }1882 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {1883 var match = obj.url.match(/^https\:\/\/www\.federalreserve\.gov\/releases\/(g\d+)\/current\//i);1884 if (match) {1885 var _ret6 = function () {1886 var url = '' + match[0] + match[1] + '.pdf';1887 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);1888 console.log(driveName);1889 return {1890 v: mkFolder((0, _path.dirname)(filePath)).then(function () {1891 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {1892 return (0, _apiToolGoogle2.default)('upload', {1893 type: 'auto',1894 name: driveName,1895 filePath: filePath,1896 parent: parent,1897 rest: function rest() {1898 return updateDocDate(type, obj.date);1899 },1900 errhandle: function errhandle(err) {1901 return (0, _utility.handleError)(err);1902 }1903 });1904 });1905 })1906 };1907 }();1908 if ((typeof _ret6 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret6)) === "object") return _ret6.v;1909 } else {1910 var share = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'content')[0], 'div', 'row')[0], 'div', 'page-header')[0], 'div', 'header-group')[0], 'div', 'shareDL')[0];1911 if (share) {1912 var a = (0, _utility.findTag)(share, 'a')[0];1913 if ((0, _utility.findTag)((0, _utility.findTag)(a, 'span')[1])[0].match(/pdf/i)) {1914 var _ret7 = function () {1915 var url = (0, _utility.addPre)(a.attribs.href, 'https://www.federalreserve.gov');1916 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);1917 console.log(driveName);1918 return {1919 v: mkFolder((0, _path.dirname)(filePath)).then(function () {1920 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {1921 return (0, _apiToolGoogle2.default)('upload', {1922 type: 'auto',1923 name: driveName,1924 filePath: filePath,1925 parent: parent,1926 rest: function rest() {1927 return updateDocDate(type, obj.date);1928 },1929 errhandle: function errhandle(err) {1930 return (0, _utility.handleError)(err);1931 }1932 });1933 });1934 })1935 };1936 }();1937 if ((typeof _ret7 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret7)) === "object") return _ret7.v;1938 }1939 }1940 }1941 driveName = obj.name + ' ' + obj.date + '.txt';1942 console.log(driveName);1943 return (0, _apiToolGoogle2.default)('upload', {1944 type: 'auto',1945 name: driveName,1946 body: obj.url,1947 parent: parent,1948 rest: function rest() {1949 return updateDocDate(type, obj.date);1950 },1951 errhandle: function errhandle(err) {1952 return (0, _utility.handleError)(err);1953 }1954 });1955 });1956 case 'sea':1957 console.log(obj);1958 driveName = obj.name + ' ' + obj.date + '.pdf';1959 console.log(driveName);1960 return mkFolder((0, _path.dirname)(filePath)).then(function () {1961 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {1962 return (0, _apiToolGoogle2.default)('upload', {1963 type: 'auto',1964 name: driveName,1965 filePath: filePath,1966 parent: parent,1967 rest: function rest() {1968 return updateDocDate(type, obj.date);1969 },1970 errhandle: function errhandle(err) {1971 return (0, _utility.handleError)(err);1972 }1973 });1974 });1975 });1976 case 'tri':1977 console.log(obj);1978 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {1979 return (0, _apiTool2.default)('url', (0, _utility.addPre)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'main')[0], 'div', 'content')[0], 'div', 'content01')[0], 'div', 'content02L')[0], 'div', 'content01LText')[0], 'div')[0], 'table', 'text6')[0], 'tr')[1], 'td')[1], 'a')[0].attribs.href, 'http://www.tri.org.tw/page')).then(function (raw_data) {1980 var url = (0, _utility.addPre)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'main')[0], 'div', 'content')[0], 'div', 'content01')[0], 'div', 'content02L')[0], 'div', 'content02LText')[0], 'div')[0], 'table', 'text6')[0], 'tr')[4], 'td')[0], 'a')[0].attribs.href, 'http://www.tri.org.tw');1981 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);1982 console.log(driveName);1983 return mkFolder((0, _path.dirname)(filePath)).then(function () {1984 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {1985 return (0, _apiToolGoogle2.default)('upload', {1986 type: 'auto',1987 name: driveName,1988 filePath: filePath,1989 parent: parent,1990 rest: function rest() {1991 return updateDocDate(type, obj.date);1992 },1993 errhandle: function errhandle(err) {1994 return (0, _utility.handleError)(err);1995 }1996 });1997 });1998 });1999 });2000 });2001 case 'ndc':2002 console.log(obj);2003 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(obj.url);2004 console.log(driveName);2005 return mkFolder((0, _path.dirname)(filePath)).then(function () {2006 return (0, _apiTool2.default)('url', obj.url, { filePath: filePath }).then(function () {2007 return (0, _apiToolGoogle2.default)('upload', {2008 type: 'auto',2009 name: driveName,2010 filePath: filePath,2011 parent: parent,2012 rest: function rest() {2013 return updateDocDate(type, obj.date);2014 },2015 errhandle: function errhandle(err) {2016 return (0, _utility.handleError)(err);2017 }2018 });2019 });2020 });2021 case 'sta':2022 console.log(obj);2023 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {2024 var html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];2025 var html2 = (0, _utility.findTag)(html, 'html')[0];2026 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html2 ? html2 : html, 'body')[0], 'div', 'wrap')[0], 'table', 'layout')[0], 'tr')[0], 'td', 'center')[0], 'div', 'cp')[0], 'div', 'article')[0], 'p').forEach(function (p) {2027 var as = (0, _utility.findTag)(p, 'a');2028 if (as.length > 0) {2029 var _iteratorNormalCompletion13 = true;2030 var _didIteratorError13 = false;2031 var _iteratorError13 = undefined;2032 try {2033 for (var _iterator13 = (0, _getIterator3.default)(as), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {2034 var a = _step13.value;2035 if (a.attribs.href.match(/\.pdf$/i)) {2036 var _ret8 = function () {2037 var url = (0, _utility.addPre)(a.attribs.href, 'https://www.stat.gov.tw');2038 if (url.match(/87231699T64V6LTY/)) {2039 return 'continue';2040 }2041 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);2042 console.log(driveName);2043 return {2044 v: mkFolder((0, _path.dirname)(filePath)).then(function () {2045 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {2046 return (0, _apiToolGoogle2.default)('upload', {2047 type: 'auto',2048 name: driveName,2049 filePath: filePath,2050 parent: parent,2051 rest: function rest() {2052 return updateDocDate(type, obj.date);2053 },2054 errhandle: function errhandle(err) {2055 return (0, _utility.handleError)(err);2056 }2057 });2058 });2059 })2060 };2061 }();2062 switch (_ret8) {2063 case 'continue':2064 continue;2065 default:2066 if ((typeof _ret8 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret8)) === "object") return _ret8.v;2067 }2068 }2069 }2070 } catch (err) {2071 _didIteratorError13 = true;2072 _iteratorError13 = err;2073 } finally {2074 try {2075 if (!_iteratorNormalCompletion13 && _iterator13.return) {2076 _iterator13.return();2077 }2078 } finally {2079 if (_didIteratorError13) {2080 throw _iteratorError13;2081 }2082 }2083 }2084 }2085 var bs = (0, _utility.findTag)(p, 'b');2086 if (bs.length > 0) {2087 var _iteratorNormalCompletion14 = true;2088 var _didIteratorError14 = false;2089 var _iteratorError14 = undefined;2090 try {2091 for (var _iterator14 = (0, _getIterator3.default)(bs), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {2092 var b = _step14.value;2093 as = (0, _utility.findTag)(b, 'a');2094 if (as.length > 0) {2095 var _iteratorNormalCompletion15 = true;2096 var _didIteratorError15 = false;2097 var _iteratorError15 = undefined;2098 try {2099 for (var _iterator15 = (0, _getIterator3.default)(as), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {2100 var _a = _step15.value;2101 if (_a.attribs.href.match(/\.pdf$/i)) {2102 var _ret9 = function () {2103 var url = (0, _utility.addPre)(_a.attribs.href, 'https://www.stat.gov.tw');2104 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);2105 console.log(driveName);2106 return {2107 v: mkFolder((0, _path.dirname)(filePath)).then(function () {2108 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {2109 return (0, _apiToolGoogle2.default)('upload', {2110 type: 'auto',2111 name: driveName,2112 filePath: filePath,2113 parent: parent,2114 rest: function rest() {2115 return updateDocDate(type, obj.date);2116 },2117 errhandle: function errhandle(err) {2118 return (0, _utility.handleError)(err);2119 }2120 });2121 });2122 })2123 };2124 }();2125 if ((typeof _ret9 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret9)) === "object") return _ret9.v;2126 }2127 }2128 } catch (err) {2129 _didIteratorError15 = true;2130 _iteratorError15 = err;2131 } finally {2132 try {2133 if (!_iteratorNormalCompletion15 && _iterator15.return) {2134 _iterator15.return();2135 }2136 } finally {2137 if (_didIteratorError15) {2138 throw _iteratorError15;2139 }2140 }2141 }2142 }2143 }2144 } catch (err) {2145 _didIteratorError14 = true;2146 _iteratorError14 = err;2147 } finally {2148 try {2149 if (!_iteratorNormalCompletion14 && _iterator14.return) {2150 _iterator14.return();2151 }2152 } finally {2153 if (_didIteratorError14) {2154 throw _iteratorError14;2155 }2156 }2157 }2158 }2159 });2160 });2161 case 'mof':2162 console.log(obj);2163 return (0, _apiTool2.default)('url', obj.url, { referer: 'https://www.mof.gov.tw/' }).then(function (raw_data) {2164 var ps = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'function-cabinet')[0], 'div', 'container')[0], 'div', 'row')[0], 'div', 'left-content')[0], 'div', 'left-content-text')[0], 'div')[1], 'article')[0], 'p');2165 var _iteratorNormalCompletion16 = true;2166 var _didIteratorError16 = false;2167 var _iteratorError16 = undefined;2168 try {2169 for (var _iterator16 = (0, _getIterator3.default)(ps), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {2170 var p = _step16.value;2171 var pc = (0, _utility.findTag)(p)[0];2172 if (pc && pc.match(/æ¬æåé表/)) {2173 var _ret10 = function () {2174 var url = (0, _utility.addPre)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(p, 'span')[0], 'strong')[0], 'span')[0], 'a')[0].attribs.href, 'https://www.mof.gov.tw');2175 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);2176 console.log(driveName);2177 return {2178 v: mkFolder((0, _path.dirname)(filePath)).then(function () {2179 return (0, _apiTool2.default)('url', encodeURI(url), { filePath: filePath }).then(function () {2180 return (0, _apiToolGoogle2.default)('upload', {2181 type: 'auto',2182 name: driveName,2183 filePath: filePath,2184 parent: parent,2185 rest: function rest() {2186 return updateDocDate(type, obj.date);2187 },2188 errhandle: function errhandle(err) {2189 return (0, _utility.handleError)(err);2190 }2191 });2192 });2193 })2194 };2195 }();2196 if ((typeof _ret10 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret10)) === "object") return _ret10.v;2197 } else {2198 var sp = (0, _utility.findTag)(p, 'span')[0];2199 var pcsp = (0, _utility.findTag)(sp)[0];2200 if (pcsp && pcsp.match(/æ¬æåé表/)) {2201 var _ret11 = function () {2202 var a = (0, _utility.findTag)((0, _utility.findTag)(sp, 'strong')[0], 'a')[0];2203 var url = a ? (0, _utility.addPre)(a.attribs.href, 'https://www.mof.gov.tw') : (0, _utility.addPre)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(sp, 'span')[0], 'strong')[0], 'span')[0], 'a')[0].attribs.href, 'https://www.mof.gov.tw');2204 driveName = obj.name + ' ' + obj.date + (0, _path.extname)(url);2205 console.log(driveName);2206 return {2207 v: mkFolder((0, _path.dirname)(filePath)).then(function () {2208 return (0, _apiTool2.default)('url', encodeURI(url), { filePath: filePath }).then(function () {2209 return (0, _apiToolGoogle2.default)('upload', {2210 type: 'auto',2211 name: driveName,2212 filePath: filePath,2213 parent: parent,2214 rest: function rest() {2215 return updateDocDate(type, obj.date);2216 },2217 errhandle: function errhandle(err) {2218 return (0, _utility.handleError)(err);2219 }2220 });2221 });2222 })2223 };2224 }();2225 if ((typeof _ret11 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret11)) === "object") return _ret11.v;2226 }2227 }2228 }2229 } catch (err) {2230 _didIteratorError16 = true;2231 _iteratorError16 = err;2232 } finally {2233 try {2234 if (!_iteratorNormalCompletion16 && _iterator16.return) {2235 _iterator16.return();2236 }2237 } finally {2238 if (_didIteratorError16) {2239 throw _iteratorError16;2240 }2241 }2242 }2243 ;2244 });2245 case 'moe':2246 console.log(obj);2247 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {2248 var files = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'form', 'form1')[0], 'main')[0], 'div', 'Float_layer')[0], 'div', 'divContent')[0], 'div', 'divContainer')[0], 'div', 'divDetail')[0], 'div', 'divRightContent')[0], 'div', 'div_Content')[0], 'div', 'news-detail-backcolor')[0], 'div', 'container')[0], 'div', 'divPageDetail_Content')[0], 'div')[0], 'div', 'div-flex-info')[0], 'div', 'div-right-info')[0], 'div')[0], 'div')[0], 'div');2249 var _iteratorNormalCompletion17 = true;2250 var _didIteratorError17 = false;2251 var _iteratorError17 = undefined;2252 try {2253 for (var _iterator17 = (0, _getIterator3.default)(files), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {2254 var f = _step17.value;2255 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(f, 'div')[1], 'div')[0], 'div')[0], 'a')[0];2256 if (a.attribs.title.match(/æ°è稿åå
¨é¨é表.*pdf/)) {2257 var _ret12 = function () {2258 var url = a.attribs.href;2259 url = url.match(/^(http|https):\/\//) ? url : 'http://' + (0, _path.join)('www.moea.gov.tw/MNS/populace/news', url);2260 driveName = obj.name + ' ' + obj.date + '.pdf';2261 console.log(driveName);2262 return {2263 v: mkFolder((0, _path.dirname)(filePath)).then(function () {2264 return (0, _apiTool2.default)('url', url, { filePath: filePath }).then(function () {2265 return (0, _apiToolGoogle2.default)('upload', {2266 type: 'auto',2267 name: driveName,2268 filePath: filePath,2269 parent: parent,2270 rest: function rest() {2271 return updateDocDate(type, obj.date);2272 },2273 errhandle: function errhandle(err) {2274 return (0, _utility.handleError)(err);2275 }2276 });2277 });2278 })2279 };2280 }();2281 if ((typeof _ret12 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret12)) === "object") return _ret12.v;2282 }2283 }2284 } catch (err) {2285 _didIteratorError17 = true;2286 _iteratorError17 = err;2287 } finally {2288 try {2289 if (!_iteratorNormalCompletion17 && _iterator17.return) {2290 _iterator17.return();2291 }2292 } finally {2293 if (_didIteratorError17) {2294 throw _iteratorError17;2295 }2296 }2297 }2298 });2299 case 'cbc':2300 console.log(obj);2301 return (0, _apiTool2.default)('url', obj.url).then(function (raw_data) {2302 var download = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'wrapper')[0], 'div', 'center')[0], 'div', 'container')[0], 'div', 'file_download')[0];2303 var downloadList = [];2304 if (download) {2305 (0, _utility.findTag)((0, _utility.findTag)(download, 'ul')[0], 'li').forEach(function (l) {2306 return (0, _utility.findTag)(l, 'a').forEach(function (a) {2307 if (a.attribs.title.match(/\.(pdf|xlsx)$/i)) {2308 downloadList.push({2309 url: (0, _utility.addPre)(a.attribs.href, 'https://www.cbc.gov.tw/tw'),2310 name: a.attribs.title2311 });2312 }2313 });2314 });2315 }2316 var recur_down = function recur_down(dIndex) {2317 if (dIndex < downloadList.length) {2318 var _ret13 = function () {2319 driveName = obj.name + ' ' + obj.date + '.' + dIndex + (0, _path.extname)(downloadList[dIndex].name);2320 console.log(driveName);2321 var subPath = (0, _utility.getFileLocation)(type, (0, _mongoTool.objectID)());2322 return {2323 v: mkFolder((0, _path.dirname)(subPath)).then(function () {2324 return (0, _apiTool2.default)('url', downloadList[dIndex].url, { filePath: subPath }).then(function () {2325 return (0, _apiToolGoogle2.default)('upload', {2326 type: 'auto',2327 name: driveName,2328 filePath: subPath,2329 parent: parent,2330 rest: function rest() {2331 return recur_down(dIndex + 1);2332 },2333 errhandle: function errhandle(err) {2334 return (0, _utility.handleError)(err);2335 }2336 });2337 });2338 })2339 };2340 }();2341 if ((typeof _ret13 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret13)) === "object") return _ret13.v;2342 } else {2343 return updateDocDate(type, obj.date);2344 }2345 };2346 driveName = obj.name + ' ' + obj.date + '.txt';2347 console.log(driveName);2348 return (0, _apiToolGoogle2.default)('upload', {2349 type: 'auto',2350 name: driveName,2351 body: obj.url,2352 parent: parent,2353 rest: function rest() {2354 return recur_down(0);2355 },2356 errhandle: function errhandle(err) {2357 return (0, _utility.handleError)(err);2358 }2359 });2360 });2361 default:2362 return (0, _utility.handleError)(new _utility.HoError('unknown external type'));2363 }2364 },2365 parseTagUrl: function parseTagUrl(type, url) {2366 var taglist = new _set2.default();2367 switch (type) {2368 case 'imdb':2369 return (0, _apiTool2.default)('url', url).then(function (raw_data) {2370 taglist.add('æç¾');2371 var html = (0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0];2372 var title = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html, 'head')[0], 'title')[0])[0];2373 title = title.match(/^(.*?) \((\d\d\d\d)\) - IMDb$/);2374 taglist.add(title[1]).add(title[2]);2375 var main = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(html, 'body')[0], 'div', 'wrapper')[0], 'div', 'root')[0], 'div', 'pagecontent')[0], 'div', 'content-2-wide')[0];2376 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(main, 'div', 'main_top')[0], 'div', 'title-overview')[0], 'div', 'title-overview-widget')[0], 'div', 'plot_summary_wrapper')[0], 'div', 'plot_summary ')[0], 'div', 'credit_summary_item').forEach(function (d) {2377 return (0, _utility.findTag)(d, 'a').forEach(function (a) {2378 if (a.attribs.href.match(/^\/name\//)) {2379 taglist.add((0, _utility.findTag)(a)[0]);2380 }2381 });2382 });2383 var main_bottom = (0, _utility.findTag)(main, 'div', 'main_bottom')[0];2384 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(main_bottom, 'div', 'titleCast')[0], 'table', 'cast_list')[0], 'tr').forEach(function (t) {2385 var cast = (0, _utility.findTag)(t, 'td');2386 if (cast.length > 1) {2387 taglist.add((0, _utility.findTag)((0, _utility.findTag)(cast[1], 'a')[0])[0]);2388 }2389 });2390 var _iteratorNormalCompletion18 = true;2391 var _didIteratorError18 = false;2392 var _iteratorError18 = undefined;2393 try {2394 for (var _iterator18 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)(main_bottom, 'div', 'titleStoryLine')[0], 'div', 'see-more inline canwrap')), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) {2395 var t = _step18.value;2396 if ((0, _utility.findTag)((0, _utility.findTag)(t, 'h4')[0])[0] === 'Genres:') {2397 (0, _utility.findTag)(t, 'a').forEach(function (a) {2398 var genre = (0, _utility.findTag)(a)[0].toLowerCase().trim();2399 taglist.add(genre);2400 var index = _constants.GENRE_LIST.indexOf(genre);2401 if (index !== -1) {2402 taglist.add(_constants.GENRE_LIST_CH[index]);2403 }2404 });2405 break;2406 }2407 }2408 } catch (err) {2409 _didIteratorError18 = true;2410 _iteratorError18 = err;2411 } finally {2412 try {2413 if (!_iteratorNormalCompletion18 && _iterator18.return) {2414 _iterator18.return();2415 }2416 } finally {2417 if (_didIteratorError18) {2418 throw _iteratorError18;2419 }2420 }2421 }2422 var _iteratorNormalCompletion19 = true;2423 var _didIteratorError19 = false;2424 var _iteratorError19 = undefined;2425 try {2426 for (var _iterator19 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)(main_bottom, 'div', 'titleDetails')[0], 'div', 'txt-block')), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) {2427 var _t = _step19.value;2428 if ((0, _utility.findTag)((0, _utility.findTag)(_t, 'h4')[0])[0] === 'Country:') {2429 (0, _utility.findTag)(_t, 'a').forEach(function (a) {2430 return taglist.add((0, _utility.findTag)(a)[0]);2431 });2432 break;2433 }2434 }2435 } catch (err) {2436 _didIteratorError19 = true;2437 _iteratorError19 = err;2438 } finally {2439 try {2440 if (!_iteratorNormalCompletion19 && _iterator19.return) {2441 _iterator19.return();2442 }2443 } finally {2444 if (_didIteratorError19) {2445 throw _iteratorError19;2446 }2447 }2448 }2449 return [].concat((0, _toConsumableArray3.default)(taglist)).map(function (t) {2450 return (0, _utility.toValidName)(t.toLowerCase());2451 });2452 });2453 case 'steam':2454 return (0, _apiTool2.default)('url', url, { cookie: 'birthtime=536425201; lastagecheckage=1-January-1987' }).then(function (raw_data) {2455 taglist.add('æç¾').add('éæ²').add('game');2456 var info = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'responsive_page_frame with_header')[0], 'div', 'responsive_page_content')[0], 'div', 'responsive_page_template_content')[0], 'div', 'game_page_background game')[0], 'div', 'page_content_ctn')[0], 'div', 'page_content')[0], 'div', 'rightcol game_meta_data')[0], 'div', 'block responsive_apppage_details_left game_details underlined_links')[0], 'div')[0], 'div')[0], 'div')[0];2457 (0, _utility.findTag)(info).forEach(function (i) {2458 var name = i.trim();2459 if (name !== ',') {2460 var date = name.match(/^\d?\d [a-zA-Z][a-zA-Z][a-zA-Z], (\d\d\d\d)$/);2461 taglist.add(date ? date[1] : name);2462 }2463 });2464 (0, _utility.findTag)(info, 'a').forEach(function (i) {2465 var a = (0, _utility.findTag)(i)[0].toLowerCase();2466 if (a === 'sports') {2467 a = 'sport';2468 }2469 taglist.add(a);2470 var index = _constants.GAME_LIST.indexOf(a);2471 if (index !== -1) {2472 taglist.add(_constants.GAME_LIST_CH[index]);2473 }2474 });2475 return [].concat((0, _toConsumableArray3.default)(taglist)).map(function (t) {2476 return (0, _utility.toValidName)(t.toLowerCase());2477 });2478 });2479 case 'allmusic':2480 return (0, _apiTool2.default)('url', url).then(function (raw_data) {2481 taglist.add('æç¾').add('é³æ¨').add('music');2482 var overflow = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div')[1];2483 if (overflow.attribs.class === 'overflow-container album') {2484 var container = (0, _utility.findTag)((0, _utility.findTag)(overflow, 'div', 'cmn_wrap')[0], 'div', 'content-container')[0];2485 var content = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(container, 'div', 'content')[0], 'header')[0], 'hgroup')[0];2486 var basic = (0, _utility.findTag)((0, _utility.findTag)(container, 'div', 'sidebar')[0], 'section', 'basic-info')[0];2487 taglist.add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(content, 'h2', 'album-artist')[0], 'span')[0], 'a')[0])[0]).add((0, _utility.findTag)((0, _utility.findTag)(content, 'h1', 'album-title')[0])[0].trim()).add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(basic, 'div', 'release-date')[0], 'span')[0])[0].match(/\d+$/)[0]);2488 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(basic, 'div', 'genre')[0], 'div')[0], 'a').forEach(function (a) {2489 var genre = (0, _utility.findTag)(a)[0].toLowerCase();2490 var index = _constants.MUSIC_LIST_WEB.indexOf(genre);2491 taglist.add(index !== -1 ? _constants.MUSIC_LIST[index] : genre);2492 });2493 } else if (overflow.attribs.class === 'overflow-container song') {2494 var overview = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(overflow, 'div', 'cmn_wrap')[0], 'div', 'content-container')[0], 'div', 'content overview')[0];2495 var _content = (0, _utility.findTag)((0, _utility.findTag)(overview, 'header')[0], 'hgroup')[0];2496 taglist.add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_content, 'h2', 'song-artist')[0], 'span')[0], 'a')[0])[0]).add((0, _utility.findTag)((0, _utility.findTag)(_content, 'h1', 'song-title')[0])[0].trim()).add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(overview, 'section', 'appearances')[0], 'table')[0], 'tbody')[0], 'tr')[0], 'td', 'year')[0])[0].trim());2497 } else if (overflow.attribs.class === 'overflow-container artist') {2498 var _container = (0, _utility.findTag)((0, _utility.findTag)(overflow, 'div', 'cmn_wrap')[0], 'div', 'content-container')[0];2499 taglist.add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_container, 'div', 'content')[0], 'header')[0], 'div', 'artist-bio-container')[0], 'hgroup')[0], 'h1', 'artist-name')[0])[0].trim());2500 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_container, 'div', 'sidebar')[0], 'section', 'basic-info')[0], 'div', 'genre')[0], 'div')[0], 'a').forEach(function (a) {2501 var genre = (0, _utility.findTag)(a)[0].toLowerCase();2502 var index = _constants.MUSIC_LIST_WEB.indexOf(genre);2503 taglist.add(index !== -1 ? _constants.MUSIC_LIST[index] : genre);2504 });2505 }2506 return [].concat((0, _toConsumableArray3.default)(taglist)).map(function (t) {2507 return (0, _utility.toValidName)(t.toLowerCase());2508 });2509 });2510 case 'marvel':2511 case 'dc':2512 return (0, _apiTool2.default)('url', url).then(function (raw_data) {2513 taglist.add('æç¾').add('漫ç«').add('comic').add(type);2514 var _iteratorNormalCompletion20 = true;2515 var _didIteratorError20 = false;2516 var _iteratorError20 = undefined;2517 try {2518 for (var _iterator20 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'WikiaSiteWrapper')[0], 'section', 'WikiaPage')[0], 'div', 'WikiaPageContentWrapper')[0], 'article', 'WikiaMainContent')[0], 'div', 'WikiaMainContentContainer')[0], 'div', 'WikiaArticle')[0], 'div', 'mw-content-text')[0], 'div')), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) {2519 var div = _step20.value;2520 if (div.attribs.class !== 'center') {2521 (0, _utility.findTag)(div, 'div').forEach(function (d, i) {2522 if (i === 0) {2523 var name = (0, _utility.findTag)(d);2524 if (name.length > 0) {2525 taglist.add(name[0]);2526 } else {2527 var _iteratorNormalCompletion21 = true;2528 var _didIteratorError21 = false;2529 var _iteratorError21 = undefined;2530 try {2531 for (var _iterator21 = (0, _getIterator3.default)(d.children), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) {2532 var c = _step21.value;2533 name = (0, _utility.findTag)(c);2534 if (c.type === 'tag' && name.length > 0) {2535 taglist.add(name[0]);2536 break;2537 }2538 }2539 } catch (err) {2540 _didIteratorError21 = true;2541 _iteratorError21 = err;2542 } finally {2543 try {2544 if (!_iteratorNormalCompletion21 && _iterator21.return) {2545 _iterator21.return();2546 }2547 } finally {2548 if (_didIteratorError21) {2549 throw _iteratorError21;2550 }2551 }2552 }2553 }2554 } else {2555 var dd = (0, _utility.findTag)(d, 'div');2556 if (dd.length > 0) {2557 if ((0, _utility.findTag)(dd[0]).length > 0) {2558 if ((0, _utility.findTag)(dd[0])[0].match(/First appearance/i)) {2559 var date = (0, _utility.findTag)(dd[2], 'div');2560 if (date.length > 0) {2561 taglist.add((0, _utility.findTag)((0, _utility.findTag)(date[0], 'a')[0])[0].match(/\d+$/)[0]);2562 }2563 } else if ((0, _utility.findTag)(dd[0])[0].match(/(creator|Editor\-in\-Chief|Cover Artist|writer|penciler|inker|letterer|editor)/i)) {2564 (0, _utility.findTag)(dd[1], 'a').forEach(function (a) {2565 return taglist.add((0, _utility.findTag)(a)[0]);2566 });2567 }2568 } else if ((0, _utility.findTag)(dd[0], 'span').length > 0 && (0, _utility.findTag)((0, _utility.findTag)(dd[0], 'span')[1])[0].match(/(creator|Editor\-in\-Chief|Cover Artist|writer|penciler|inker|letterer|editor)/i)) {2569 (0, _utility.findTag)(dd[1], 'a').forEach(function (a) {2570 return taglist.add((0, _utility.findTag)(a)[0]);2571 });2572 }2573 }2574 }2575 });2576 break;2577 }2578 }2579 } catch (err) {2580 _didIteratorError20 = true;2581 _iteratorError20 = err;2582 } finally {2583 try {2584 if (!_iteratorNormalCompletion20 && _iterator20.return) {2585 _iterator20.return();2586 }2587 } finally {2588 if (_didIteratorError20) {2589 throw _iteratorError20;2590 }2591 }2592 }2593 return [].concat((0, _toConsumableArray3.default)(taglist)).map(function (t) {2594 return (0, _utility.toValidName)(t.toLowerCase());2595 });2596 });2597 case 'tvdb':2598 return (0, _apiTool2.default)('url', url).then(function (raw_data) {2599 taglist.add('æç¾').add('é»è¦å').add('tv show');2600 var fanart = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'table')[0], 'tr')[2], 'td', 'maincontent')[0], 'div', 'fanart')[0];2601 taglist.add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(fanart, 'table')[0], 'tr')[0], 'td')[2], 'div', 'content')[0], 'h1')[0])[0]);2602 (0, _utility.findTag)(fanart, 'div', 'content').forEach(function (c, i) {2603 if (i === 0) {2604 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(c, 'table')[0], 'tr')[0], 'td')[0], 'table')[0], 'tr').forEach(function (t) {2605 var label = (0, _utility.findTag)((0, _utility.findTag)(t, 'td')[0])[0];2606 if (label === 'First Aired:') {2607 taglist.add((0, _utility.findTag)((0, _utility.findTag)(t, 'td')[1])[0].match(/\d+$/)[0]);2608 } else if (label === 'Network:') {2609 taglist.add((0, _utility.findTag)((0, _utility.findTag)(t, 'td')[1])[0]);2610 } else if (label === 'Genre:') {2611 (0, _utility.findTag)((0, _utility.findTag)(t, 'td')[1]).forEach(function (d) {2612 var g = d.toLowerCase();2613 if (g === 'science-fiction') {2614 g = 'sci-fi';2615 }2616 var index = _constants.GENRE_LIST.indexOf(g);2617 taglist.add(g);2618 if (index !== -1) {2619 taglist.add(_constants.GENRE_LIST_CH[index]);2620 }2621 });2622 }2623 });2624 } else {2625 if ((0, _utility.findTag)((0, _utility.findTag)(c, 'h1')[0])[0] === 'Actors') {2626 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(c, 'table')[0], 'tr')[0], 'td').forEach(function (t) {2627 return taglist.add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(t, 'table')[0], 'tr')[0], 'td')[0], 'h2')[0], 'a')[0])[0]);2628 });2629 }2630 }2631 });2632 return [].concat((0, _toConsumableArray3.default)(taglist)).map(function (t) {2633 return (0, _utility.toValidName)(t.toLowerCase());2634 });2635 });2636 default:2637 return (0, _utility.handleError)(new _utility.HoError('unknown external type'));2638 }2639 },2640 youtubePlaylist: function youtubePlaylist(id, index) {2641 var pageToken = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;2642 var back = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;2643 return (0, _apiToolGoogle2.default)('y playItem', (0, _assign2.default)({ id: id }, pageToken ? { pageToken: pageToken } : {})).then(function (_ref) {2644 var _ref2 = (0, _slicedToArray3.default)(_ref, 4),2645 vId_arr = _ref2[0],2646 total = _ref2[1],2647 nPageToken = _ref2[2],2648 pPageToken = _ref2[3];2649 if (total <= 0) {2650 return (0, _utility.handleError)(new _utility.HoError('playlist is empty'));2651 }2652 var ret_obj = back ? vId_arr[vId_arr.length - 1] : vId_arr[0];2653 var is_new = true;2654 if (index === 1) {2655 is_new = false;2656 } else {2657 var _iteratorNormalCompletion22 = true;2658 var _didIteratorError22 = false;2659 var _iteratorError22 = undefined;2660 try {2661 for (var _iterator22 = (0, _getIterator3.default)(vId_arr), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) {2662 var i = _step22.value;2663 if (i.id === index) {2664 ret_obj = i;2665 is_new = false;2666 break;2667 }2668 }2669 } catch (err) {2670 _didIteratorError22 = true;2671 _iteratorError22 = err;2672 } finally {2673 try {2674 if (!_iteratorNormalCompletion22 && _iterator22.return) {2675 _iterator22.return();2676 }2677 } finally {2678 if (_didIteratorError22) {2679 throw _iteratorError22;2680 }2681 }2682 }2683 }2684 return [ret_obj, false, total, vId_arr, nPageToken, pPageToken, pageToken, is_new];2685 });2686 },2687 getSingleId: function getSingleId(type, url, index) {2688 var _this = this;2689 var pageToken = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;2690 var back = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;2691 var sub_index = 0;2692 if (typeof index === 'number' || index.match(/^[\d\.]+$/)) {2693 if (index < 1) {2694 return (0, _utility.handleError)(new _utility.HoError('index must > 0'));2695 }2696 sub_index = Math.round(+index * 1000) % 1000;2697 if (sub_index === 0) {2698 sub_index++;2699 }2700 index = Math.floor(+index);2701 } else if (type !== 'youtube') {2702 return (0, _utility.handleError)(new _utility.HoError('index invalid'));2703 }2704 console.log(url);2705 var saveList = function saveList(getlist, raw_list, is_end, etime) {2706 var exGet = function exGet() {2707 return etime === -1 ? _promise2.default.resolve([raw_list, is_end]) : !etime || etime < new Date().getTime() / 1000 ? getlist() : _promise2.default.resolve([[], false]);2708 };2709 exGet().then(function (_ref3) {2710 var _ref4 = (0, _slicedToArray3.default)(_ref3, 2),2711 raw_list = _ref4[0],2712 is_end = _ref4[1];2713 if (raw_list.length > 0) {2714 return (0, _redisTool2.default)('hmset', 'url: ' + encodeURIComponent(url), {2715 raw_list: (0, _stringify2.default)(raw_list),2716 is_end: is_end,2717 etime: Math.round(new Date().getTime() / 1000 + _constants.CACHE_EXPIRE)2718 });2719 }2720 }).catch(function (err) {2721 return (0, _utility.handleError)(err, 'Redis');2722 });2723 };2724 var _ret14 = function () {2725 switch (type) {2726 case 'youtube':2727 var youtube_id = url.match(/list=([^&]+)/);2728 return {2729 v: youtube_id ? _this.youtubePlaylist(youtube_id[1], index, pageToken, back) : _promise2.default.resolve([{2730 id: 'you_' + url.match(/v=([^&]+)/)[1],2731 index: 1,2732 showId: 12733 }, false, 1])2734 };2735 case 'lovetv':2736 var prefix = url.match(/^((http|https):\/\/[^\/]+)\//);2737 if (!prefix) {2738 return {2739 v: (0, _utility.handleError)(new _utility.HoError('invaild url'))2740 };2741 }2742 prefix = prefix[1];2743 var lovetvGetlist = function lovetvGetlist() {2744 return (0, _apiTool2.default)('url', url).then(function (raw_data) {2745 var list = [];2746 var content = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'content')[0];2747 if (content) {2748 var outer = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(content, 'div', 'content-outer')[0], 'div', 'fauxborder-left content-fauxborder-left')[0], 'div', 'content-inner')[0], 'div', 'main-outer')[0], 'div', 'fauxborder-left main-fauxborder-left')[0], 'div', 'region-inner main-inner')[0], 'div', 'columns fauxcolumns')[0], 'div', 'columns-inner')[0], 'div', 'column-center-outer')[0], 'div', 'column-center-inner')[0], 'div', 'main')[0], 'div', 'Blog1')[0], 'div', 'blog-posts hfeed')[0], 'div', 'date-outer');2749 var table = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(outer[0], 'div', 'date-posts')[0], 'div', 'post-outer')[0], 'div')[0], 'div', 'post-body entry-content')[0], 'table')[0];2750 if (table) {2751 (0, _utility.findTag)(table, 'tr').forEach(function (t) {2752 var h = (0, _utility.findTag)((0, _utility.findTag)(t, 'td')[0], 'h3')[0];2753 if (h) {2754 var a = (0, _utility.findTag)(h, 'a')[0];2755 if (a) {2756 var name = (0, _utility.findTag)(a)[0];2757 if (!name.match(/Synopsis$/i)) {2758 list.splice(0, 0, {2759 name: name,2760 url: a.attribs.href2761 });2762 }2763 }2764 }2765 });2766 } else {2767 var _iteratorNormalCompletion23 = true;2768 var _didIteratorError23 = false;2769 var _iteratorError23 = undefined;2770 try {2771 for (var _iterator23 = (0, _getIterator3.default)(outer), _step23; !(_iteratorNormalCompletion23 = (_step23 = _iterator23.next()).done); _iteratorNormalCompletion23 = true) {2772 var o = _step23.value;2773 var a = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(o, 'div', 'date-posts')[0], 'div', 'post-outer')[0], 'div')[0], 'h3')[0], 'a')[0];2774 var name = (0, _utility.findTag)(a)[0];2775 if (name.match(/åéå表/)) {2776 url = a.attribs.href;2777 console.log(url);2778 return lovetvGetlist();2779 }2780 if (!name.match(/Synopsis$/i)) {2781 list.splice(0, 0, {2782 name: name,2783 url: a.attribs.href2784 });2785 }2786 }2787 } catch (err) {2788 _didIteratorError23 = true;2789 _iteratorError23 = err;2790 } finally {2791 try {2792 if (!_iteratorNormalCompletion23 && _iterator23.return) {2793 _iterator23.return();2794 }2795 } finally {2796 if (_didIteratorError23) {2797 throw _iteratorError23;2798 }2799 }2800 }2801 }2802 } else {2803 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'wrapper')[0], 'div', 'main')[0], 'div', 'container')[0], 'div', 'content')[0], 'div')[2], 'div', 'entry-content')[0], 'table')[0], 'tbody')[0], 'tr').forEach(function (t) {2804 var h = (0, _utility.findTag)((0, _utility.findTag)(t, 'td')[0], 'h3')[0];2805 if (h) {2806 var _a2 = (0, _utility.findTag)(h, 'a')[0];2807 var _name = (0, _utility.findTag)(_a2)[0];2808 if (!_name.match(/Synopsis$/i)) {2809 list.splice(0, 0, {2810 name: _name,2811 url: _a2.attribs.href2812 });2813 }2814 }2815 });2816 }2817 var is_end = false;2818 var _iteratorNormalCompletion24 = true;2819 var _didIteratorError24 = false;2820 var _iteratorError24 = undefined;2821 try {2822 for (var _iterator24 = (0, _getIterator3.default)(list), _step24; !(_iteratorNormalCompletion24 = (_step24 = _iterator24.next()).done); _iteratorNormalCompletion24 = true) {2823 var _i = _step24.value;2824 if (_i.name.match(/大çµå±/)) {2825 is_end = true;2826 break;2827 }2828 }2829 } catch (err) {2830 _didIteratorError24 = true;2831 _iteratorError24 = err;2832 } finally {2833 try {2834 if (!_iteratorNormalCompletion24 && _iterator24.return) {2835 _iterator24.return();2836 }2837 } finally {2838 if (_didIteratorError24) {2839 throw _iteratorError24;2840 }2841 }2842 }2843 return list.length < 1 ? (0, _mongoTool2.default)('find', _constants.STORAGEDB, {2844 owner: type,2845 url: encodeURIComponent(url)2846 }).then(function (items) {2847 if (items.length < 1) {2848 return (0, _utility.handleError)(new _utility.HoError('cannot find lovetv url'));2849 }2850 var nextLove = function nextLove(index, dramaIndex, list) {2851 var _iteratorNormalCompletion25 = true;2852 var _didIteratorError25 = false;2853 var _iteratorError25 = undefined;2854 try {2855 var _loop = function _loop() {2856 var i = _step25.value;2857 if (i.name === items[0].name) {2858 var validUrl = (0, _utility.isValidString)(i.url, 'url');2859 if (!validUrl) {2860 return {2861 v: (0, _utility.handleError)(new _utility.HoError('url is not vaild'))2862 };2863 }2864 return {2865 v: (0, _mongoTool2.default)('update', _constants.STORAGEDB, { _id: items[0]._id }, { $set: { url: validUrl } }).then(function (item) {2866 url = i.url;2867 return lovetvGetlist();2868 })2869 };2870 }2871 };2872 for (var _iterator25 = (0, _getIterator3.default)(list), _step25; !(_iteratorNormalCompletion25 = (_step25 = _iterator25.next()).done); _iteratorNormalCompletion25 = true) {2873 var _ret15 = _loop();2874 if ((typeof _ret15 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret15)) === "object") return _ret15.v;2875 }2876 } catch (err) {2877 _didIteratorError25 = true;2878 _iteratorError25 = err;2879 } finally {2880 try {2881 if (!_iteratorNormalCompletion25 && _iterator25.return) {2882 _iterator25.return();2883 }2884 } finally {2885 if (_didIteratorError25) {2886 throw _iteratorError25;2887 }2888 }2889 }2890 dramaIndex++;2891 if (dramaIndex < dramaList.length) {2892 return recur_loveList(dramaIndex, nextLove);2893 }2894 return (0, _utility.handleError)(new _utility.HoError('cannot find lovetv'));2895 };2896 return recur_loveList(0, nextLove);2897 }) : [list, is_end];2898 });2899 };2900 return {2901 v: (0, _redisTool2.default)('hgetall', 'url: ' + encodeURIComponent(url)).then(function (item) {2902 var sendList = function sendList(raw_list, is_end, etime) {2903 var choose = raw_list[index - 1];2904 if (!choose) {2905 return (0, _utility.handleError)(new _utility.HoError('cannot find external index'));2906 }2907 saveList(lovetvGetlist, raw_list, is_end, etime);2908 return [(0, _assign2.default)({2909 id: 'ope_' + new Buffer(!choose.url.match(/^(http|https):\/\//) ? '' + prefix + choose.url : choose.url).toString('base64'),2910 title: choose.name,2911 index: index,2912 showId: index2913 }), is_end, raw_list.length];2914 /*return Api('url', !choose.url.match(/^(http|https):\/\//) ? `${prefix}${choose.url}` : choose.url).then(raw_data => {2915 let obj = [];2916 const vs = findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'content')[0], 'div', 'content-outer')[0], 'div', 'fauxborder-left content-fauxborder-left')[0], 'div', 'content-inner')[0], 'div', 'main-outer')[0], 'div', 'fauxborder-left main-fauxborder-left')[0], 'div', 'region-inner main-inner')[0], 'div', 'columns fauxcolumns')[0], 'div', 'columns-inner')[0], 'div', 'column-center-outer')[0], 'div', 'column-center-inner')[0], 'div', 'main')[0], 'div', 'widget Blog')[0], 'div', 'blog-posts hfeed')[0], 'div', 'date-outer')[0], 'div', 'date-posts')[0], 'div', 'post-outer')[0], 'div')[0], 'div', 'post-body entry-content')[0];2917 const getV = (v, vType='') => {2918 if (v) {2919 const vIds = findTag(findTag(v, 'div', `video_ids${vType}`)[0])[0].match(/[^,]+/g);2920 if (vIds.length > 0) {2921 const t = Number(findTag(findTag(v, 'div', `video_type${vType}`)[0])[0]);2922 if (t === 17) {2923 for (let i = 1; i <= vIds[1]; i++) {2924 obj.push(`bil_av${vIds[0]}_${i}`);2925 }2926 } else if (t === 1) {2927 for (let i of vIds) {2928 obj.push(`you_${i}`);2929 }2930 } else if (t === 10) {2931 for (let i of vIds) {2932 obj.push(`yuk_${i}`);2933 }2934 } else if (t === 3) {2935 //open2936 for (let i of vIds) {2937 obj.push(`ope_${i}`);2938 }2939 } else if (t === 12) {2940 //up2stream2941 for (let i of vIds) {2942 obj.push(`up2_${i}`);2943 }2944 } else if (t === 19) {2945 //æå¥è2946 for (let i of vIds) {2947 obj.push(`iqi_${i}`);2948 }2949 } else if (t === 6) {2950 //line tv2951 for (let i of vIds) {2952 obj.push(`lin_${i}`);2953 }2954 } else {2955 for (let i of vIds) {2956 obj.push(`dym_${i}`);2957 }2958 }2959 }2960 }2961 }2962 const div1 = findTag(findTag(vs, 'p')[0], 'div', 'video_div')[0];2963 getV(div1 ? div1 : findTag(vs, 'div', 'video_div')[0]);2964 getV(findTag(vs, 'div', 'video_div_s2')[0], '_s2');2965 getV(findTag(vs, 'div', 'video_div_s3')[0], '_s3');2966 if (!obj) {2967 return handleError(new HoError('no source'));2968 }2969 if (sub_index > obj.length) {2970 sub_index = 1;2971 }2972 console.log(obj);2973 saveList(lovetvGetlist, raw_list, is_end, etime);2974 return [Object.assign({2975 id: obj[sub_index-1],2976 index: index,2977 showId: index,2978 }, (obj.length > 1) ? {2979 sub: obj.length,2980 index: (index * 1000 + sub_index) / 1000,2981 showId: (index * 1000 + sub_index) / 1000,2982 } : {}), is_end, raw_list.length];2983 });*/2984 };2985 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : lovetvGetlist().then(function (_ref5) {2986 var _ref6 = (0, _slicedToArray3.default)(_ref5, 2),2987 raw_list = _ref6[0],2988 is_end = _ref6[1];2989 return sendList(raw_list, is_end, -1);2990 });2991 })2992 };2993 case 'eztv':2994 var eztvGetlist = function eztvGetlist() {2995 var getEzList = function getEzList(tr) {2996 var list = [];2997 tr.reverse().forEach(function (tr) {2998 var td = (0, _utility.findTag)(tr, 'td', 'forum_thread_post');2999 var a = (0, _utility.findTag)(td[2], 'a', 'magnet')[0];3000 if (a) {3001 var episodeMatch = a.attribs.title.match(/ S?(\d+)[XE](\d+) /i);3002 if (episodeMatch) {3003 var season = episodeMatch[1].length === 1 ? '00' + episodeMatch[1] : episodeMatch[1].length === 2 ? '0' + episodeMatch[1] : episodeMatch[1];3004 season = episodeMatch[2].length === 1 ? season + '00' + episodeMatch[2] : episodeMatch[2].length === 2 ? season + '0' + episodeMatch[2] : '' + season + episodeMatch[2];3005 var sizeMatch = (0, _utility.findTag)(td[3])[0].match(/^(\d+\.?\d+?) ([MG])/);3006 var size = sizeMatch[2] === 'G' ? Number(sizeMatch[1]) * 1000 : Number(sizeMatch[1]);3007 var data = {3008 magnet: a.attribs.href,3009 name: (0, _utility.findTag)((0, _utility.findTag)(td[1], 'a')[0])[0],3010 season: season,3011 size: size3012 };3013 var si = -1;3014 for (var _i2 in list) {3015 if (list[_i2][0]['season'] === season) {3016 si = _i2;3017 break;3018 }3019 }3020 if (si === -1) {3021 list.push([data]);3022 } else {3023 var isInsert = false;3024 for (var _i3 in list[si]) {3025 if (list[si][_i3].size > size) {3026 list[si].splice(_i3, 0, data);3027 isInsert = true;3028 break;3029 }3030 }3031 if (!isInsert) {3032 list[si].push(data);3033 }3034 }3035 }3036 }3037 });3038 return list;3039 };3040 if (url.match(/^https:\/\/eztv\.ag\/search\//)) {3041 console.log('start more');3042 return (0, _apiTool2.default)('url', url, { referer: 'https://eztv.ag/' }).then(function (raw_data) {3043 return [getEzList((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'header_holder')[0], 'table', 'forum_header_border')[2], 'tr', 'forum_header_border')), false];3044 });3045 } else {3046 return (0, _apiTool2.default)('url', url, { referer: 'https://eztv.ag/' }).then(function (raw_data) {3047 var center = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'header_holder')[0], 'div')[6], 'table', 'forum_header_border_normal')[0], 'tr')[1], 'td')[0], 'center')[0];3048 var tr = (0, _utility.findTag)((0, _utility.findTag)(center, 'table', 'forum_header_noborder')[0], 'tr', 'forum_header_border');3049 var trLength = tr.length;3050 console.log(trLength);3051 var is_end = false;3052 var _iteratorNormalCompletion26 = true;3053 var _didIteratorError26 = false;3054 var _iteratorError26 = undefined;3055 try {3056 for (var _iterator26 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(center, 'table')[0], 'tr')[4], 'td')[0], 'b')), _step26; !(_iteratorNormalCompletion26 = (_step26 = _iterator26.next()).done); _iteratorNormalCompletion26 = true) {3057 var _i4 = _step26.value;3058 if ((0, _utility.findTag)(_i4)[0] === 'Ended') {3059 is_end = true;3060 break;3061 }3062 }3063 } catch (err) {3064 _didIteratorError26 = true;3065 _iteratorError26 = err;3066 } finally {3067 try {3068 if (!_iteratorNormalCompletion26 && _iterator26.return) {3069 _iterator26.return();3070 }3071 } finally {3072 if (_didIteratorError26) {3073 throw _iteratorError26;3074 }3075 }3076 }3077 if (trLength < 100) {3078 return [getEzList(tr), is_end];3079 } else {3080 console.log('too much');3081 var show_name = url.match(/^https:\/\/[^\/]+\/shows\/\d+\/([^\/]+)/);3082 if (!show_name) {3083 return (0, _utility.handleError)(new _utility.HoError('unknown name!!!'));3084 }3085 return (0, _apiTool2.default)('url', 'https://eztv.ag/search/' + show_name[1], { referer: 'https://eztv.ag/' }).then(function (raw_data) {3086 var tr1 = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'header_holder')[0], 'table', 'forum_header_border')[2], 'tr', 'forum_header_border');3087 var trLength1 = tr1.length;3088 console.log(trLength1);3089 if (trLength1 > trLength) {3090 tr = tr1;3091 }3092 return [getEzList(tr), is_end];3093 });3094 }3095 });3096 }3097 };3098 return {3099 v: (0, _redisTool2.default)('hgetall', 'url: ' + encodeURIComponent(url)).then(function (item) {3100 var sendList = function sendList(raw_list, is_end, etime) {3101 var choose = raw_list[index - 1].slice();3102 if (!choose) {3103 return (0, _utility.handleError)(new _utility.HoError('cannot find external index'));3104 }3105 var chooseMag = choose.splice(choose.length - 1, 1)[0];3106 var ret_obj = {3107 index: index,3108 showId: index,3109 is_magnet: true,3110 complete: false3111 };3112 var final_check = function final_check() {3113 if (!(0, _utility.isValidString)(chooseMag.magnet, 'url')) {3114 return (0, _utility.handleError)(new _utility.HoError('magnet is not vaild'));3115 }3116 return (0, _mongoTool2.default)('find', _constants.STORAGEDB, { magnet: {3117 $regex: chooseMag.magnet.match(/^magnet:[^&]+/)[0].match(/[^:]+$/)[0],3118 $options: 'i'3119 } }, { limit: 1 }).then(function (items) {3120 return [(0, _assign2.default)(ret_obj, { title: chooseMag.name }, items.length > 0 ? { id: items[0]._id } : { magnet: chooseMag.magnet }), is_end, raw_list.length];3121 });3122 };3123 var recur_check = function recur_check(mIndex) {3124 return (0, _mongoTool2.default)('find', _constants.STORAGEDB, { magnet: {3125 $regex: choose[mIndex].magnet.match(/^magnet:[^&]+/)[0].match(/[^:]+$/)[0],3126 $options: 'i'3127 } }, { limit: 1 }).then(function (items) {3128 if (items.length > 0) {3129 return [(0, _assign2.default)(ret_obj, {3130 id: items[0]._id,3131 title: choose[mIndex].name3132 }), is_end, raw_list.length];3133 } else {3134 mIndex++;3135 return mIndex < choose.length ? recur_check(mIndex) : final_check();3136 }3137 });3138 };3139 saveList(eztvGetlist, raw_list, is_end, etime);3140 return choose.length > 0 ? recur_check(0) : final_check();3141 };3142 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : eztvGetlist().then(function (_ref7) {3143 var _ref8 = (0, _slicedToArray3.default)(_ref7, 2),3144 raw_list = _ref8[0],3145 is_end = _ref8[1];3146 return sendList(raw_list, is_end, -1);3147 });3148 })3149 };3150 case 'yify':3151 var yifyGetlist = function yifyGetlist() {3152 return (0, _apiTool2.default)('url', url, { referer: 'https://yts.ag/' }).then(function (raw_data) {3153 var json_data = (0, _utility.getJson)(raw_data);3154 if (json_data === false) {3155 return (0, _utility.handleError)(new _utility.HoError('json parse error!!!'));3156 }3157 if (json_data['status'] !== 'ok' || !json_data['data']['movie']) {3158 return (0, _utility.handleError)(new _utility.HoError('yify api fail'));3159 }3160 var magnet = null;3161 var _iteratorNormalCompletion27 = true;3162 var _didIteratorError27 = false;3163 var _iteratorError27 = undefined;3164 try {3165 for (var _iterator27 = (0, _getIterator3.default)(json_data['data']['movie']['torrents']), _step27; !(_iteratorNormalCompletion27 = (_step27 = _iterator27.next()).done); _iteratorNormalCompletion27 = true) {3166 var _i5 = _step27.value;3167 if (_i5['quality'] === '1080p' || !magnet && _i5['quality'] === '720p') {3168 magnet = 'magnet:?xt=urn:btih:' + _i5['hash'] + '&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969';3169 }3170 }3171 } catch (err) {3172 _didIteratorError27 = true;3173 _iteratorError27 = err;3174 } finally {3175 try {3176 if (!_iteratorNormalCompletion27 && _iterator27.return) {3177 _iterator27.return();3178 }3179 } finally {3180 if (_didIteratorError27) {3181 throw _iteratorError27;3182 }3183 }3184 }3185 return [[{3186 magnet: magnet,3187 title: json_data['data']['movie']['title']3188 }], false];3189 });3190 };3191 return {3192 v: (0, _redisTool2.default)('hgetall', 'url: ' + encodeURIComponent(url)).then(function (item) {3193 var sendList = function sendList(raw_list, is_end, etime) {3194 if (!(0, _utility.isValidString)(raw_list[0].magnet, 'url')) {3195 return (0, _utility.handleError)(new _utility.HoError('magnet is not vaild'));3196 }3197 saveList(yifyGetlist, raw_list, is_end, etime);3198 return (0, _mongoTool2.default)('find', _constants.STORAGEDB, { magnet: {3199 $regex: raw_list[0].magnet.match(/^magnet:[^&]+/)[0].match(/[^:]+$/)[0],3200 $options: 'i'3201 } }, { limit: 1 }).then(function (items) {3202 return [(0, _assign2.default)({3203 index: 1,3204 showId: 1,3205 title: raw_list[0].title,3206 is_magnet: true,3207 complete: false3208 }, items.length > 0 ? { id: items[0]._id } : { magnet: raw_list[0].magnet }), is_end, raw_list.length];3209 });3210 };3211 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : yifyGetlist().then(function (_ref9) {3212 var _ref10 = (0, _slicedToArray3.default)(_ref9, 2),3213 raw_list = _ref10[0],3214 is_end = _ref10[1];3215 return sendList(raw_list, is_end, -1);3216 });3217 })3218 };3219 case 'bilibili':3220 var bilibiliGetlist = function bilibiliGetlist() {3221 var bili_id = url.match(/(av)?\d+/);3222 if (!bili_id) {3223 return (0, _utility.handleError)(new _utility.HoError('bilibili id invalid'));3224 }3225 var getBangumi = function getBangumi(sId) {3226 return (0, _apiTool2.default)('url', 'http://bangumi.bilibili.com/jsonp/seasoninfo/' + sId + '.ver?callback=seasonListCallback&jsonp=jsonp&_=' + new Date().getTime(), { referer: url }).then(function (raw_data) {3227 var json_data = (0, _utility.getJson)(raw_data.match(/^[^\(]+\((.*)\);$/)[1]);3228 if (json_data === false) {3229 return (0, _utility.handleError)(new _utility.HoError('json parse error!!!'));3230 }3231 if (!json_data.result || !json_data.result.episodes) {3232 return (0, _utility.handleError)(new _utility.HoError('cannot get episodes'));3233 }3234 return [json_data.result.episodes.map(function (e) {3235 return {3236 id: 'bil_av' + e.av_id + '_' + e.page,3237 name: e.index_title3238 };3239 }).reverse(), json_data.result.seasons];3240 });3241 };3242 return bili_id[1] ? (0, _apiTool2.default)('url', url, { referer: 'http://www.bilibili.com/' }).then(function (raw_data) {3243 var select = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'b-page-body')[0], 'div', 'player-wrapper')[0], 'div', 'main-inner')[0], 'div', 'v-plist')[0], 'div', 'plist')[0], 'select');3244 return select.length > 0 ? [(0, _utility.findTag)(select[0], 'option').map(function (o) {3245 return {3246 id: 'bil_' + bili_id[0] + '_' + o.attribs.value.match(/index_(\d+)\.html/)[1],3247 name: (0, _utility.findTag)(o)[0]3248 };3249 }), false] : [[{3250 id: 'bil_' + bili_id[0],3251 name: 'bil'3252 }], false];3253 }) : getBangumi(bili_id[0]).then(function (_ref11) {3254 var _ref12 = (0, _slicedToArray3.default)(_ref11, 2),3255 list = _ref12[0],3256 seasons = _ref12[1];3257 var recur_season = function recur_season(index) {3258 return getBangumi(seasons[index].season_id).then(function (_ref13) {3259 var _ref14 = (0, _slicedToArray3.default)(_ref13, 2),3260 slist = _ref14[0],3261 sseasons = _ref14[1];3262 list = list.concat(slist);3263 index++;3264 return index < seasons.length ? recur_season(index) : [list, false];3265 });3266 };3267 return seasons.length > 0 ? recur_season(0) : [list, false];3268 });3269 };3270 return {3271 v: (0, _redisTool2.default)('hgetall', 'url: ' + encodeURIComponent(url)).then(function (item) {3272 var sendList = function sendList(raw_list, is_end, etime) {3273 var choose = raw_list[index - 1];3274 if (!choose) {3275 return (0, _utility.handleError)(new _utility.HoError('cannot find external index'));3276 }3277 saveList(bilibiliGetlist, raw_list, is_end, etime);3278 return [{3279 index: index,3280 showId: index,3281 id: choose.id,3282 title: choose.name3283 }, is_end, raw_list.length];3284 };3285 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : bilibiliGetlist().then(function (_ref15) {3286 var _ref16 = (0, _slicedToArray3.default)(_ref15, 2),3287 raw_list = _ref16[0],3288 is_end = _ref16[1];3289 return sendList(raw_list, is_end, -1);3290 });3291 })3292 };3293 case 'kubo':3294 var kuboGetlist = function kuboGetlist() {3295 return (0, _apiTool2.default)('url', url).then(function (raw_data) {3296 var list = [];3297 var is_end = false;3298 var main = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'main')[0];3299 var _iteratorNormalCompletion28 = true;3300 var _didIteratorError28 = false;3301 var _iteratorError28 = undefined;3302 try {3303 for (var _iterator28 = (0, _getIterator3.default)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(main, 'div', 'datal')[0], 'div', 'vmain')[0], 'div', 'vshow')[0], 'p')), _step28; !(_iteratorNormalCompletion28 = (_step28 = _iterator28.next()).done); _iteratorNormalCompletion28 = true) {3304 var p = _step28.value;3305 var _iteratorNormalCompletion30 = true;3306 var _didIteratorError30 = false;3307 var _iteratorError30 = undefined;3308 try {3309 for (var _iterator30 = (0, _getIterator3.default)((0, _utility.findTag)(p)), _step30; !(_iteratorNormalCompletion30 = (_step30 = _iterator30.next()).done); _iteratorNormalCompletion30 = true) {3310 var pt = _step30.value;3311 if (pt.match(/å®çµ/)) {3312 is_end = true;3313 break;3314 }3315 }3316 } catch (err) {3317 _didIteratorError30 = true;3318 _iteratorError30 = err;3319 } finally {3320 try {3321 if (!_iteratorNormalCompletion30 && _iterator30.return) {3322 _iterator30.return();3323 }3324 } finally {3325 if (_didIteratorError30) {3326 throw _iteratorError30;3327 }3328 }3329 }3330 if (is_end) {3331 break;3332 }3333 }3334 } catch (err) {3335 _didIteratorError28 = true;3336 _iteratorError28 = err;3337 } finally {3338 try {3339 if (!_iteratorNormalCompletion28 && _iterator28.return) {3340 _iterator28.return();3341 }3342 } finally {3343 if (_didIteratorError28) {3344 throw _iteratorError28;3345 }3346 }3347 }3348 var flvUrl = null;3349 var listY = [];3350 (0, _utility.findTag)((0, _utility.findTag)(main, 'div', 'topRow')[0], 'div', 'hideCont').forEach(function (h) {3351 var ul = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(h, 'ul')[0], 'div', 'vmain')[0], 'div', 'vpl')[0], 'ul')[0];3352 var div = (0, _utility.findTag)(ul, 'div')[0];3353 if (div) {3354 ul = div;3355 }3356 var _iteratorNormalCompletion29 = true;3357 var _didIteratorError29 = false;3358 var _iteratorError29 = undefined;3359 try {3360 for (var _iterator29 = (0, _getIterator3.default)((0, _utility.findTag)(ul, 'li')), _step29; !(_iteratorNormalCompletion29 = (_step29 = _iterator29.next()).done); _iteratorNormalCompletion29 = true) {3361 var l = _step29.value;3362 var a = (0, _utility.findTag)(l, 'a')[0];3363 list.push({3364 name: opencc.convertSync((0, _utility.findTag)(a)[0]),3365 id: 'kur_' + new Buffer(a.attribs.href).toString('base64') + '}'3366 });3367 /*const a = findTag(l, 'a')[0];3368 let urlMatch = addPre(a.attribs.href, 'http://www.99kubo.tv').match(/youtube\.php\?(.*)$/);3369 if (urlMatch) {3370 listY.push({3371 name: findTag(a)[0],3372 id: `kdy_${urlMatch[1]}`,3373 });3374 } else {3375 if (a.attribs.href.match(/vod\-play\-id\-/)) {3376 flvUrl = addPre(a.attribs.href, 'http://www.99kubo.tv');3377 break;3378 }3379 }*/3380 }3381 } catch (err) {3382 _didIteratorError29 = true;3383 _iteratorError29 = err;3384 } finally {3385 try {3386 if (!_iteratorNormalCompletion29 && _iterator29.return) {3387 _iterator29.return();3388 }3389 } finally {3390 if (_didIteratorError29) {3391 throw _iteratorError29;3392 }3393 }3394 }3395 });3396 return [list, is_end];3397 /*return flvUrl ? Api('url', flvUrl).then(raw_data => {3398 let ff_urls = '';3399 const jM = findTag(findTag(findTag(findTag(findTag(findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'playmar')[0], 'div', 'play')[0], 'div')[0], 'script')[0])[0].match(/^\s*var\s*ff_urls\s*=\s*['"](.*)['"];?\s*$/);3400 if (jM) {3401 ff_urls = getJson(jM[1].replace(/\\\"/g, '"'));3402 }3403 let list1 = [];3404 let list2 = [];3405 let lists = [];3406 let listO = [];3407 ff_urls.Data.forEach(f => {3408 if (f.playname === 'bj58') {3409 list = f.playurls.map(p => ({3410 name: p[0],3411 id: `kur_${new Buffer(p[2]).toString('base64')}`,3412 }));3413 } else if (f.playname === 'bj') {3414 list1 = f.playurls.map(p => ({3415 name: p[0],3416 id: `kyu_${p[1].match(/^(.*)_wd1$/)[1]}`,3417 }));3418 } else if (f.playname === 'bj2') {3419 list2 = f.playurls.map(p => ({3420 name: p[0],3421 id: `kur_${new Buffer(p[2]).toString('base64')}`,3422 }));3423 } else if (f.playname.match(/^bj/)) {3424 lists = f.playurls.map(p => ({3425 name: p[0],3426 id: `kur_${new Buffer(p[2]).toString('base64')}`,3427 }));3428 } else {3429 listO = f.playurls.map(p => ({3430 name: p[0],3431 id: `kur_${new Buffer(p[2]).toString('base64')}`,3432 }));3433 }3434 });3435 list = list.concat(listY);3436 list = list.concat(list1);3437 list = list.concat(list2);3438 list = list.concat(lists);3439 list = list.concat(listO);3440 return [list, is_end];3441 }) : [listY, is_end];*/3442 });3443 };3444 return {3445 v: (0, _redisTool2.default)('hgetall', 'url: ' + encodeURIComponent(url)).then(function (item) {3446 var sendList = function sendList(raw_list, is_end, etime) {3447 var choose = raw_list[index - 1];3448 if (!choose) {3449 return (0, _utility.handleError)(new _utility.HoError('cannot find external index'));3450 }3451 saveList(kuboGetlist, raw_list, is_end, etime);3452 return [(0, _assign2.default)({3453 index: index,3454 showId: index,3455 id: choose.id,3456 title: choose.name3457 }, choose.id.match(/^(kdy|kyu)_/) ? {3458 index: (index * 1000 + sub_index) / 1000,3459 showId: (index * 1000 + sub_index) / 1000,3460 id: choose.id + '_' + sub_index3461 } : {}), is_end, raw_list.length];3462 };3463 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : kuboGetlist().then(function (_ref17) {3464 var _ref18 = (0, _slicedToArray3.default)(_ref17, 2),3465 raw_list = _ref18[0],3466 is_end = _ref18[1];3467 return sendList(raw_list, is_end, -1);3468 });3469 })3470 };3471 /*const kuboGetlist = () => Api('url', url).then(raw_data => {3472 let list = [];3473 const container = findTag(findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'container ff-bg')[1];3474 const is_end = findTag(findTag(findTag(findTag(findTag(findTag(findTag(container, 'div', 'row')[0], 'div', 'col-md-8 col-xs-12')[0], 'div', 'media')[0], 'div', 'media-body')[0], 'h4')[0], 'small', 'text-red')[0])[0].includes('å
¨') ? true : false;3475 findTag(findTag(container, 'div', 'tab-content ff-playurl-tab')[0], 'ul').forEach(u => findTag(u, 'li').forEach(l => {3476 const a = findTag(l, 'a')[0];3477 list.push({3478 name: findTag(a)[0],3479 id: `kur_${new Buffer(a.attribs.href).toString('base64')}}`,3480 });3481 }));3482 return [list, is_end];3483 });3484 return Redis('hgetall', `url: ${encodeURIComponent(url)}`).then(item => {3485 const sendList = (raw_list, is_end, etime) => {3486 const choose = raw_list[index - 1];3487 if (!choose) {3488 return handleError(new HoError('cannot find external index'));3489 }3490 saveList(kuboGetlist, raw_list, is_end, etime);3491 return [Object.assign({3492 index,3493 showId: index,3494 id: choose.id,3495 title: choose.name,3496 }, choose.id.match(/^(kdy|kyu)_/) ? {3497 index: (index * 1000 + sub_index) / 1000,3498 showId: (index * 1000 + sub_index) / 1000,3499 id: `${choose.id}_${sub_index}`,3500 } : {}), is_end, raw_list.length];3501 };3502 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : kuboGetlist().then(([raw_list, is_end]) => sendList(raw_list, is_end, -1));3503 });*/3504 case 'dm5':3505 var madGetlist = function madGetlist() {3506 return (0, _apiTool2.default)('url', url, {3507 referer: 'http://www.dm5.com/',3508 cookie: 'SERVERID=node1; isAdult=1; frombot=1',3509 is_dm5: true3510 }).then(function (raw_data) {3511 var list = [];3512 var body = (0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0];3513 var divs = (0, _utility.findTag)(body, 'div');3514 var is_end = false;3515 var _iteratorNormalCompletion31 = true;3516 var _didIteratorError31 = false;3517 var _iteratorError31 = undefined;3518 try {3519 for (var _iterator31 = (0, _getIterator3.default)(divs), _step31; !(_iteratorNormalCompletion31 = (_step31 = _iterator31.next()).done); _iteratorNormalCompletion31 = true) {3520 var d = _step31.value;3521 if ((0, _utility.findTag)(d, 'section', 'banner_detail').length > 0) {3522 if ((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(d, 'section', 'banner_detail')[0], 'div', 'banner_detail_form')[0], 'div', 'info')[0], 'p', 'tip')[0], 'span', 'block')[0], 'span')[0])[0] === 'å·²å®ç»') {3523 is_end = true;3524 }3525 break;3526 }3527 }3528 } catch (err) {3529 _didIteratorError31 = true;3530 _iteratorError31 = err;3531 } finally {3532 try {3533 if (!_iteratorNormalCompletion31 && _iterator31.return) {3534 _iterator31.return();3535 }3536 } finally {3537 if (_didIteratorError31) {3538 throw _iteratorError31;3539 }3540 }3541 }3542 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(body, 'div', 'view-comment')[0], 'div', 'container')[0], 'div', 'left-bar')[0], 'div', 'tempc')[0], 'div', 'chapterlistload')[0], 'ul').forEach(function (u) {3543 var li = (0, _utility.findTag)(u, 'li');3544 var more = (0, _utility.findTag)(u, 'ul');3545 if (more.length > 0) {3546 li = li.concat((0, _utility.findTag)(more[0], 'li'));3547 }3548 li.reverse().forEach(function (l) {3549 var a = (0, _utility.findTag)(l, 'a')[0];3550 var title = (0, _utility.findTag)(a)[0];3551 if (!title) {3552 title = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(a, 'div', 'info')[0], 'p', 'title ')[0])[0];3553 }3554 list.push({3555 title: opencc.convertSync(title),3556 url: (0, _utility.addPre)(a.attribs.href, 'http://www.dm5.com')3557 });3558 });3559 });3560 return [list, is_end];3561 });3562 };3563 return {3564 v: (0, _redisTool2.default)('hgetall', 'url: ' + encodeURIComponent(url)).then(function (item) {3565 var sendList = function sendList(raw_list, is_end, etime) {3566 var choose = raw_list[index - 1];3567 if (!choose) {3568 index = 1;3569 choose = raw_list[index - 1];3570 if (!choose) {3571 return (0, _utility.handleError)(new _utility.HoError('cannot find external index'));3572 }3573 }3574 saveList(madGetlist, raw_list, is_end, etime);3575 return [{3576 index: (index * 1000 + sub_index) / 1000,3577 showId: (index * 1000 + sub_index) / 1000,3578 title: choose.title,3579 pre_url: choose.url3580 }, is_end, raw_list.length];3581 };3582 return item ? sendList(JSON.parse(item.raw_list), item.is_end === 'false' ? false : item.is_end, item.etime) : madGetlist().then(function (_ref19) {3583 var _ref20 = (0, _slicedToArray3.default)(_ref19, 2),3584 raw_list = _ref20[0],3585 is_end = _ref20[1];3586 return sendList(raw_list, is_end, -1);3587 });3588 })3589 };3590 default:3591 return {3592 v: (0, _utility.handleError)(new _utility.HoError('unknown external type'))3593 };3594 }3595 }();3596 if ((typeof _ret14 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret14)) === "object") return _ret14.v;3597 },3598 saveSingle: function saveSingle(type, id) {3599 var url = null;3600 switch (type) {3601 case 'yify':3602 var getMid = function getMid() {3603 return isNaN(id) ? (0, _apiTool2.default)('url', 'https://yts.ag/movie/' + id, { referer: 'https://yts.ag/' }).then(function (raw_data) {3604 return (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'main-content')[0], 'div', 'movie-content')[0], 'div', 'row')[0], 'div', 'movie-info')[0].attribs['data-movie-id'];3605 }) : _promise2.default.resolve(id);3606 };3607 return getMid().then(function (mid) {3608 url = 'https://yts.ag/api/v2/movie_details.json?with_cast=true&movie_id=' + mid;3609 return (0, _apiTool2.default)('url', url, { referer: 'https://yts.ag/' }).then(function (raw_data) {3610 var json_data = (0, _utility.getJson)(raw_data);3611 if (json_data === false) {3612 return (0, _utility.handleError)(new _utility.HoError('json parse error!!!'));3613 }3614 if (json_data['status'] !== 'ok' || !json_data['data']['movie']) {3615 return (0, _utility.handleError)(new _utility.HoError('yify api fail'));3616 }3617 var setTag = new _set2.default(['yify', 'video', 'å½±ç', 'movie', 'é»å½±']);3618 setTag.add(json_data['data']['movie']['imdb_code']).add(json_data['data']['movie']['year'].toString());3619 if (json_data['data']['movie']['genres']) {3620 json_data['data']['movie']['genres'].forEach(function (i) {3621 return setTag.add(i);3622 });3623 }3624 if (json_data['data']['movie']['cast']) {3625 json_data['data']['movie']['cast'].forEach(function (i) {3626 return setTag.add(i.name);3627 });3628 }3629 var newTag = new _set2.default();3630 setTag.forEach(function (i) {3631 return newTag.add(_constants.GENRE_LIST.includes(i) ? _constants.GENRE_LIST_CH[_constants.GENRE_LIST.indexOf(i)] : i);3632 });3633 return [json_data['data']['movie']['title'], newTag, new _set2.default(), 'yify', json_data['data']['movie']['small_cover_image'], url];3634 });3635 });3636 case 'kubo':3637 /*url = `http://www.99kubo.tv/vod-read-id-${id}.html`3638 return Api('url', url, {referer: 'http://www.99kubo.tv/'}).then(raw_data => {3639 const media = findTag(findTag(findTag(findTag(findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'container ff-bg')[1], 'div', 'row')[0], 'div', 'col-md-8 col-xs-12')[0], 'div', 'media')[0]3640 const img = findTag(findTag(findTag(media, 'div', 'media-left')[0], 'a')[0], 'img')[0];3641 const mediaBody = findTag(media, 'div', 'media-body')[0];3642 const name = findTag(findTag(findTag(mediaBody, 'h4')[0], 'a')[0])[0];3643 let tags = new Set(['kubo', 'é
·æ', 'å½±ç', 'video']);3644 findTag(findTag(mediaBody, 'dl')[0], 'dd').forEach(d => findTag(d, 'a').forEach(a => {3645 const tag = findTag(a)[0];3646 if (tag && !tag.includes('å®æ´æ¼å¡è¡¨') && !tag.includes('æªç¥')) {3647 tags.add(tag);3648 console.log(tag);3649 for (let i in KUBO_TYPE) {3650 const index = KUBO_TYPE[i].indexOf(tag);3651 if (index !== -1) {3652 if (i === '0') {3653 tags.add('movie').add('é»å½±');3654 switch (index) {3655 case 0:3656 tags.add('action').add('åä½');3657 break;3658 case 1:3659 tags.add('comedy').add('åå');3660 break;3661 case 2:3662 tags.add('romance').add('浪漫');3663 break;3664 case 3:3665 tags.add('sci-fi').add('ç§å¹»');3666 break;3667 case 4:3668 tags.add('horror').add('ææ');3669 break;3670 case 5:3671 tags.add('drama').add('åæ
');3672 break;3673 case 6:3674 tags.add('war').add('æ°ç');3675 break;3676 case 7:3677 tags.add('animation').add('åç«');3678 break;3679 }3680 } else if (i === '1') {3681 tags.add('tv show').add('é»è¦å');3682 } else if (i === '2') {3683 tags.add('tv show').add('é»è¦å').add('ç¶èç¯ç®');3684 } else if (i === '3') {3685 tags.add('animation').add('åç«');3686 }3687 break;3688 }3689 }3690 }3691 }));3692 let newTag = new Set();3693 tags.forEach(t => {3694 const index = DM5_ORI_LIST.indexOf(t);3695 newTag.add((index !== -1) ? DM5_CH_LIST[index] : t);3696 });3697 return [3698 name,3699 newTag,3700 new Set(),3701 'kubo',3702 img.attribs['data-original'],3703 url,3704 ];3705 });*/3706 url = 'http://www.99kubo.tv/vod-read-id-' + id + '.html';3707 return (0, _apiTool2.default)('url', url, { referer: 'http://www.99kubo.tv/' }).then(function (raw_data) {3708 var vmain = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'main')[0], 'div', 'datal')[0], 'div', 'vmain')[0];3709 var img = (0, _utility.findTag)((0, _utility.findTag)(vmain, 'div', 'vpic')[0], 'img')[0];3710 var name = img.attribs.alt;3711 var thumb = img.attribs.src;3712 var tags = new _set2.default(['kubo', 'é
·æ', 'å½±ç', 'video']);3713 (0, _utility.findTag)((0, _utility.findTag)(vmain, 'div', 'vshow')[0], 'p').forEach(function (p) {3714 var t = (0, _utility.findTag)(p)[0];3715 if (t) {3716 var match = (0, _utility.findTag)(p)[0].match(/^å¥å:(.*)$/);3717 if (match) {3718 match[1].split('/').forEach(function (m) {3719 if (m) {3720 tags.add(m);3721 }3722 });3723 } else {3724 if (t === 'é¡åï¼') {3725 (0, _utility.findTag)(p, 'a').forEach(function (a) {3726 if (a) {3727 tags.add((0, _utility.findTag)(a)[0]);3728 }3729 });3730 } else if (t === 'åé¡ï¼') {3731 (0, _utility.findTag)(p, 'font').forEach(function (a) {3732 if (a) {3733 tags.add((0, _utility.findTag)(a)[0]);3734 }3735 });3736 var _type = (0, _utility.findTag)((0, _utility.findTag)(p, 'a')[0])[0];3737 if (_type) {3738 tags.add(_type);3739 for (var _i6 in _constants.KUBO_TYPE) {3740 var index = _constants.KUBO_TYPE[_i6].indexOf(_type);3741 if (index !== -1) {3742 if (_i6 === '0') {3743 tags.add('movie').add('é»å½±');3744 switch (index) {3745 case 0:3746 tags.add('action').add('åä½');3747 break;3748 case 1:3749 tags.add('comedy').add('åå');3750 break;3751 case 2:3752 tags.add('romance').add('浪漫');3753 break;3754 case 3:3755 tags.add('sci-fi').add('ç§å¹»');3756 break;3757 case 4:3758 tags.add('horror').add('ææ');3759 break;3760 case 5:3761 tags.add('drama').add('åæ
');3762 break;3763 case 6:3764 tags.add('war').add('æ°ç');3765 break;3766 case 7:3767 tags.add('animation').add('åç«');3768 break;3769 }3770 } else if (_i6 === '1') {3771 tags.add('tv show').add('é»è¦å');3772 } else if (_i6 === '2') {3773 tags.add('tv show').add('é»è¦å').add('ç¶èç¯ç®');3774 } else if (_i6 === '3') {3775 tags.add('animation').add('åç«');3776 }3777 break;3778 }3779 }3780 }3781 }3782 }3783 }3784 });3785 var newTag = new _set2.default();3786 tags.forEach(function (t) {3787 t = opencc.convertSync(t);3788 var index = _constants.DM5_ORI_LIST.indexOf(t);3789 newTag.add(index !== -1 ? _constants.DM5_CH_LIST[index] : t);3790 });3791 return [opencc.convertSync(img.attribs.alt), newTag, new _set2.default(), 'kubo', img.attribs.src, url];3792 });3793 case 'dm5':3794 url = 'http://www.dm5.com/' + id + '/';3795 return (0, _apiTool2.default)('url', url, { is_dm5: true }).then(function (raw_data) {3796 var divs = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div');3797 var info = null;3798 for (var _i7 = 0; _i7 < divs.length; _i7++) {3799 if (divs[_i7].attribs.class === '') {3800 info = (0, _utility.findTag)((0, _utility.findTag)(divs[_i7], 'section', 'banner_detail')[0], 'div', 'banner_detail_form')[0];3801 break;3802 }3803 }3804 if (!info) {3805 return (0, _utility.handleError)(new _utility.HoError('dm5 misses info'));3806 }3807 var setTag = new _set2.default(['dm5', '漫ç«', 'comic', 'åçé', 'image book', 'åç', 'image']);3808 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(info, 'div', 'info')[0], 'p', 'subtitle')[0], 'a').forEach(function (a) {3809 return setTag.add(opencc.convertSync((0, _utility.findTag)(a)[0]));3810 });3811 var block = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(info, 'div', 'info')[0], 'p', 'tip')[0], 'span', 'block')[1];3812 if (block) {3813 (0, _utility.findTag)(block, 'a').forEach(function (a) {3814 return setTag.add(opencc.convertSync((0, _utility.findTag)((0, _utility.findTag)(a, 'span')[0])[0]));3815 });3816 }3817 var newTag = new _set2.default();3818 setTag.forEach(function (i) {3819 return newTag.add(_constants.DM5_ORI_LIST.includes(i) ? _constants.DM5_CH_LIST[_constants.DM5_ORI_LIST.indexOf(i)] : i);3820 });3821 return [opencc.convertSync((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(info, 'div', 'info')[0], 'p', 'title')[0])[0]), newTag, new _set2.default(), 'dm5', (0, _utility.findTag)((0, _utility.findTag)(info, 'div', 'cover')[0], 'img')[0].attribs.src, url];3822 });3823 case 'bilibili':3824 url = id.match(/^av/) ? 'http://www.bilibili.com/video/' + id + '/' : 'http://bangumi.bilibili.com/anime/' + id + '/';3825 return (0, _apiTool2.default)('url', url, {3826 referer: 'http://www.bilibili.com/',3827 not_utf8: true3828 }).then(function (raw_data) {3829 var name = '';3830 var thumb = '';3831 var body = (0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0];3832 var wrapper = (0, _utility.findTag)(body, 'div', 'main-container-wrapper');3833 var setTag = new _set2.default(['bilibili', 'å½±ç', 'video']);3834 if (wrapper.length > 0) {3835 setTag.add('åç«').add('animation');3836 var info = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(wrapper[0], 'div', 'main-container')[0], 'div', 'page-info-wrp')[0], 'div', 'bangumi-info-wrapper')[0], 'div', 'main-inner')[0], 'div', 'info-content')[0];3837 var img = (0, _utility.findTag)((0, _utility.findTag)(info, 'div', 'bangumi-preview')[0], 'img')[0];3838 name = img.attribs.alt;3839 thumb = img.attribs.src;3840 var infoR = (0, _utility.findTag)(info, 'div', 'bangumi-info-r')[0];3841 setTag.add((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(infoR, 'div', 'info-row info-update')[0], 'em')[0], 'span')[0])[0].match(/^\d+/)[0]);3842 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(infoR, 'div', 'info-row info-cv')[0], 'em')[0], 'span').forEach(function (s) {3843 return setTag.add(opencc.convertSync((0, _utility.findTag)(s)[0]));3844 });3845 (0, _utility.findTag)((0, _utility.findTag)(infoR, 'div', 'b-head')[0], 'a').forEach(function (a) {3846 return setTag.add(opencc.convertSync((0, _utility.findTag)((0, _utility.findTag)(a, 'span')[0])[0]));3847 });3848 } else {3849 var main = (0, _utility.findTag)((0, _utility.findTag)(body, 'div', 'b-page-body')[0], 'div', 'main-inner');3850 var _info = (0, _utility.findTag)((0, _utility.findTag)(main[0], 'div', 'viewbox')[0], 'div', 'info')[0];3851 (0, _utility.findTag)((0, _utility.findTag)(_info, 'div', 'tminfo')[0], 'span').forEach(function (s) {3852 if ((0, _utility.findTag)((0, _utility.findTag)(s, 'a')[0])[0].match(/å¨ç»$/)) {3853 setTag.add('åç«').add('animation');3854 } else if ((0, _utility.findTag)((0, _utility.findTag)(s, 'a')[0])[0].match(/çµå½±$/)) {3855 setTag.add('é»å½±').add('movie');3856 }3857 });3858 (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(main[1], 'div', 'v_large')[0], 'div', 'v_info')[0], 'div', 's_tag')[0], 'ul')[0], 'li').forEach(function (l) {3859 return setTag.add(opencc.convertSync((0, _utility.findTag)((0, _utility.findTag)(l, 'a')[0])[0]));3860 });3861 name = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_info, 'div', 'v-title')[0], 'h1')[0])[0];3862 thumb = (0, _utility.findTag)(body, 'img')[0].attribs.src;3863 }3864 var newTag = new _set2.default();3865 setTag.forEach(function (i) {3866 return newTag.add(_constants.DM5_ORI_LIST.includes(i) ? _constants.DM5_CH_LIST[_constants.DM5_ORI_LIST.indexOf(i)] : i);3867 });3868 return [name, newTag, new _set2.default(), 'bilibili', thumb, url];3869 });3870 default:3871 return (0, _utility.handleError)(new _utility.HoError('unknown external type'));3872 }3873 }3874};3875var subHdUrl = exports.subHdUrl = function subHdUrl(str) {3876 return (0, _apiTool2.default)('url', 'http://subhd.com/search/' + encodeURIComponent(str)).then(function (raw_data) {3877 var list = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'container list')[0], 'div', 'row')[0], 'div', 'col-md-9')[0];3878 if ((0, _utility.findTag)(list)[0] && (0, _utility.findTag)(list)[0].match(/ææ¶æ²¡æ/)) {3879 return null;3880 }3881 var big_item = (0, _utility.findTag)(list, 'div', 'box')[0];3882 if (!big_item) {3883 console.log(raw_data);3884 return (0, _utility.handleError)(new _utility.HoError('sub data error!!!'));3885 }3886 var sub_id = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(big_item, 'div', 'pull-left lb_r')[0], 'table')[0], 'tr')[0], 'td')[0], 'h4')[0], 'a')[0].attribs.href;3887 return (0, _apiTool2.default)('url', 'http://subhd.com/ajax/down_ajax', {3888 post: { sub_id: sub_id.match(/\d+$/)[0] },3889 is_json: true,3890 referer: 'http://subhd.com' + sub_id3891 }).then(function (data) {3892 console.log(data);3893 return data.success ? data.url : (0, _utility.handleError)(new _utility.HoError('too many times!!!'));3894 });3895 });3896};3897var bilibiliVideoUrl = exports.bilibiliVideoUrl = function bilibiliVideoUrl(url) {3898 console.log(url);3899 var id = url.match(/(av)?(\d+)\/(index_(\d+)\.html)?$/);3900 if (!id) {3901 return (0, _utility.handleError)(new _utility.HoError('bilibili id invalid'));3902 }3903 var page = id[3] ? Number(id[4]) : 1;3904 return (0, _apiTool2.default)('url', 'http://api.bilibili.com/view?type=json&appkey=8e9fc618fbd41e28&id=' + id[2] + '&page=1&batch=true', { referer: 'http://api.bilibili.com/' }).then(function (raw_data) {3905 var json_data = (0, _utility.getJson)(raw_data);3906 if (json_data === false) {3907 return (0, _utility.handleError)(new _utility.HoError('json parse error!!!'));3908 }3909 if (!json_data.list) {3910 return (0, _utility.handleError)(new _utility.HoError('cannot get list'));3911 }3912 return {3913 title: json_data.list[page - 1].part,3914 video: [],3915 embed: ['//static.hdslb.com/miniloader.swf?aid=' + id[2] + '&page=' + page]3916 };3917 });3918};3919var kuboVideoUrl = exports.kuboVideoUrl = function kuboVideoUrl(id, url) {3920 var subIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;3921 console.log(url);3922 if (id === 'kdy') {3923 return (0, _apiTool2.default)('url', url, { referer: 'http://www.58b.tv/' }).then(function (raw_data) {3924 var iframes = (0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)((0, _utility.findTag)(_htmlparser2.default.parseDOM(raw_data), 'html')[0], 'body')[0], 'div', 'container')[0], 'div', 'youtube-player')[0], 'iframe');3925 if (subIndex > iframes.length) {3926 subIndex = iframes.length;3927 }3928 var getUrl = function getUrl(youUrl) {3929 return youUrl.match(/www\.youtube\.com/) ? youtubeVideoUrl('you', 'http://www.youtube.com/watch?v=' + youUrl.match(/embed\/(.*)$/)[1]) : youtubeVideoUrl('dym', 'http://www.dailymotion.com/embed/video/' + youUrl.match(/url\=(.*)$/)[1]);3930 };3931 if (!iframes[subIndex - 1]) {3932 console.log(iframes);3933 return (0, _utility.handleError)(new _utility.HoError('cannot find mp4'));3934 }3935 return getUrl(iframes[subIndex - 1].attribs.src).then(function (ret_obj) {3936 return (0, _assign2.default)(ret_obj, iframes.length > 1 ? { sub: iframes.length } : {});3937 });3938 });3939 } else if (id === 'kud') {3940 return _promise2.default.resolve({3941 video: [],3942 url: [url]3943 });3944 /*return Api('url', url, {referer: 'http://www.58b.tv/'}).then(raw_data => {3945 let ret_obj = {video: []};3946 const script = findTag(findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0], 'script')[0];3947 if (!script) {3948 return handleError(new HoError('cannot find mp4'));3949 }3950 const videoData = findTag(script)[0];3951 if (videoData) {3952 JuicyCodes.Run(videoData.match(/\((.*)\)/)[1].replace(/["\+]/g, ''));3953 kuboInfo.sources.forEach(s => {3954 if (s.type === 'video/mp4') {3955 ret_obj.video.splice(0, 0, s.file);3956 }3957 });3958 if (ret_obj.video.length < 1) {3959 console.log(ret_obj.video);3960 return handleError(new HoError('cannot find mp4'));3961 }3962 return ret_obj;3963 } else {3964 return handleError(new HoError('cannot find videoData'));3965 return Api('url', `http://www.99tw.net/redirect?id=${url.match(/\&kubovid\=(\d+)/)[1]}&pid=${subIndex}`, {referer: 'http://www.58b.tv/'}).then(raw_data => {3966 for (let i of findTag(findTag(findTag(Htmlparser.parseDOM(raw_data), 'html')[0], 'body')[0], 'script')) {3967 const videoData = findTag(i)[0];3968 if (videoData) {3969 const videoMatch = videoData.match(/videoDetail = ([^\]]+\])/);3970 if (videoMatch) {3971 let bps = 0;3972 getJson(videoMatch[1].replace(/'/g, '"').replace(/bps/g, '"bps"').replace(/src/g, '"src"').replace(/type/g, '"type"')).forEach(i => {3973 if (i.bps) {3974 if (parseInt(i.bps) > bps) {3975 bps = parseInt(i.bps);3976 ret_obj.video.splice(0, 0, i.src);3977 } else {3978 ret_obj.video.push(i.src);3979 }3980 }3981 });...
program.spec.js
Source:program.spec.js
...90 rout.addRung(new Rung("XIC(someTag)NOP();"));91 expect(prog).toMatchSnapshot();92 });93 test("findTag: Throws on Invalid Input", () => {94 const fn = name => () => prog.findTag(name);95 expect(fn(new Program("notATag"))).toThrow();96 expect(fn(12)).toThrow();97 expect(fn("aTag")).not.toThrow();98 });99 test("findTag: Finds Target Tag", () => {100 prog.addTag(new Tag("aTag", "DINT"));101 prog.addTag(new Tag("bTag", "SINT"));102 const tag = new Tag("cTag", "BOOL");103 prog.addTag(tag);104 expect(prog.findTag("aTag")).not.toBeNull();105 expect(prog.findTag("aTag")).toMatchSnapshot();106 expect(prog.findTag("bTag")).not.toBeNull();107 expect(prog.findTag("bTag")).toMatchSnapshot();108 expect(prog.findTag("cTag")).not.toBeNull();109 expect(prog.findTag("cTag")).toMatchSnapshot();110 expect(prog.findTag("dTag")).toBeNull();111 prog.findTag("cTag").dom.attributes.Name = "eTag";112 expect(prog).toMatchSnapshot();113 expect(tag).toMatchSnapshot();114 });115 test("findRoutine: Throws on Invalid Input", () => {116 const fn = name => () => prog.findRoutine(name);117 expect(fn(new Program("notATag"))).toThrow();118 expect(fn(12)).toThrow();119 expect(fn("aRoutine")).not.toThrow();120 });121 test("findRoutine: Finds Target Routine", () => {122 prog.addRoutine(new Routine("aRoutine"));123 prog.addRoutine(new Routine("bRoutine"));124 const rout = new Routine("cRoutine");125 prog.addRoutine(rout);...
recipe.controller.js
Source:recipe.controller.js
1const genericCrud = require('./generic.controller')2const boom = require('boom')3const { Recipe, Category, Tag, Ingredients } = require('../model')4module.exports = {5 ...genericCrud(Recipe),6 async postRecipe({ body }, res) {7 try {8 //Ð¼Ð¾Ð´ÐµÐ»Ñ ÑеÑепÑа9 const recipe = new Recipe(body)10 //ÑоÑ
ÑанÑем ÑеÑепÑ11 const newRecipe = await recipe.save()12 //////////Ðобавление в каÑегоÑии////////////////13 //иÑем каÑегоÑÐ¸Ñ Ð² базе даннÑÑ
, коÑоÑÐ°Ñ ÐµÑÑÑ Ð² ÑеÑепÑе14 const foundCategory = await Category.findById(body.category)15 //ÐобавлÑем в каÑегоÑÐ¸Ñ Ð½Ð°Ñ Ð½Ð¾Ð²Ñй ÑеÑепÑ16 foundCategory.products.push(newRecipe.id)17 //ÐÑпÑавлÑем на Ð±Ð°Ð·Ñ Ð´Ð°Ð½Ð½ÑÑ
обновленнÑй ÑеÑепÑ18 const newCategory = await Category.findByIdAndUpdate(body.category, foundCategory, { new: true })19 //////////Ðобавление в каÑегоÑии////////////////20 ////////////Ðобавление в Ñеги///////////////////////21 for (let item of recipe.tags) {22 const findTag = await Tag.findOne({title: item.toLowerCase() })23 if (findTag) {24 findTag.products.push(newRecipe.id)25 const newTag = await Tag.findByIdAndUpdate(findTag._id, findTag)26 } else {27 let tag = new Tag(28 {29 title: item.toLowerCase(),30 description: '',31 products: [newRecipe.id]32 })33 await tag.save()34 }35 }36 ////////////Ðобавление в Ñеги///////////////////////37 ////////////Ðобавление в ингÑедиенÑÑ///////////////////////38 for (let item of recipe.ingredients) {39 const findIngredients = await Ingredients.findOne({ title: item.title.toLowerCase() })40 if (findIngredients) {41 findIngredients.products.push(newRecipe.id)42 const newIngredient = await Ingredients.findByIdAndUpdate(findIngredients._id, findIngredients)43 } else {44 let ingredient = new Ingredients(45 {46 title: item.title.toLowerCase(),47 description: '',48 products: [newRecipe.id]49 })50 await ingredient.save()51 }52 }53 ////////////Ðобавление в ингÑедиенÑÑ///////////////////////54 return res.status(200).send(newRecipe)55 } catch (e) {56 return res.status(400).send(boom.boomify(e))57 }58 }...
playerBars.ts
Source:playerBars.ts
...13 const study = ctrl.study;14 if (!study || ctrl.embed) return;15 const tags = study.data.chapter.tags,16 playerNames = {17 white: findTag(tags, 'white')!,18 black: findTag(tags, 'black')!19 };20 if (!playerNames.white && !playerNames.black && !treeOps.findInMainline(ctrl.tree.root, n => !!n.clock)) return;21 const clocks = renderClocks(ctrl),22 ticking = !isFinished(study.data.chapter) && ctrl.turnColor();23 return (['white', 'black'] as Color[]).map(color =>24 renderPlayer(tags, clocks, playerNames, color, ticking === color, ctrl.bottomColor() !== color));25}26function renderPlayer(tags: TagArray[], clocks: [VNode, VNode] | undefined, playerNames: PlayerNames, color: Color, ticking: boolean, top: boolean): VNode {27 const title = findTag(tags, `${color}title`),28 elo = findTag(tags, `${color}elo`),29 result = resultOf(tags, color === 'white');30 return h(`div.study__player.study__player-${top ? 'top' : 'bot'}`, {31 class: { ticking }32 }, [33 h('div.left', [34 result && h('span.result', result),35 h('span.info', [36 title && h('span.utitle', title == 'BOT' ? { attrs: { 'data-bot': true } } : {}, title + ' '),37 h('span.name', playerNames[color]),38 elo && h('span.elo', elo)39 ])40 ]),41 clocks && clocks[color === 'white' ? 0 : 1]42 ]);...
Using AI Code Generation
1const { findTag } = require("qawolf");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await findTag(page, "input[name=q]");8 await browser.close();9})();10const { findTag } = require("qawolf");11const { chromium } = require("playwright");12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 await findTag(page, "a", { text: "About" });17 await browser.close();18})();19const { findTag } = require("qawolf");20const { chromium } = require("playwright");21(async () => {22 const browser = await chromium.launch();23 const context = await browser.newContext();24 const page = await context.newPage();25 await findTag(page, "a", { text: "About", exact: false });26 await browser.close();27})();28const { findTag } = require("qawolf");29const { chromium } = require("playwright");30(async () => {31 const browser = await chromium.launch();
Using AI Code Generation
1const { findTag } = require("qawolf");2const { chromium } = require("playwright-chromium");3const browser = await chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const element = await findTag(page, "h1");7await element.click();8await browser.close();9const { findText } = require("qawolf");10const { chromium } = require("playwright-chromium");11const browser = await chromium.launch();12const context = await browser.newContext();13const page = await context.newPage();14const element = await findText(page, "Example Domain");15await element.click();16await browser.close();17const { findLabel } = require("qawolf");18const { chromium } = require("playwright-chromium");19const browser = await chromium.launch();20const context = await browser.newContext();21const page = await context.newPage();22const element = await findLabel(page, "Search");23await element.click();24await browser.close();25const { findPlaceholder } = require("qawolf");26const { chromium } = require("playwright-chromium");27const browser = await chromium.launch();28const context = await browser.newContext();29const page = await context.newPage();30const element = await findPlaceholder(page, "Search");31await element.click();32await browser.close();33const { findAlt } = require("qawolf");34const { chromium } = require("playwright-chromium");35const browser = await chromium.launch();36const context = await browser.newContext();37const page = await context.newPage();38const element = await findAlt(page, "Example Domain");39await element.click();40await browser.close();41const { findValue } = require("qawolf");42const { chromium } = require("playwright-chromium");43const browser = await chromium.launch();
Using AI Code Generation
1const { findTag } = require('qawolf');2const { findTag } = require('qawolf');3const { findTag } = require('qawolf');4const { findTag } = require('qawolf');5const { findTag } = require('qawolf');6const { findTag } = require('qawolf');7const { findTag } = require('qawolf');8const { findTag } = require('qawolf');9const { findTag } = require('qawolf');10const { findTag } = require('qawolf');11const { findTag } = require('qawolf');12const { findTag } = require('qawolf');13const { findTag } = require('qawolf');14const { findTag } = require('qawolf');
Using AI Code Generation
1const { findTag } = require("qawolf");2const { launch } = require("qawolf");3const browser = await launch();4const page = await browser.newPage();5const tag = await findTag(page, "input", { text: "Search" });6await page.type(tag, "hello world");7await browser.close();8{9 "scripts": {10 },11 "dependencies": {12 }13}14const { findText } = require("qawolf");15const { launch } = require("qawolf");16const browser = await launch();17const page = await browser.newPage();18const text = await findText(page, "Search");19await page.type(text, "hello world");20await browser.close();21{22 "scripts": {23 },24 "dependencies": {25 }26}27const { findValue } = require("qawolf");28const { launch } = require("qawolf");29const browser = await launch();30const page = await browser.newPage();31const value = await findValue(page, "input", { text: "Search" });32await page.type(value, "hello world");33await browser.close();34{35 "scripts": {36 },37 "dependencies": {38 }39}40const { findXpath } = require("qawolf");41const { launch } = require("qawolf");42const browser = await launch();43const page = await browser.newPage();
Using AI Code Generation
1const { findTag } = require("qawolf");2(async () => {3 const tag = await findTag("test");4 console.log(tag);5})();6const { findTag } = require("qawolf");7(async () => {8 const tag = await findTag("test");9 console.log(tag);10})();11const { findTag } = require("qawolf");12(async () => {13 const tag = await findTag("test");14 console.log(tag);15})();16const { findTag } = require("qawolf");17(async () => {18 const tag = await findTag("test");19 console.log(tag);20})();21const { findTag } = require("qawolf");22(async () => {23 const tag = await findTag("test");24 console.log(tag);25})();26const { findTag } = require("qawolf");27(async () => {28 const tag = await findTag("test");29 console.log(tag);30})();31const { findTag } = require("qawolf");32(async () => {33 const tag = await findTag("test");34 console.log(tag);35})();36const { findTag } = require("qawolf");37(async () => {38 const tag = await findTag("test");39 console.log(tag);40})();41const { findTag } = require("qawolf");42(async () => {43 const tag = await findTag("test");44 console.log(tag);45})();46const { findTag } = require("qawolf");47(async () => {48 const tag = await findTag("test");49 console.log(tag);50})();
Using AI Code Generation
1const { findTag } = require("qawolf");2console.log(tag);3const { findTags } = require("qawolf");4console.log(tags);5const { findText } = require("qawolf");6console.log(text);7const { findTexts } = require("qawolf");8console.log(texts);9const { findUrl } = require("qawolf");10console.log(url);11const { findUrls } = require("qawolf");12console.log(urls);13const { findValue } = require("qawolf");14console.log(value);15const { findValues } = require("qawolf");16console.log(values);17const { findVisible } = require("qawolf");18console.log(visible);19const { findVisibles } = require("qawolf");20console.log(visibles);21const { findWidth } = require("qawolf");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!