MCPcopy
hub / github.com/iptv-org/iptv / downloadData

Function downloadData

scripts/api.ts:72–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70}
71
72async function downloadData() {
73 function formatBytes(bytes: number) {
74 if (bytes === 0) return '0 B'
75 const k = 1024
76 const sizes = ['B', 'KB', 'MB', 'GB']
77 const i = Math.floor(Math.log(bytes) / Math.log(k))
78 return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
79 }
80
81 const files = [
82 'blocklist',
83 'categories',
84 'channels',
85 'cities',
86 'countries',
87 'feeds',
88 'guides',
89 'languages',
90 'logos',
91 'regions',
92 'streams',
93 'subdivisions',
94 'timezones'
95 ]
96
97 const multiBar = new cliProgress.MultiBar({
98 stopOnComplete: true,
99 hideCursor: true,
100 forceRedraw: true,
101 barsize: 36,
102 format(options, params, payload) {
103 const filename = payload.filename.padEnd(18, ' ')
104 const barsize = options.barsize || 40
105 const percent = (params.progress * 100).toFixed(2)
106 const speed = payload.speed ? formatBytes(payload.speed) + '/s' : 'N/A'
107 const total = formatBytes(params.total)
108 const completeSize = Math.round(params.progress * barsize)
109 const incompleteSize = barsize - completeSize
110 const bar =
111 options.barCompleteString && options.barIncompleteString
112 ? options.barCompleteString.substr(0, completeSize) +
113 options.barGlue +
114 options.barIncompleteString.substr(0, incompleteSize)
115 : '-'.repeat(barsize)
116
117 return `${filename} [${bar}] ${percent}% | ETA: ${params.eta}s | ${total} | ${speed}`
118 }
119 })
120
121 const dataManager = new sdk.DataManager({ dataDir: DATA_DIR })
122
123 const requests: Promise<unknown>[] = []
124 for (const basename of files) {
125 const filename = `${basename}.json`
126 const progressBar = multiBar.create(0, 0, { filename })
127 const request = dataManager.downloadFileToDisk(basename, {
128 onDownloadProgress({ total, loaded, rate }) {
129 if (total) progressBar.setTotal(total)

Callers 1

mainFunction · 0.90

Calls 1

createMethod · 0.65

Tested by

no test coverage detected