-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5243ff0
Showing
17 changed files
with
2,080 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
description: Prepares the repo for a typical CI job | ||
|
||
name: Prepare | ||
|
||
runs: | ||
steps: | ||
- uses: pnpm/[email protected] | ||
with: | ||
version: 9 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
cache: pnpm | ||
- run: pnpm install | ||
shell: bash | ||
using: composite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: build-test | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ./.github/actions/prepare | ||
- name: use pnpm to build API Server | ||
run: | | ||
pnpm build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
### Node template | ||
# Logs | ||
/logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.vercel | ||
/public/sitemap.xml | ||
/public/robots.txt | ||
data | ||
/data | ||
data/status.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# Nuxt generate | ||
dist | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless | ||
|
||
# IDE / Editor | ||
.idea | ||
|
||
# Service worker | ||
sw.* | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# Vim swap files | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2025 sanweb.info | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# 🌐 Live Cricket Score 🏏 | ||
|
||
![build-test](https://github.com/sanwebinfo/ts-cricket-score/workflows/build-test/badge.svg) | ||
|
||
🌍 Free Live Cricket Score JSON API (Typescript Version) - Get data from Cricbuzz - Live Cricket Score API ⚡ | ||
|
||
Typescript Version - Get Live Cricket Score data from Cricbuzz.com | ||
|
||
This is an unofficial API and not Linked or Partnered with Any Brands/Company. | ||
|
||
**Note** | ||
|
||
I primarily built this tool for personal use, and I mostly run it on my home server or localhost.This tool is not recommended for production use, this is for educational purpose , you are welcome to fork the project and make any changes as needed. | ||
|
||
## Setup | ||
|
||
- Download or Clone the repo | ||
- install dependencies | ||
|
||
```sh | ||
pnpm install | ||
``` | ||
|
||
- Development | ||
|
||
```sh | ||
pnpm dev | ||
``` | ||
|
||
- Build a Project | ||
|
||
```sh | ||
pnpm build | ||
``` | ||
|
||
- Start the server | ||
|
||
```sh | ||
pnpm start | ||
``` | ||
|
||
## Routes | ||
|
||
- `/` - Static Home Page for Fetch Live Cricket Score | ||
- `/score` - Score API | ||
|
||
## API Usage | ||
|
||
- Get Live Cricket Score | ||
|
||
```sh | ||
curl http://localhost:6020/score?id=12345 | ||
``` | ||
|
||
## Disclaimer 🗃 | ||
|
||
- This is not an Offical API from Cricbuzz - it's an Unofficial API | ||
- This is for Education Purpose only - use at your own risk on Production Site | ||
- All Credits Goes to <https://www.cricbuzz.com/> | ||
|
||
The score data retrieved from CricBuzz is collected strictly for personal use only. This data is scraped using custom scripts and stored locally on my Android device, which functions as a personal server. The data is accessed and displayed via Termux, and the network traffic is securely proxied through a Cloudflare Argo Tunnel. | ||
|
||
This setup is fully contained within my personal environment and is not accessible to the outside world. The data is not served externally or used for any commercial purposes. I do not claim ownership of any data or content provided by CricBuzz. The scraping process is solely for personal use and complies with CricBuzz’s terms of service, ensuring no infringement on their intellectual property rights. | ||
|
||
Please note that any use, redistribution, or public display beyond personal use may violate CricBuzz’s terms and may be subject to legal or ethical consequences. I take no responsibility for any actions outside of personal, non-commercial use. | ||
|
||
## LICENSE | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const publicSrcDir = path.join(__dirname, 'public'); | ||
const distDir = path.join(__dirname, 'dist'); | ||
|
||
if (!fs.existsSync(path.join(distDir, 'public'))) { | ||
fs.mkdirSync(path.join(distDir, 'public'), { recursive: true }); | ||
} | ||
|
||
function copyFiles(src, dest) { | ||
const stats = fs.statSync(src); | ||
if (stats.isDirectory()) { | ||
if (!fs.existsSync(dest)) { | ||
fs.mkdirSync(dest, { recursive: true }); | ||
} | ||
fs.readdirSync(src).forEach((file) => { | ||
const srcFile = path.join(src, file); | ||
const destFile = path.join(dest, file); | ||
copyFiles(srcFile, destFile); | ||
}); | ||
} else { | ||
fs.copyFileSync(src, dest); | ||
} | ||
} | ||
|
||
fs.readdirSync(publicSrcDir).forEach(file => { | ||
const srcFile = path.join(publicSrcDir, file); | ||
const destFile = path.join(distDir, 'public', file); | ||
copyFiles(srcFile, destFile); | ||
}); | ||
|
||
console.log('Public folders copied successfully!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import express, { Application, Request, Response, NextFunction } from "express"; | ||
import axios from "axios"; | ||
import * as cheerio from "cheerio"; | ||
import path from 'path'; | ||
import errorHandler from './utils/error'; | ||
import { setSecureHeaders } from "./utils/secureHeaders"; | ||
|
||
const app: Application = express(); | ||
const PORT = process.env.PORT || 6020; | ||
|
||
app.use(express.json()); | ||
app.use( | ||
express.urlencoded({ | ||
extended: true, | ||
}) | ||
); | ||
app.use(setSecureHeaders); | ||
app.disable("x-powered-by"); | ||
|
||
app.use(express.static(path.join(__dirname, '.', 'public'))); | ||
app.get('/', (req: Request, res: Response) => { | ||
res.sendFile(path.join(__dirname, '.', 'public', 'index.html')); | ||
}); | ||
|
||
const fetchHTML = async (url: string): Promise<string> => { | ||
try { | ||
const response = await axios.get(url, { | ||
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" }, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
throw new Error("Failed to fetch the HTML content"); | ||
} | ||
}; | ||
|
||
const parseCricketScore = ($: cheerio.CheerioAPI): Record<string, string> => { | ||
const getText = (selector: string): string => | ||
$(selector).first().text().trim() || "Match Stats will Update Soon"; | ||
|
||
const matchStatuses: string[] = [ | ||
".cb-col.cb-col-100.cb-min-stts.cb-text-complete", | ||
".cb-text-inprogress", | ||
".cb-col.cb-col-100.cb-font-18.cb-toss-sts.cb-text-abandon", | ||
".cb-text-stumps", | ||
".cb-text-lunch", | ||
".cb-text-inningsbreak", | ||
".cb-text-tea", | ||
".cb-text-rain", | ||
".cb-text-wetoutfield", | ||
".cb-text-delay", | ||
".cb-col.cb-col-100.cb-font-18.cb-toss-sts.cb-text-", | ||
]; | ||
|
||
const matchUpdate = matchStatuses | ||
.map((selector) => $(selector).first().text().trim()) | ||
.find((status) => status) || "Match Stats will Update Soon"; | ||
|
||
const matchDateElement = $('span[itemprop="startDate"]').attr("content"); | ||
const matchDate = | ||
matchDateElement && | ||
new Date(matchDateElement).toLocaleString("en-IN", { | ||
timeZone: "Asia/Kolkata", | ||
hour12: true, | ||
}); | ||
|
||
return { | ||
title: getText("h1.cb-nav-hdr").replace(" - Live Cricket Score, Commentary", "").trim(), | ||
update: matchUpdate, | ||
matchDate: matchDate ? `Date: ${matchDate}` : "Match Stats will Update Soon", | ||
livescore: getText(".cb-font-20.text-bold"), | ||
runrate: `${getText(".cb-font-12.cb-text-gray")}`, | ||
}; | ||
}; | ||
|
||
const asyncHandler = | ||
(fn: (req: Request, res: Response, next: NextFunction) => Promise<void>) => | ||
(req: Request, res: Response, next: NextFunction): void => { | ||
Promise.resolve(fn(req, res, next)).catch(next); | ||
}; | ||
|
||
app.get( | ||
"/score", | ||
asyncHandler(async (req: Request, res: Response) => { | ||
const id = req.query.id as string; | ||
if (!id) { | ||
res.status(400).json({ error: "Match ID is required" }); | ||
return; | ||
} | ||
|
||
const url = `https://www.cricbuzz.com/live-cricket-scores/${id}`; | ||
const html = await fetchHTML(url); | ||
const $ = cheerio.load(html); | ||
const matchData = parseCricketScore($); | ||
res.json(matchData); | ||
}) | ||
); | ||
|
||
app.use((req: Request, res: Response) => { | ||
res.status(404).json({ error: 'Resource not found' }); | ||
}); | ||
|
||
app.use(errorHandler); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server PORT: ${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "ts-cricket-score", | ||
"version": "0.0.1", | ||
"private": true, | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"dev": "nodemon index.ts", | ||
"build": "tsc && node copy.js", | ||
"start": "node dist/index.js" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.7.9", | ||
"cheerio": "^1.0.0", | ||
"express": "^4.21.2" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^5.0.0", | ||
"@types/node": "^22.10.2", | ||
"nodemon": "^3.1.9", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
Oops, something went wrong.