-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
189 lines (186 loc) · 8.71 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const axios = require('axios');
var apiKey = 1;
module.exports = {
setApiKey(key){
apiKey = key
},
async getTeamByName(name){
name = makeUrl(name)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/searchteams.php?t=${name}`)).data;
},
async getTeamByShortCode(code){
code = makeUrl(code)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/searchteams.php?sname=${code}`)).data;
},
async getAllPlayersByTeam(name){
name = makeUrl(name)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/searchplayers.php?t=${name}`)).data;
},
async getPlayerByName(name, team){
name = makeUrl(name)
team = makeUrl(team)
var params = []
params.push(`p=${name}`)
if(team) params.push(`t=${team}`)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/searchplayers.php?${params.join('&')}`)).data;
},
async getEventByName(name, season){
name = makeUrl(name)
season = makeUrl(season)
var params = []
params.push(`e=${name}`)
if(season) params.push(`s=${season}`)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/searchevents.php?${params.join('&')}`)).data;
},
async getSportsList(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/all_sports.php`)).data;
},
async getLeagueList(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/all_leagues.php`)).data;
},
async getCountryList(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/all_countries.php`)).data;
},
async getLeagueListByCountry(country, sport){
country = makeUrl(country)
sport = makeUrl(sport)
var params = []
params.push(`c=${country}`)
if(sport) params.push(`s=${sport}`)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/search_all_leagues.php?${params.join('&')}`)).data;
},
async getSeasonsInLeagueById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/search_all_seasons.php?id=${id}`)).data;
},
async getTeamsByLeagueName(name){
name = makeUrl(name)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/search_all_teams.php?l=${name}`)).data;
},
async getTeamsByLeagueName(name){
name = makeUrl(name)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/search_all_teams.php?l=${name}`)).data;
},
async getTeamsByCountryAndSport(sport, country){
country = makeUrl(country)
sport = makeUrl(sport)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/search_all_teams.php?s=${sport}&c=${country}`)).data;
},
// async getTeamDetailsById(id){
// return axios.get(`https://www.thesportsdb.com/api/v1/json/1/lookup_all_teams.php?id=${id}`).data;
// },
async getPlayersByTeamId(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookup_all_players.php?id=${id}`)).data;
},
async getUsersLoved(user){
user = makeUrl(user)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/searchloves.php?u=${user}`)).data;
},
async getLeagueDetailsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookupleague.php?id=${id}`)).data;
},
async getTeamDetailsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookupteam.php?id=${id}`)).data;
},
async getPlayerDetailsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookupplayer.php?id=${id}`)).data;
},
async getEventDetailsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookupevent.php?id=${id}`)).data;
},
async getPlayerHonoursById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookuphonors.php?id=${id}`)).data;
},
async getPlayerFormerTeamsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookupformerteams.php?id=${id}`)).data;
},
async getPlayerContractsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookupcontracts.php?id=${id}`)).data;
},
async getEventResultsById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventresults.php?id=${id}`)).data;
},
async getTvEventById(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookuptv.php?id=${id}`)).data;
},
async getLookupTableByLeagueIdAndSeason(id, season){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/lookuptable.php?l=${id}&s=${season}`)).data;
},
async getNext5EventsByTeamId(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventsnext.php?id=${id}`)).data;
},
async getNext15EventsByLeagueId(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventsnext.php?id=${id}`)).data;
},
async getPast5EventsByTeamId(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventslast.php?id=${id}`)).data;
},
async getPast15EventsByLeagueId(id){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventspastleague.php?id=${id}`)).data;
},
async getEventsInRound(id, round, season){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventsround.php?id=${id}&r=${round}&s=${season}`)).data;
},
async getEventsOnDay(day, sport, name){
sport = makeUrl(sport)
name = makeUrl(name)
var params = []
if(day) params.push(`d=${day}`)
if(name) params.push(`l=${name}`)
if(sport) params.push(`s=${sport}`)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventsday.php?${params.join('&')}`)).data;
},
async getTvEventsOnDay(day, sport, country){
sport = makeUrl(sport)
country = makeUrl(country)
var params = []
if(day) params.push(`d=${day}`)
if(country) params.push(`a=${league}`)
if(sport) params.push(`s=${sport}`)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventstv.php?${params.join('&')}`)).data;
},
async getTvEventsByChannel(channel){
channel = makeUrl(channel)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventstv.php?c=${channel}`)).data;
},
async getEventsByLeagueIdAndSeason(id, season){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventsseason.php?id=${id}&s=${season}`)).data;
},
async getImage(id){
return (await axios.get(`https://www.thesportsdb.com/images/media/league/fanart/${id}.jpg`)).data;
},
async getPreviewImage(id){
return (await axios.get(`https://www.thesportsdb.com/images/media/league/fanart/${id}.jpg/preview`)).data;
},
async getYoutubeEventHighligts(day, league, sport){
league = makeUrl(league)
sport = makeUrl(sport)
var x = []
if(day) x.push(`d=${day}`)
if(league) x.push(`l=${league}`)
if(sport) x.push(`s=${sport}`)
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventshighlights.php?${x.join("&")}`)).data;
},
async getAllEventsByLeagueIdAndSeason(id, season){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/eventsseason.php?id=${id}&s=${season}`)).data;
},
async getSoccerLivescores(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/latestsoccer.php`)).data;
},
async getLivescoresBySport(sport){
sport = makeUrl(sport)
return (await axios.get(`https://www.thesportsdb.com/api/v2/json/${apiKey}/livescore.php?s=${sport}`)).data;
},
async getGolfLivescores(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/latestgolf.php`)).data;
},
async getBasketballLivescores(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/latestbasketball.php`)).data;
},
async getAmericanFootballLivescores(){
return (await axios.get(`https://www.thesportsdb.com/api/v1/json/${apiKey}/latestamericanfootball.php`)).data;
}
}
function makeUrl(x){
if(!x) return x;
return x.split(" ").join("_");
}