Skip to content

Commit

Permalink
Use KVPairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Davilarek committed Nov 13, 2023
1 parent 7d968ed commit c270a96
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
19 changes: 17 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<dd></dd>
<dt><a href="#TekstowoAPI">TekstowoAPI</a></dt>
<dd></dd>
<dt><a href="#KVPair">KVPair</a></dt>
<dd></dd>
</dl>

## Functions
Expand Down Expand Up @@ -106,7 +108,7 @@
* [.getPagesForSong(artist, songName, skipFetch, from)](#TekstowoAPI+getPagesForSong) ⇒ <code>Promise.&lt;number&gt;</code>
* [.getLyrics(artist, songName)](#TekstowoAPI+getLyrics) ⇒ <code>Promise.&lt;(TekstowoAPILyrics\|null)&gt;</code>
* [.getMetadata(songIdOrHtml, useHTML)](#TekstowoAPI+getMetadata) ⇒ <code>Promise.&lt;(TekstowoAPILyricsMetadata\|null)&gt;</code>
* [.getArtistsSongList(artistId, options)](#TekstowoAPI+getArtistsSongList) ⇒ <code>Promise.&lt;Object.&lt;string, TekstowoAPILyricsID&gt;&gt;</code>
* [.getArtistsSongList(artistId, options)](#TekstowoAPI+getArtistsSongList) ⇒ <code>Promise.&lt;{pageCount: number, results: Array.&lt;KVPair.&lt;string, TekstowoAPIArtistID&gt;&gt;}&gt;</code>

<a name="new_TekstowoAPI_new"></a>

Expand Down Expand Up @@ -234,7 +236,7 @@ Downloads, parses lyrics page and extracts "metrics" section for specified argum

<a name="TekstowoAPI+getArtistsSongList"></a>

### tekstowoAPI.getArtistsSongList(artistId, options) ⇒ <code>Promise.&lt;Object.&lt;string, TekstowoAPILyricsID&gt;&gt;</code>
### tekstowoAPI.getArtistsSongList(artistId, options) ⇒ <code>Promise.&lt;{pageCount: number, results: Array.&lt;KVPair.&lt;string, TekstowoAPIArtistID&gt;&gt;}&gt;</code>
Downloads and parses artist song list

**Kind**: instance method of [<code>TekstowoAPI</code>](#TekstowoAPI)
Expand All @@ -247,6 +249,19 @@ Downloads and parses artist song list
| options.sortDir | <code>string</code> |
| options.sortMode | <code>string</code> |

<a name="KVPair"></a>

## KVPair
**Kind**: global class
<a name="new_KVPair_new"></a>

### new KVPair(key, value)

| Param | Type |
| --- | --- |
| key | <code>K</code> |
| value | <code>V</code> |

<a name="TekstowoAPIProxyMethods"></a>

## TekstowoAPIProxyMethods : <code>enum</code>
Expand Down
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class TekstowoAPI {
* @param {number} options.page
* @param {string} options.sortDir
* @param {string} options.sortMode
* @returns {Promise<Object.<string, TekstowoAPILyricsID>>}
* @returns {Promise<{ pageCount: number, results: Array<KVPair<string, TekstowoAPIArtistID>> }>}
*/
async getArtistsSongList(artistId, options = {}) {
const { sortMode, sortDir, page } = options;
Expand All @@ -433,18 +433,32 @@ class TekstowoAPI {
const pageCount = await this.getPagesForSong(undefined, undefined, responseText);
const base = responseText.split('-lista">')[1].split("<!-- end right column -->")[0].replace(/\n/g, "").replace(/\t/g, "");
/**
* @type {Object.<string, TekstowoAPILyricsID>}
* @type {Array<KVPair<string, TekstowoAPIArtistID>>}
*/
const base2 = {};
const base2 = [];
const splitTarget = `<a href="/piosenka,`;
const extractedIds = getTextBetween(base, splitTarget, `.html" class="`);
for (let i = 0; i < extractedIds.length; i++) {
const element = extractedIds[i];
const name = base.split(splitTarget + element + `.html" class="title"title="`)[1].split(`">`)[0];
base2[name] = element;
base2.push(new KVPair(name, element));
}
// debugger;
return { pages: pageCount, results: base2 };
return { pageCount, results: base2 };
}
}

/**
* @template K, V
*/
class KVPair {
/**
* @param {K} key
* @param {V} value
*/
constructor(key, value) {
this.key = key;
this.value = value;
}
}

Expand Down

0 comments on commit c270a96

Please sign in to comment.