Created
November 4, 2023 00:04
-
-
Save Fortyseven/4bec2965f7c54a7f14ccbef5660d06b0 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env python | |
import argparse | |
# yes we could just slot in the country code but I wanted to | |
# do more with this, and I get the benefit of a dict with the | |
# valid entries in it | |
PLAYLISTS_BY_COUNTRY = { | |
"au": "https://iptv-org.github.io/iptv/countries/au.m3u", | |
"cn": "https://iptv-org.github.io/iptv/countries/cn.m3u", | |
"de": "https://iptv-org.github.io/iptv/countries/de.m3u", | |
"es": "https://iptv-org.github.io/iptv/countries/es.m3u", | |
"fr": "https://iptv-org.github.io/iptv/countries/fr.m3u", | |
"it": "https://iptv-org.github.io/iptv/countries/it.m3u", | |
"jp": "https://iptv-org.github.io/iptv/countries/jp.m3u", | |
"kp": "https://iptv-org.github.io/iptv/countries/kp.m3u", | |
"kr": "https://iptv-org.github.io/iptv/countries/kr.m3u", | |
"ru": "https://iptv-org.github.io/iptv/countries/ru.m3u", | |
"uk": "https://iptv-org.github.io/iptv/countries/uk.m3u", | |
"us": "https://iptv-org.github.io/iptv/countries/us.m3u", | |
} | |
# execute vlc with the playlist | |
def vlc(playlist): | |
# spawn shell and then return leaving the child running | |
import subprocess | |
subprocess.Popen(["vlc", playlist]) | |
return | |
# take arguments | |
parser = argparse.ArgumentParser( | |
description="Watch TV channels from different countries" | |
) | |
# two letter code required if not --list | |
parser.add_argument( | |
"country", metavar="C", type=str, nargs="*", help="two letter country code" | |
) | |
# list all the countries | |
parser.add_argument("--list", action="store_true", help="list all the countries") | |
args = parser.parse_args() | |
# if --list is passed, list all the countries | |
if args.list: | |
for country in PLAYLISTS_BY_COUNTRY: | |
print(country) | |
exit(0) | |
# if country is not in the list, exit | |
if args.country[0] not in PLAYLISTS_BY_COUNTRY: | |
print("Country not found") | |
exit(1) | |
# if country is in the list, execute vlc with the playlist | |
vlc(PLAYLISTS_BY_COUNTRY[args.country[0]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment