Roshan-R / termv

A terminal iptv player written in bash
GNU General Public License v3.0
222 stars 19 forks source link

[Feature] Provide option for quick (initial) filtering by Country/ Category, etc #4

Closed LaurentFough closed 2 years ago

LaurentFough commented 3 years ago

@Roshan-R; great project.

I see the original json files have some sorting already.

I'm just trying to envision the tui options for allowing for allowing users search & select using those pre-sorted files.

Roshan-R commented 3 years ago

Glad you liked the project @LaurentFough !

This feature was on my mind for a long time but I'm not sure on how to implement the following things-

Downloading JSONs

Screenshot from 2021-04-27 12-29-04

This makes the script download only the jsons corresponding to categories/language/country the user selects.

Another implementation i could think of is to download all the jsons the fist time the user executes the scipt, but this would mean the first time setup would take a lot of time to download all the jsons.

Using this feature

This would also mean we would need to implement the feature of adding/removing which all categories/language/country the user likes and would probably need to make a config file for the script.

Moreover, these questions need to be addressed

What should be the default behavior of the script? I'm of the opinion that the default behavior would be to show all the available channels. The user can then sort using command line flags

eg. termv -l would open an fzf menu to select a language image

I'm sure there are better ways to implement this, let me know if you have something in mind :smile:

Kabouik commented 3 years ago
* **downloading all the jsons initially**

Another implementation i could think of is to download all the jsons the fist time the user executes the scipt, but this would mean the first time setup would take a lot of time to download all the jsons.

I would vote for that, and a posteriori filtering which would give the user more flexibility. I think the initial download is rather quick anyway, it took only a few seconds every time I downloaded it. An option to update the file might be useful by the way, currently I think it can only be redownloaded by deleting the original file, whose path is not exactly clear to a user who would not understand Bash or even open termv executable in an editor.

Kabouik commented 3 years ago

I'm of the opinion that the default behavior would be to show all the available channels. The user can then sort using command line flags

eg. termv -l would open an fzf menu to select a language image

I'm sure there are better ways to implement this, let me know if you have something in mind smile

As a simple user, I like it! Like you, I believe the default should show all, users are free to set aliases if they want (and the README could show an example).

Language is only one of many filters users may want to use (georestrictions make country filtering very useful too for instance), and adding specific options for all relevant filters may add unnecessary complexity. Maybe a more generic --filter, -f option could be used. Something that could be used like termv -f "language=eng", but also with multiple filters like termv -f "country=uk language=eng category=sport".

Using country codes instead of names should be easier, shorter and more compatible (no spaces) and I see they are already in the json file. Same with languages, abbreviations are already in the file. Similarly, would be great if all filters could be case-insensitive. I'm not sure how to do that, but I imagine it should be relatively straightforward with fzf, jq or some Bash magic?

The help could list all available filters and an example. If filters are not set in the command but -f is used, then the filters could be set interactively with fzf, first showing all available filters, and then all possible values within the filter selected (full names this time, like "United Kingdom" and "English" instead of "uk" and "eng", respectively, in a way similar to what your screenshot shows). This would only allow one filter at a time but wouldn't it be acceptable if not manually setting them in command line?

Roshan-R commented 3 years ago
* **downloading all the jsons initially**

Another implementation i could think of is to download all the jsons the fist time the user executes the scipt, but this would mean the first time setup would take a lot of time to download all the jsons.

I would vote for that, and a posteriori filtering which would give the user more flexibility. I think the initial download is rather quick anyway, it took only a few seconds every time I downloaded it. An option to update the file might be useful by the way, currently I think it can only be redownloaded by deleting the original file, whose path is not exactly clear to a user who would not understand Bash or even open termv executable in an editor.

Yeah, there should be an option to update the file by some kind of argument like -u. We could download the new file into a temporary directory and replace the old one with the new one. I'm not sure if we can check for updates on the json without downloading it again, I'll open a new Issue about updating the json

About the initial downloads, I rechecked the iptv repo and there's only one json file there, the one we're using right now. Rest of them are m3u files. I feel we could do something like cat channels.json | jq '.[] | select(.category=="Movies").name ' on the existing json file to filter stuff.

odnar-dev commented 3 years ago

what about using something like this

cat "channels.json" | jq -r '.[] | "\(.name) : [\(.category)] -- [\(.languages|.[].name)]  -- \(.url)"' | \
fzf --cycle --header="Select channel (press Escape to exit)" --with-nth='1..-3' -e | awk '{print $NF}'

image

Kabouik commented 3 years ago

That looks cool! Also minimal and yet efficient, while the interactive menus above may be more fancy but harder to implement I assume. I would just remove the unnecessary colons and hyphens to declutter, and add another pair of brackets for Country because I think most 404 errors are due to georestricted content. But I'm just one user.