Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready for another rewrite [v2.0] #39

Open
odnar-dev opened this issue Jun 18, 2023 · 11 comments
Open

Ready for another rewrite [v2.0] #39

odnar-dev opened this issue Jun 18, 2023 · 11 comments

Comments

@odnar-dev
Copy link
Contributor

hi @Roshan-R ,
i think we can't add new features to termv in it current form, without a whole rewrite.

for now, termv act as a terminal client for iptv-org channels, i think the first step is to make termv independent from iptv-org and that by introducing our own format for files.
for this we can use json file or a simple text file with .termv extension
and store data in it like this: name \t category \t language \t countries \t channelsUrl

random name 	 News 	 English 	 Spain 	 http://domain.com/path/channel.m3u8
listen.moe 	 Radio 	 N/A 	 N/A 	 https://listen.moe/stream

with this, we can add the support of multiple sources with different formats, cause we can download the file process it and convert it into our own format. and also the user can create his own channels list easily by creating a file with .termv extension.

the source list can be loaded form config file with this parameters : source_name, source_url and source_type

"iptv_org_m3u8" "https://iptv-org.github.io/iptv/index.m3u" "m3u8"
"cn_cgtn.m3u" "https://raw.githubusercontent.com/iptv-org/iptv/master/streams/cn_cgtn.m3u" "m3u8"

we will use the source_url to download file from , use source_name as file_name, then call process function based on source_type.
image

image

i created a m3u8 parser using only bash functions, but it slow in large files.

@Roshan-R
Copy link
Owner

Hey @odnar-dev

I do think that we could have a rewrite of termv, development has slowed down very much due it not being exiting anymore.
Creating a new format for termv sound fun, and I'm really intrested in doing so.

I'll take a look into this issue and post my thoughts here when I get time

@Roshan-R
Copy link
Owner

I've looked into the issue and yeah, making a new format for termv looks promising. A tab seperated .termv file would be best i think instead of using json.
I'll be looking more into how to parse m3u8 files and see how it plays with out idea.

@odnar-dev
Copy link
Contributor Author

odnar-dev commented Nov 8, 2023

hi @Roshan-R , looks like i forget about this 😄
well if you still want to brainstorm some ideas , and pick this up let me know , and i will share with u my progress

@Roshan-R
Copy link
Owner

Roshan-R commented Nov 8, 2023

Yes, I'd love to do that @odnar-dev, I'll be looking into this and will be sharing my progress

@odnar-dev
Copy link
Contributor Author

so here is the m3u8 parser i told u about, you give it a m3u8 file

#!/usr/bin/env bash

# m3u8 related
parse_playlist_m3u8(){
	local filepath="$@"

	IFS= read -r first_line < "${filepath:?}"
	case "${first_line}" in
		"#EXTM3U"*) printf '%s' "(valide)";;
		*) { prnt_err "${filepath:?} don't have a valide m3u8 header" ; return 1 ;};;
	esac

	while read -r line; do
		case "$line" in
			"#EXTINF"*)
				declare -A metadata=( )
				metadata[tv-name]="${line##*,}"
				metadata[tv-name]="${metadata[tv-name]%%[[:cntrl:]]}"
				metadata[tv-name]="$(echo ${metadata[tv-name]} | tr -d '\r')"

				local other_metadata="${line%%,*}"
				local other_metadata="${other_metadata#* }"
				
				while IFS="=" read -r key val; do
					[ "${key##\#*}" ] || continue
					metadata[${key}]="${val//\"}"
				done < <(printf '%s\n' ${other_metadata:-} )
				;;
			"#EXTVLCOPT"*|"#KODIPROP"*|"# ")
				;;
			*)
				[ -z "${metadata[tv-name]}" ] && continue
				[ -z "${line}" ] && continue
				
				#[ -z "${metadata[tv-glanguage]}" ] && metadata[tv-glanguage]="${metadata[tvg-language]}"
				#[ -z "${metadata[tv-gcountry]}" ] && metadata[tv-gcountry]="${metadata[tvg-country]}"

				printf '%s \t %s \t %s \t %s \t %s\n' "${metadata[tv-name]:?}" "${metadata[group-title]:-N/A}" "${metadata[tv-glanguage]:-N/A}" "${metadata[tv-gcountry]:-N/A}" "${line:?}"
				declare -A metadata=( )
				;;
		esac
	done < "$filepath"
}

parse_playlist_m3u8 "${@:?}"

@odnar-dev
Copy link
Contributor Author

check out the repo https://github.com/odnar-dev/termv-rewrite
i just uploaded my full progress, and here you can see the whole idea and how it gonna work

git clone --depth 1 https://github.com/odnar-dev/termv-rewrite
cd ./termv-rewrite
chmod +x ./termv
./termv

@Roshan-R
Copy link
Owner

I'm taking a look into the code and it seems to be a big change with what we have so far, I'll review and put my thoughts here once I go through it

@Roshan-R
Copy link
Owner

Roshan-R commented Nov 13, 2023

I'm pretty sure we could use awk to parse the m3u8 files, I've been working on that. Couple of things to note

  1. Iptv-org m3u files only have one category in each file, so if a user gives the category as sports, no other category would be filterable. This would prove to be a limitation of this new version
  2. What to do when duplicate channels are found, when using more than one source for the data

@odnar-dev
Copy link
Contributor Author

i just wanted to try to create a pure bash m3u8 , just to see if it would work 😄

  1. the idea here is to just to make termv independent from IPTV-ORG format, we can always add back the support for the iptv-org json format and make it optional.

  2. what type of duplication are you talking about, if you mean duplicated lines (same channel with the same link) can be removed easily, but if you talking about same channel with different link, i think we should keep those

@Roshan-R
Copy link
Owner

As you said, I feel it would be better if we keep the existing iptv-org json format and then allow users to create .termv files on top of the data source. Most users would be satisfied by just the channels in the iptv-org json

About same channel with different links, I feel we should keep both but find a way to differentiate the two in the fzf dialog. something to think about

I'm very much liking the new direction you are proposing for termv.

@boredness
Copy link

boredness commented May 16, 2024

Hopefully supporting personal playlists gets implemented in your rewrite @Roshan-R. I'd be very interested and I think it would make this more widely used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants