aboutsummaryrefslogtreecommitdiff
path: root/cmd/_old/sanguisuga/js/scripts/torrentleech.js
blob: 80c66c117ea748bb511da027bd229e5d93d11e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const regex =
  /^New Torrent Announcement: <([^>]*)>\s+Name:'(.*)' uploaded by '.*' ?(freeleech)?\s+-\s+https:..\w+.\w+.\w+\/.\w+\/([0-9]+)$/;

const genURL = (torrentName, baseURL, id, passkey) =>
  `https://www.torrentleech.org/rss/download/${id}/${passkey}/${torrentName}`;

export const allowLine = (nick, channel) => {
  if (channel !== "#tlannounces") {
    return false;
  }

  if (nick !== "_AnnounceBot_") {
    return false;
  }

  return true;
};

export const parseLine = (msg) => {
  const [_blank, category, torrentName, freeleech, baseURL, id, size] =
    msg.split(regex);

  return {
    torrent: {
      category,
      name: torrentName,
      freeleech: freeleech !== "",
      id: id,
      url: genURL(torrentName, baseURL, id),
    },
  };
};