gigobyte / hltv Goto Github PK
View Code? Open in Web Editor NEWThe unofficial HLTV Node.js API
License: MIT License
The unofficial HLTV Node.js API
License: MIT License
console.log(HLTV.default.connectToScorebot( {id: 2314408, onScoreboardUpdate: (data) => {
console.log(data, 'Flag 1')
}}) )
This returns = Promise { pending }
I wasn't getting this the other day, it seems like scorebot isn't getting any data to send to me. If I am missing something please lmk
It doesn't seem to be working after the layout update, even on runkit
Hi, i don't know, but something got changed in the api, cant get a proper team name, it happens with all the teams. You can see even through postman, something is not right. In name - it shows ENCEmousesports, when it should display hellraisers
preview
I use getMatches method in my project. Most recently, I started to notice that some games have identical IDs of two teams. I think you should check this out. Thank you!
I dont use the database for grabbing. I get the data from the saved page cache.
Can you help me get the date for 'getResults.ts'? pls
I made a quick project for school using this awesome package... it was working fine on my local machine... my GetMatches() and GetResults() were returning me the correct data and everything was fine... The only weird(ish) thing I did was call these methods from my NodeJS server and then from there send it to my front end. My front end was getting the data perfectly etc.... I set up a droplet on Digital ocean, pushed my project and got it up and running. Now whenever I try to get the data my Getmatches() and GetResults() return an empty array []. Any idea what this could be?
HLTV.getPlayer({id: 429})
It's Karrigan player ID (https://www.hltv.org/stats/players/429/karrigan)
Error:
Cannot read property '0' of null at Object.<anonymous>(node_modules/hltv/lib/endpoints/getPlayer.js:51:65)
Hi @gigobyte, nice project!
It's possible to search player by name?
Or some way to get players ID for use on HLTV.getPlayer()
method?
Cheers!
Currently some of the dependencies are outdated, they need to be updated.
(Also make sure the project builds by running the build
command)
How i cant get match score when match end?
Since today I got this messages. I try to fetch details from this game https://www.hltv.org/matches/2326680/w7m-vs-furia-inagame-aorus-league-2018-season-3-brazil
getMatch.js
(node:16311) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16311) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:16311) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
at /home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getMatch.js:120:97
at Array.map (<anonymous>)
at Object.<anonymous> (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getMatch.js:112:87)
at step (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getMatch.js:32:23)
at Object.next (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getMatch.js:13:53)
at fulfilled (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getMatch.js:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
(node:16311) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
getTeam.js
(node:30319) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:30319) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
at getPlayerId (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getTeam.js:65:48)
at /home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getTeam.js:68:29
at Array.map (<anonymous>)
at Object.<anonymous> (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getTeam.js:66:122)
at step (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getTeam.js:32:23)
at Object.next (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getTeam.js:13:53)
at fulfilled (/home/scidev2/Bots/hltv-scorebot/node_modules/hltv/lib/endpoints/getTeam.js:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
(node:30319) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
This module does not receive command icons?
Any ideas about this? Thank you
Hello, since last night the api returns a empty array on every call, did HLTV change something to break the api?
I checked hltv and it does not seem like i am ip banned.
let stats = await HLTV.getMatchMapStats({id : 74429});
The teams are inverted on roundHistory
Hello, when i updated module to 2.7.3, ive go error like this.
How i can fix this? Can you help please?
This is some code:
#>function checkLive444(){
HLTV.getMatches().then((res) => {
for(var i in res)
{
var e1 = res[i].date;
var e2 = String(e1);
var event_date = e2.slice(0, -3);
if(res[i].live){
requestify.post('http://localhost/checkLive823677812aw', {match_id: res[i].id}).then(function (response) {
if(JSON.parse(response.body).status == 1){
console.log("Status live");
HLTV.getMatch({id: res[i].id}).then(res2 => {
var streams = res2.streams[0].link;
var team1_id = res2.team1Id;
var team2_id = res2.team2Id;
if(streams == 'undefined' || streams == '' || streams == ' '){streams = 'no stream';}
requestify.post('http://localhost/updateStream823677812aw', {
stream: streams,
match_id: res[i].id,
team1_id: team1_id,
team2_id: team2_id
})
.then(function (response) {
startFollow(res[i].id);
if(JSON.parse(response.body).status == 'false'){}
if(JSON.parse(response.body).status == 'true'){console.log("Stream added live");}
}, function (err) {
console.tag('Tournament').log(err);
});
});
}
}, function (err) {});
}
if(event_date == 'undefi'){}else{
if(timeDifference(event_date) == 1){
requestify.post('http://localhost/checkLive823677812aw', {match_id: res[i].id}).then(function (response) {
if(JSON.parse(response.body).status == 1){
console.log("Status live");
HLTV.getMatch({id: res[i].id}).then(res2 => {
var streams = res2.streams[0].link;
var team1_id = res2.team1Id;
var team2_id = res2.team2Id;
if(streams == 'undefined' || streams == '' || streams == ' '){streams = 'no stream';}
requestify.post('http://localhost/updateStream823677812aw', {
stream: streams,
match_id: res[i].id,
team1_id: team1_id,
team2_id: team2_id
})
.then(function (response) {
startFollow(res[i].id);
if(JSON.parse(response.body).status == 'false'){}
if(JSON.parse(response.body).status == 'true'){console.log("Stream added live");}
}, function (err) {
console.tag('Tournament').log(err);
});
});
}
}, function (err) {});
}
}
}
});
}
This match does not have any additionalInfo - https://www.hltv.org/matches/2312432/infused-vs-excel-gfinity-elite-series
But modul try get additionalInfo and we get errors:
(node:11272) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:11272) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'split' of undefined
Greetings! Used your development, everything worked perfectly! But recently I began to notice that instead of matches began to come an empty array. I decided to check. I sent a request on the link https://www.hltv.org/matches with the REQUEST module. The status code is 404, but the content of the page is successfully taken. Perhaps the administration of the project hltv.org made such a "bluff" to the parsers stopped working. I ask for help!
Hello. I want to convert response to JSON - comfortable for http server in NodeJS. How can I do it ?
Sometimes when parsing I get an error that can happen 1000 times (in this case 1373 times): (node:22516) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1373): TypeError: Cannot read property 'split' of undefined
HLTV.getTeam({id: 6137}).then(res => {
console.log(res);
})
(node:25940) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'split' of undefined
(node:25940) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
To get teams names you use - $('div.teamName')
But on this page with LIVE match 4 div with class teamName:
0:div.teamName 1:div.teamName 2:div.nameCell.teamName 3:div.nameCell.teamName
Last 2 on scorboard.
To get 1 team name you use: $('div.teamName').first()
and this work
But for 2 team name you use $('div.teamName').last()
and we get 3:div.nameCell.teamName
not 1:div.teamName
Maybe worth using: $('div.teamName').eq(0)
and $('div.teamName').eq(1)
Improve createInstance
by allowing an additional object to be passed through to the fetch instance to support custom http headers, http agent and query string parameters.
I'm not up-to-scratch with my typescript - if we add in a fetchOptions
object to the base HLTVConfig
export default interface HLTVConfig {
hltvUrl?: string
hltvStaticUrl?: string
fetchOptions?: object
}
and then handle that inside mappers/fetchPage
export const fetchPage = async (url: string) => cheerio.load(await fetch(url, fetchOptions).then((res: any) => res.text()))
I think we're in business.
fetchOptions
can be an empty object. Then we can pass through headers like user-agent
, host
, and referrer
or a custom https agent.
isomorphic-fetch
uses node-fetch
https://www.npmjs.com/package/node-fetch
Looking at the docs here: https://www.npmjs.com/package/node-fetch#api
Options
{
// These properties are part of the Fetch Standard
method: 'GET',
headers: {}, // request headers. format is the identical to that accepted by the Headers constructor (see below)
body: null, // request body. can be null, a string, a Buffer, a Blob, or a Node.js Readable stream
redirect: 'follow', // set to `manual` to extract redirect headers, `error` to reject redirect
// The following properties are node-fetch extensions
follow: 20, // maximum redirect count. 0 to not follow redirect
timeout: 0, // req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)
compress: true, // support gzip/deflate content encoding. false to disable
size: 0, // maximum response body size in bytes. 0 to disable
agent: null // http(s).Agent instance, allows custom proxy, certificate etc.
}
If no values are set, the following request headers will be sent automatically:
Header | Value |
---|---|
Accept-Encoding |
gzip,deflate (when options.compress === true ) |
Accept |
*/* |
Connection |
close (when no options.agent is present) |
Content-Length |
(automatically calculated, if possible) |
User-Agent |
node-fetch/1.0 (+https://github.com/bitinn/node-fetch) |
So we want to be setting User-Agent
at the very least to a proper browser user agent. Being able to set agent
allows us to set a proxy-pass ip and port without having to host a proxied version of hltv if we so wish to.
If you're happy with that solution I can put together a PR.
New
position changeTest with this methods:
HLTV.getMatches()
HLTV.getStreams()
HLTV.getResults()
All of them return an empty array
Hey there @gigobyte, this project seems rad!
I'm using just a simple little express server and trying to make calls to the API inside of a route. I'm only getting back an empty array, no matter how hard I try. I even tried to use lucaspalencia's CS:GO CLI project and it seems to be suffering from the same issue.
I just simply use it in this way:
HLTV.getPlayer({ id: 9216 }).then(console.log, console.log)
then get an error
TypeError: Cannot read property 'includes' of undefined
at Object.<anonymous> (node_modules/hltv/lib/endpoints/getPlayer.js:54:41)
at step (node_modules/hltv/lib/endpoints/getPlayer.js:32:23)
at Object.next (node_modules/hltv/lib/endpoints/getPlayer.js:13:53)
at fulfilled (node_modules/hltv/lib/endpoints/getPlayer.js:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
then I go check the related source code
shownImage = $('.containedImageFrame img').attr('src');
image = !shownImage.includes('blankplayer') ? shownImage : undefined;
it seems that shownImage
may be undefined which makes this error happened
I will make a PR later to fix it, please check it out
Can i get winner team id when match end?
In UpcomingMatch model 'format' is required but some games don't have this property.
Example: {"id":2322001,"date":1524067200000,"format":"","title":"DH Marseille Group A Elimination Match","stars":0,"live":false}
Format is empty.
Can't getMatch because there is one draw in head to head history and no .winner
if (team1 && team2) {
headToHead = toArray($('.head-to-head-listing tr')).map(matchEl => ({
date: Number(matchEl.find('.date a span').attr('data-unix')),
winner: {
name: matchEl.find('.winner .flag').next().text(),
id: Number(matchEl.find('.winner .flag').next().attr('href').split('/')[2]) //Cannot read property split of undefined
},
event: {
name: matchEl.find('.event a').text(),
id: Number(matchEl.find('.event a').attr('href').split('/')[2])
},
map: matchEl.find('.dynamic-map-name-short').text() as MapSlug,
result: matchEl.find('.result').text()
}))
}
Match id that i can't get: 2325766
Match id with draw: 2316771
hltv.org/results/ has a "featured results" section containing several matches. These matches are also found elsewhere on the page. The getResults method returns all matches on the page including those in the "featured results" sections so they appear twice in the array. I believe they should be removed if possible.
Hi, Could you add feature for getMatches() and getResults() of adding team logos so that i could use it for interpolation
Hi,
When I simply try to load module, it fails (npm installed module properly). The same thing happens if you test it with npm's runkit:
When i use getMatch
for started match i dont get stream names. You use in endpoints/getMatch.ts
:
name: streamEl.find('.flagAlign .spoiler').text()
for get stream name, but on hltv stream don't have class .spoiler
. It can be fixed if use: name: streamEl.find('.flagAlign').text()
.
Is it possible to change the "map" variable in https://github.com/gigobyte/HLTV/blob/master/src/models/MatchResult.ts to an array to support bo3-mapparsing?
I haven't use node.js .. How can i get info from hltv
Hello, i was wondering how i should go about sending the data to the client so i can use it in an app, i can only log it to the console, but using postman i get nothting in the request.
Any help would be appreciated !
Sometimes the name or id of one of the teams is not parsed.
{ "id":2313372, "team1":{ "name":"Majestic Lions", "id":6576 }, "team2":{ "name":"", "id":5412 }, "event":{ "name":"PG WAY Trnava 2017", "id":null }, "format":"Best of 3", "maps":[ "ovp", "inf", "mrg" ], "stars":0, "live":true }
Sometimes I got this error
(node:7959) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'match' of undefined
at Object.exports.getMapsStatistics (/home/discord/scorebottest/node_modules/hltv/lib/utils/mappers.js:118:17)
at Object.<anonymous> (/home/discord/scorebottest/node_modules/hltv/lib/endpoints/getTeam.js:96:47)
at step (/home/discord/scorebottest/node_modules/hltv/lib/endpoints/getTeam.js:32:23)
at Object.next (/home/discord/scorebottest/node_modules/hltv/lib/endpoints/getTeam.js:13:53)
at fulfilled (/home/discord/scorebottest/node_modules/hltv/lib/endpoints/getTeam.js:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:7959) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7959) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I have found a way to fix this
change line 96 from
mapStatistics = mappers_1.getMapsStatistics(t$(t$('.graph').get(1)).attr('data-fusionchart-config'));
into this
try {
mapStatistics = mappers_1.getMapsStatistics(t$(t$('.graph').get(1)).attr('data-fusionchart-config'));
} catch(_c) {
mapStatistics = [];
}
The error appears when I try to get details from team "tempo storm" (HLTV teamId: 6118) from HLTV
The getMatch method are returning link undefined for all streams.
Example:
HLTV.getMatch({ id: '2319592' }).then(result => {
console.log(result);
res.status(200).json(result);
})
returns
{ team1: { name: 'Liquid', id: 5973 },
team2: { name: 'eUnited', id: 7106 },
winnerTeam: undefined,
date: 1524607200000,
format: 'Best of 1',
additionalInfo: '',
event: { name: 'ECS Season 5 North America', id: 3602 },
maps: [ { name: 'inf', result: '' } ],
players:
{ team1: [ [Object], [Object], [Object], [Object], [Object] ],
team2: [ [Object], [Object], [Object], [Object], [Object] ] },
streams: [ { name: 'FACEIT TV', link: undefined, viewers: 7800 } ],
live: true,
title: undefined,
hasScorebot: true,
highlightedPlayer: { name: 'NAF', id: 8520 },
headToHead:
[ { date: 1499814096000,
winner: [Object],
event: [Object],
map: 'cbl',
result: '16 - 7' },
{ date: 1499814096000,
winner: [Object],
event: [Object],
map: 'mrg',
result: '16 - 14' } ],
vetoes: [],
highlights: [] }
Good afternoon. I ran my script, he worked for about 2 hours and I got a ip-ban on HLTV. Do you know the circumvention of this restriction? When a certain number of requests come through your API, the cloudflare automatically ban my IP
Hello,
I just wanted to try your api, but unfortunately I got this error:
Fetch API cannot load http://www.hltv.org/matches. Redirect from 'http://www.hltv.org/matches' to 'https://www.hltv.org/matches' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Anything what could help?
Thanks!
Do you have any plans to add events?
Do you accept contributions?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.