cifraclub-wrapper 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +49 -0
- package/dist/index.js +1 -0
- package/package.json +41 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Document } from 'docx';
|
|
2
|
+
|
|
3
|
+
declare class Cifra {
|
|
4
|
+
id: string;
|
|
5
|
+
position: number;
|
|
6
|
+
name: string;
|
|
7
|
+
author: string;
|
|
8
|
+
tom: string;
|
|
9
|
+
hash: URLSearchParams;
|
|
10
|
+
capo: number;
|
|
11
|
+
capo_tom: string;
|
|
12
|
+
content: Array<{
|
|
13
|
+
type: string;
|
|
14
|
+
text: string;
|
|
15
|
+
}>;
|
|
16
|
+
readonly url: string;
|
|
17
|
+
private apiUrl;
|
|
18
|
+
constructor(data: CifraMeta);
|
|
19
|
+
lyrics(): Cifra;
|
|
20
|
+
noTabs(): Cifra;
|
|
21
|
+
chords(): Cifra;
|
|
22
|
+
private formatContent;
|
|
23
|
+
get(): Promise<void>;
|
|
24
|
+
private fetch;
|
|
25
|
+
setTone(halfSteps: number): void;
|
|
26
|
+
private getContent;
|
|
27
|
+
}
|
|
28
|
+
declare class CifraList extends Array<Cifra> {
|
|
29
|
+
constructor(...items: Array<Cifra>);
|
|
30
|
+
lyrics(): CifraList;
|
|
31
|
+
noTabs(): CifraList;
|
|
32
|
+
chords(): CifraList;
|
|
33
|
+
document(): Document;
|
|
34
|
+
}
|
|
35
|
+
type CifraMeta = {
|
|
36
|
+
path: string;
|
|
37
|
+
position: number;
|
|
38
|
+
hash: URLSearchParams;
|
|
39
|
+
name: string;
|
|
40
|
+
author: string;
|
|
41
|
+
};
|
|
42
|
+
declare class CifraClubApi {
|
|
43
|
+
static search(search: string): Promise<any>;
|
|
44
|
+
static list(url: string): Promise<Array<CifraMeta>>;
|
|
45
|
+
static downloadList(data?: Array<CifraMeta>): Promise<CifraList>;
|
|
46
|
+
static get(data: CifraMeta): Promise<Cifra | boolean>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { Cifra, CifraList, type CifraMeta, CifraClubApi as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function t(t,e){if(e==null||e>t.length)e=t.length;for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function e(t){if(Array.isArray(t))return t}function n(e){if(Array.isArray(e))return t(e)}function r(t){if(t===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return t}function o(t,e,n,r,o,i,u){try{var a=t[i](u);var c=a.value}catch(t){n(t);return}if(a.done){e(c)}else{Promise.resolve(c).then(r,o)}}function i(t){return function(){var e=this,n=arguments;return new Promise(function(r,i){var u=t.apply(e,n);function a(t){o(u,r,i,a,c,"next",t)}function c(t){o(u,r,i,a,c,"throw",t)}a(undefined)})}}function u(t,e,n){e=h(e);return _(t,T()?Reflect.construct(e,n||[],h(t).constructor):e.apply(t,n))}function a(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}}function c(t,e,n){if(T()){c=Reflect.construct}else{c=function t(t,e,n){var r=[null];r.push.apply(r,e);var o=Function.bind.apply(t,r);var i=new o;if(n)k(i,n.prototype);return i}}return c.apply(null,arguments)}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(t,r.key,r)}}function l(t,e,n){if(e)s(t.prototype,e);if(n)s(t,n);return t}function f(t,e,n){if(e in t){Object.defineProperty(t,e,{value:n,enumerable:true,configurable:true,writable:true})}else{t[e]=n}return t}function h(t){h=Object.setPrototypeOf?Object.getPrototypeOf:function t(t){return t.__proto__||Object.getPrototypeOf(t)};return h(t)}function p(t,e){if(typeof e!=="function"&&e!==null){throw new TypeError("Super expression must either be null or a function")}t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:true,configurable:true}});if(e)k(t,e)}function y(t,e){if(e!=null&&typeof Symbol!=="undefined"&&e[Symbol.hasInstance]){return!!e[Symbol.hasInstance](t)}else{return t instanceof e}}function d(t){return Function.toString.call(t).indexOf("[native code]")!==-1}function b(t){if(typeof Symbol!=="undefined"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function m(t,e){var n=t==null?null:typeof Symbol!=="undefined"&&t[Symbol.iterator]||t["@@iterator"];if(n==null)return;var r=[];var o=true;var i=false;var u,a;try{for(n=n.call(t);!(o=(u=n.next()).done);o=true){r.push(u.value);if(e&&r.length===e)break}}catch(t){i=true;a=t}finally{try{if(!o&&n["return"]!=null)n["return"]()}finally{if(i)throw a}}return r}function v(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function g(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function w(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};var r=Object.keys(n);if(typeof Object.getOwnPropertySymbols==="function"){r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))}r.forEach(function(e){f(t,e,n[e])})}return t}function O(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);if(e){r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})}n.push.apply(n,r)}return n}function x(t,e){e=e!=null?e:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(t,Object.getOwnPropertyDescriptors(e))}else{O(Object(e)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})}return t}function _(t,e){if(e&&(A(e)==="object"||typeof e==="function")){return e}return r(t)}function k(t,e){k=Object.setPrototypeOf||function t(t,e){t.__proto__=e;return t};return k(t,e)}function j(t,n){return e(t)||m(t,n)||S(t,n)||v()}function P(t){return n(t)||b(t)||S(t)||g()}function A(t){"@swc/helpers - typeof";return t&&typeof Symbol!=="undefined"&&t.constructor===Symbol?"symbol":typeof t}function S(e,n){if(!e)return;if(typeof e==="string")return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor)r=e.constructor.name;if(r==="Map"||r==="Set")return Array.from(r);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return t(e,n)}function E(t){var e=typeof Map==="function"?new Map:undefined;E=function t(t){if(t===null||!d(t))return t;if(typeof t!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof e!=="undefined"){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return c(t,arguments,h(this).constructor)}n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:false,writable:true,configurable:true}});return k(n,t)};return E(t)}function T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(T=function(){return!!t})()}function C(t,e){var n,r,o,i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},u=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return u.next=a(0),u["throw"]=a(1),u["return"]=a(2),typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function a(t){return function(e){return c([t,e])}}function c(a){if(n)throw new TypeError("Generator is already executing.");while(u&&(u=0,a[0]&&(i=0)),i)try{if(n=1,r&&(o=a[0]&2?r["return"]:a[0]?r["throw"]||((o=r["return"])&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;if(r=0,o)a=[a[0]&2,o.value];switch(a[0]){case 0:case 1:o=a;break;case 4:i.label++;return{value:a[1],done:false};case 5:i.label++;r=a[1];a=[0];continue;case 7:a=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(a[0]===6||a[0]===2)){i=0;continue}if(a[0]===3&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(a[0]===6&&i.label<o[1]){i.label=o[1];o=a;break}if(o&&i.label<o[2]){i.label=o[2];i.ops.push(a);break}if(o[2])i.ops.pop();i.trys.pop();continue}a=e.call(t,i)}catch(t){a=[6,t];r=0}finally{n=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}}Object.defineProperty(exports,"__esModule",{value:true});var R=require("docx"),D=require("axios");function G(t){return t&&t.__esModule?t:{default:t}}var I=G(D);var $=function(t){return(typeof require==="undefined"?"undefined":A(require))<"u"?require:(typeof Proxy==="undefined"?"undefined":A(Proxy))<"u"?new Proxy(t,{get:function(t,e){return((typeof require==="undefined"?"undefined":A(require))<"u"?require:t)[e]}}):t}(function(t){if((typeof require==="undefined"?"undefined":A(require))<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var q=$("cheerio"),M=/*#__PURE__*/function(){function t(e){a(this,t);this.$=q.load(e,{decodeEntities:false})}l(t,[{key:"find",value:function t(t){return this.$(t)}},{key:"setText",value:function t(t,e){return this.$(t).text(e),this}},{key:"setHtml",value:function t(t,e){return this.$(t).html(e),this}},{key:"addClass",value:function t(t,e){return this.$(t).addClass(e),this}},{key:"setAttr",value:function t(t,e,n){return this.$(t).attr(e,n),this}},{key:"remove",value:function t(t){return this.$(t).remove(),this}},{key:"each",value:function t(t,e){var n=this;return this.$(t).each(function(t,r){return e(n.$(r),t)}),this}},{key:"extractText",value:function t(t){return this.$(t).text().trim()}},{key:"extractList",value:function t(t){var e=this;return this.$(t).map(function(t,n){return e.$(n).text().trim()}).get()}},{key:"html",value:function t(){return this.$.html()}}]);return t}();var U=function(t){return"https://solr.sscdn.co/cc/h2/?q=".concat(encodeURIComponent(t),"&callback")},B="https://www.cifraclub.com.br",F=/urlAPI3:\s*'([^']+)'/,L={start:/#t\d+#/g,end:/#\/t\d+#/g};function W(t,e){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:false,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:12;if(!n)return(t-e+r)%r;var o=Math.abs(t-e);return Math.min(o,r-o)}var N=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:false,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:false;return"".concat(["A",t?"A#":"Bb","B","C",t?"C#":"Db","D",t?"D#":"Eb","E","F",t?"F#":"Gb","G",t?"G#":"Ab"][e]).concat(n?"m":"")};var H=function(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:false;var n=["A",["Bb","A#"],"B","C",["Db","C#"],"D",["D#","Eb"],"E","F",["F#","Gb"],"G",["Ab","G#"]],r=false;return n.forEach(function(n,o){r!==false&&typeof n=="string"||(typeof n=="string"&&t.startsWith(n)&&(r=e?new RegExp(n,"g"):o),Array.isArray(n)&&n.forEach(function(i){t.startsWith(i)&&(r=e?new RegExp(n.join("|"),"g"):o)}))}),r};function z(t){return new Promise(function(e){return setTimeout(e,t)})}var K=/^(\s*(?:\[.*?\]|\(.*?\)|[A-G](?:b|#)?(?:m|maj|min|sus|dim|aug|add|mMaj|∆|°|ø)?\d*(?:\([^\)]+\))?(?:\/[A-G](?:b|#)?)?)\s*)+$/i,J=/\b([A-G](?:#|b)?(?:m|maj7|maj|min7|m7|sus2|sus4|dim|aug|add\d+|7)?(?:\/[A-G](?:#|b)?)?)\b/g,Q=/*#__PURE__*/function(){function t(e){a(this,t);this.id="";this.name="";this.author="";this.tom="";this.capo=0;this.capo_tom="";this.content=[];this.apiUrl="";this.url="".concat(B,"/").concat(e.path),this.author=e.author,this.name=e.name,this.hash=e.hash,this.position=e.position}l(t,[{key:"lyrics",value:function t(){return x(w({},this),{content:this.content.filter(function(t){return t.type.includes("lyrics")})})}},{key:"noTabs",value:function t(){return x(w({},this),{content:this.content.filter(function(t){return t.type!=="tab"})})}},{key:"chords",value:function t(){return x(w({},this),{content:this.content.filter(function(t){return t.type.includes("chords")})})}},{key:"formatContent",value:function t(t){this.content=t.split("\n").map(function(t){var e=t.match(K),n=t.includes("|")&&t.includes("--")&&/A|B|C|D|E|F|G/i.test(t)?"tab":e?"chords":"lyrics";return t=t.replace(L.start,"").replace(L.end,""),t.includes("[")&&t.includes("]")&&(n="indicator_".concat(n)),t.trim().length==0&&(n="empty"),{type:n,text:t.trimEnd()}}).filter(function(t,e,n){if(e===0)return true;var r=n[e-1].type=="empty";return!(t.type=="empty"&&r)})}},{key:"get",value:function t(){return i(function(){var t,e,n,r,o,i;return C(this,function(u){switch(u.label){case 0:return[4,this.fetch()];case 1:t=u.sent(),e=t.capo,n=t.cifra_id,r=t.tom,o=t.minor,i=t.capo_tom;this.capo=e,this.id=n,this.tom=N(false,r,o),this.capo_tom=N(false,i,o);return[2]}})}).call(this)}},{key:"fetch",value:function t(){return i(function(){var t,e,n,r,o,i,u,a,c,s,l,f,h,p,y,d,b;return C(this,function(m){switch(m.label){case 0:e=parseInt(this.hash.get("capo")||"0"),n=parseInt(this.hash.get("key")||"0");return[4,I.default.get(this.url)];case 1:r=m.sent().data,o=new M(r),i=(t=F.exec(r))===null||t===void 0?void 0:t[1];this.apiUrl="https://api.cifraclub.com.br/v3/".concat(i);u=j(o.find("#cifra_tom").text().match(J),2),a=u[0],c=u[1],s=a.includes("m"),l=c?H(c):0;this.formatContent(o.find(".cifra_cnt").find("pre").text());f=H(a),h=c?W(f,l):0,p=f+h;p+=n,this.hash.get("capo")&&(h=e,n=-h),p+=h,p>=11&&(p-=11),console.log(N(true,p));y=p-h;y<0&&(y+=11);return[4,this.getContent(n)];case 2:d=m.sent(),b=d.content;return[2,(this.formatContent(b.replace(/(\<b\>)|(\<\/b\>)/g,"")),{tom:p,capo:h,capo_tom:y,cifra_id:i,minor:s})]}})}).call(this)}},{key:"setTone",value:function t(t){this.hash.set("key",(parseInt(this.hash.get("key")||"0")+t).toString())}},{key:"getContent",value:function t(t){return i(function(){return C(this,function(e){switch(e.label){case 0:return[4,I.default.get("".concat(this.apiUrl,"/transpose?halfSteps=").concat(t,"&newFormat=false"),{headers:{accept:"*/*","accept-language":"pt-BR,pt;q=0.9",origin:"https://www.cifraclub.com.br",priority:"u=1, i",referer:"https://www.cifraclub.com.br/","sec-ch-ua":'"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"',"sec-ch-ua-mobile":"?0","sec-ch-ua-platform":'"Windows"',"sec-fetch-dest":"empty","sec-fetch-mode":"cors","sec-fetch-site":"same-site","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36"}})];case 1:return[2,e.sent().data]}})}).call(this)}}]);return t}(),V=/*#__PURE__*/function(t){p(e,t);function e(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++){n[r]=arguments[r]}a(this,e);return u(this,e,P(n))}l(e,[{key:"lyrics",value:function t(){return c(e,P(this.map(function(t){return t.lyrics()})))}},{key:"noTabs",value:function t(){return c(e,P(this.map(function(t){return t.noTabs()})))}},{key:"chords",value:function t(){return c(e,P(this.map(function(t){return t.chords()})))}},{key:"document",value:function t(){return new R.Document({sections:this.map(function(t){return X(t)})})}}]);return e}(E(Array));function X(t){return{properties:{page:{margin:{top:720,right:720,bottom:720,left:720}},column:{count:t.content.length>80?2:1,space:720}},children:[new R.Paragraph({children:[new R.TextRun({text:t.name,bold:true}),new R.TextRun(" - "),new R.TextRun(t.author)],heading:R.HeadingLevel.HEADING_5}),new R.Paragraph({children:[new R.TextRun({text:"TOM: ",bold:true}),new R.TextRun({text:t.tom,bold:true,color:"#ed7802"})].concat(P(t.capo>0?[new R.TextRun(" (Capo ".concat(t.capo,"\xaa casa, acordes em ").concat(t.capo_tom,")"))]:[]))})].concat(P(t.content.map(function(t,e){return new R.Paragraph({children:[new R.TextRun(w({text:t.text,font:"Courier New",size:15},t.type.includes("chords")?{color:"#ed7802",bold:true}:{}))]})})))}}var Y=/*#__PURE__*/function(){function t(){a(this,t)}l(t,null,[{key:"search",value:function t(t){return i(function(){var e,n,r;return C(this,function(o){switch(o.label){case 0:e=U(t);o.label=1;case 1:o.trys.push([1,3,,4]);return[4,I.default.get(e)];case 2:n=o.sent().data.trim().slice(1,-1);return[2,JSON.parse(n).response.docs.map(function(t){return{path:"".concat(t.d,"/").concat(t.u),hash:new URLSearchParams(""),name:t.m,author:t.a,position:0}})];case 3:r=o.sent();return[2,[]];case 4:return[2]}})})()}},{key:"list",value:function t(t){return i(function(){var e,n;return C(this,function(r){switch(r.label){case 0:r.trys.push([0,2,,3]);return[4,I.default.get(t)];case 1:e=r.sent();return[2,new M(e.data.toString()).find(".list-musics").find("a").toArray().map(function(t,e){var n=j(t.attribs.href.split("#"),2),r=n[0],o=n[1];return{path:r,position:e,hash:new URLSearchParams(o||""),name:t.children[0].children[0].data,author:t.children[1].data.slice(3)}})];case 2:n=r.sent();console.error(n);return[3,3];case 3:return[2,[]]}})})()}},{key:"downloadList",value:function e(){return i(function(){var e,n,r,o,i;var u=arguments;return C(this,function(a){switch(a.label){case 0:e=u.length>0&&u[0]!==void 0?u[0]:[];n=new V;a.label=1;case 1:a.trys.push([1,7,,8]);a.label=2;case 2:if(!(e.length>0))return[3,6];r=e.shift();return[4,t.get(r)];case 3:o=a.sent();y(o,Q)&&n.push(o);return[4,z(100)];case 4:a.sent();a.label=5;case 5:return[3,2];case 6:return[3,8];case 7:i=a.sent();console.error(i);return[3,8];case 8:return[2,n]}})}).apply(this,arguments)}},{key:"get",value:function t(t){return i(function(){var e,n;return C(this,function(r){switch(r.label){case 0:r.trys.push([0,2,,3]);e=new Q(t);return[4,e.get()];case 1:return[2,(r.sent(),e)];case 2:n=r.sent();console.log(n);return[3,3];case 3:return[2,false]}})})()}}]);return t}();var Z=Y;exports.Cifra=Q;exports.CifraList=V;exports.default=Z;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cifraclub-wrapper",
|
|
3
|
+
"main": "./dist/index.js",
|
|
4
|
+
"types": "./dist/index.d.ts",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=16.20.1"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "ts-node-dev src/index.ts",
|
|
15
|
+
"build": "tsup && npm publish --access public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^1.13.2",
|
|
19
|
+
"cheerio": "^1.1.2",
|
|
20
|
+
"docx": "^9.5.1",
|
|
21
|
+
"ts-node-dev": "^2.0.0",
|
|
22
|
+
"tsup": "^8.5.1",
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
},
|
|
25
|
+
"tsd": {
|
|
26
|
+
"directory": "test/types",
|
|
27
|
+
"compilerOptions": {
|
|
28
|
+
"esModuleInterop": false,
|
|
29
|
+
"strict": true,
|
|
30
|
+
"allowSyntheticDefaultImports": true,
|
|
31
|
+
"strictPropertyInitialization": false,
|
|
32
|
+
"noImplicitAny": false,
|
|
33
|
+
"strictNullChecks": true,
|
|
34
|
+
"module": "commonjs",
|
|
35
|
+
"target": "ES2017"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@swc/core": "^1.15.3"
|
|
40
|
+
}
|
|
41
|
+
}
|