freearhey / iptv-checker

Node.js CLI tool for checking links in IPTV playlists
MIT License
517 stars 82 forks source link

Feature: Extend for modular compatibility #13

Closed detroitenglish closed 4 years ago

detroitenglish commented 4 years ago

I'd love to utilize this package as a module in other scripts in addition to its current form as a standalone CMD tool.

My basic idea as a module would be to accept e.g. an array of items from iptv-playlist-parser, process them with ffprobe, append status info and metadata to each item, and finally return the array of freshly-checked items.

Of course, nothing would change if called via command line. But if it's requireed by another script, it'll, for example, disable everything file-system related.

Here's a working example branch. Run npm run module-example, and a script will pass an array of items, and a URL into two imported iptv-checker instances respectively.

I guess the most important question is: do you want to work together on this, or would you rather I forked and created a separate package?

I'm fine with either - your repo, your call! 😎

freearhey commented 4 years ago

I think it's a great idea and this module can really be very useful.

Also, if you decide to include iptv-playlist-parser in the future we can just use it as a core for iptv-checker itself.

So if I were you, I would really make a hard fork and create a separate package based on it. In this way, you will be able to get rid of a lot of unnecessary code at once and make things more straightforward.

detroitenglish commented 4 years ago

Took an initial stab at it: https://github.com/detroitenglish/iptv-checker-module

Taking a second look, though, I see it's probably smarter to include iptv-playlist-parser, and parse a String or Buffer passed in as the first parameter... it was way too late at night when I wrote that code

detroitenglish commented 4 years ago

Taking a second look, though, I see it's probably smarter to include iptv-playlist-parser, and parse a String or Buffer passed in as the first parameter...

Just updated to to v1.0, which now parses a file path, URL or playlist data buffer passed in as first parameter

freearhey commented 4 years ago

Yeah, I noticed. I was just starting to investigate your code.

freearhey commented 4 years ago

I just tried to install iptv-checker-module but unfortunately this is not possible at this time.

The point is that the playlist check can often last for hours, but the current version does not allow to monitor the progress of the check. So it's impossible not to display the progress of the bar, or keep a log. Also, in case of some error during the check, all the results will be simply erased.

I thought that the solution might be to use EventEmitter so that the module would trigger events after each verified channel, something like this:

const checker = iptvChecker('path/to/file.m3u')

checker.on('item', item => {
  // log result
})

but I just couldn't figure out how to implement it in the current version of code.

Although perhaps you can find some other solution to this problem. If so, then let me know and I'll try again.

detroitenglish commented 4 years ago

Great idea! But I don't believe event listening is the right choice, as the module itself is an async function that's likely to be awaited. Setting event listeners is unnecessarily complicated in that case.

What do you think about adding an itemCallback option, which accepts a function to run after each finished item, called with the item as first parameter?


const logger = item => {
  // log result
}

await iptvChecker('path/to/file.m3u', { itemCallback: logger })
freearhey commented 4 years ago

Looks great to me 😁👍

detroitenglish commented 4 years ago

Added in v1.2.0! 👍

detroitenglish commented 4 years ago

@freearhey BTW I just emailed your Gmail account, regarding the module's package maintenance

freearhey commented 4 years ago

Version 0.16.0 officially released 🎉

Thank you again for your help!