Skip to content

Commit

Permalink
Merge pull request #43 from krreet/feature/support-for-catchup
Browse files Browse the repository at this point in the history
OS-001 added 8 days epg generation
  • Loading branch information
krreet committed Mar 5, 2023
2 parents acdef35 + 7200b12 commit 6a1c5e0
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 13 deletions.
148 changes: 147 additions & 1 deletion resources/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,152 @@
CATCHUP_SRC = "https://jiotv.data.cdn.jio.com/apis/v1.3/getepg/get?offset={0}&channel_id={1}&langId=6"
M3U_SRC = os.path.join(translatePath(
ADDON.getAddonInfo("profile")), "playlist.m3u")
EPG_PATH = os.path.join(translatePath(
ADDON.getAddonInfo("profile")), "jiotv-epg.xml.gz")
M3U_CHANNEL = "\n#EXTINF:0 tvg-id=\"{tvg_id}\" tvg-name=\"{channel_name}\" group-title=\"{group_title}\" tvg-chno=\"{tvg_chno}\" tvg-logo=\"{tvg_logo}\"{catchup},{channel_name}\n{play_url}"
EPG_SRC = "https://kodi.botallen.com/tv/epg.xml.gz"
DICTIONARY_URL = "https://jiotvapi.cdn.jio.com/apis/v1.3/dictionary/dictionary?langId=6"
DICTIONARY_URL = "https://jiotvapi.cdn.jio.com/apis/v1.3/dictionary/dictionary?langId=6"

IMG_CONFIG = {
"Genres": {
"Entertainment": {
"tvImg": IMG_PUBLIC + "38/52/Entertainment_1584620980069_tv.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/Entertainment_1579245819981.jpg",
},
"Movies": {
"tvImg": IMG_PUBLIC + "logos/langGen/movies_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/movies_1579517470920.jpg",
},
"Kids": {
"tvImg": IMG_PUBLIC + "logos/langGen/kids_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/kids_1579517470920.jpg",
},
"Sports": {
"tvImg": IMG_PUBLIC + "logos/langGen/Sports_1579245819981.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/Sports_1579245819981.jpg",
},
"Lifestyle": {
"tvImg": IMG_PUBLIC + "logos/langGen/lifestyle_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/lifestyle_1579517470920.jpg",
},
"Infotainment": {
"tvImg": IMG_PUBLIC + "logos/langGen/infotainment_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/infotainment_1579517470920.jpg",
},
# "Religious": {
# "tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# "promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# },
"News": {
"tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
},
"Music": {
"tvImg": IMG_PUBLIC + "logos/langGen/Music_1579245819981.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/Music_1579245819981.jpg",
},
# "Regional": {
# "tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# "promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# },
"Devotional": {
"tvImg": IMG_PUBLIC + "logos/langGen/devotional_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/devotional_1579517470920.jpg",
},
"Business News": {
"tvImg": IMG_PUBLIC + "logos/langGen/business_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/business_1579517470920.jpg",
},
"Educational": {
"tvImg": IMG_PUBLIC + "logos/langGen/educational_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/educational_1579517470920.jpg",
},
"Shopping": {
"tvImg": IMG_PUBLIC + "logos/langGen/shopping_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/shopping_1579517470920.jpg",
},
"Jio Darshan": {
"tvImg": IMG_PUBLIC + "logos/langGen/jiodarshan_1579517470920.jpg",
"promoImg": IMG_PUBLIC + "logos/langGen/jiodarshan_1579517470920.jpg",
}
},
"Languages": {
"Hindi": {
"tvImg": IMG_PUBLIC + "logos/langGen/Hindi_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"98/98/Hindi_1580458058289_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528144026.jpg"
},
"Marathi": {
"tvImg": IMG_PUBLIC + "logos/langGen/Marathi_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"30/23/Marathi_1580458084801_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528755040_s.jpg"
},
"Punjabi": {
"tvImg": IMG_PUBLIC + "logos/langGen/Punjabi_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"79/58/Punjabi_1580458722849_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/2105281190010_s.jpg"
},
"Urdu": {
# "tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# "promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/urdu1.jpg"
},
"Bengali": {
"tvImg": IMG_PUBLIC + "logos/langGen/Bengali_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"72/66/Bengali_1580459416363_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/2105281369026_s.jpg"
},
"English": {
"tvImg": IMG_PUBLIC + "logos/langGen/English_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"52/8/English_1580458071796_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/Friends_Carousal.jpg"
},
"Malayalam": {
"tvImg": IMG_PUBLIC + "logos/langGen/Malayalam_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"67/0/Malayalam_1580459753008_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/2105281221000_s.jpg"
},
"Tamil": {
"tvImg": IMG_PUBLIC + "logos/langGen/Tamil_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"58/79/Tamil_1580458708325_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528429019.jpg"
},
"Gujarati": {
"tvImg": IMG_PUBLIC + "logos/langGen/Gujarati_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"41/66/Gujarati_1580459392856_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528196027.jpg"
},
"Odia": {
"tvImg": IMG_PUBLIC + "logos/langGen/Odia_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"67/0/Odia_1580459753008_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528722020.jpg"
},
"Telugu": {
"tvImg": IMG_PUBLIC + "logos/langGen/Telugu_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"89/86/Telugu_1580458096736_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528638024.jpg"
},
"Bhojpuri": {
"tvImg": IMG_PUBLIC + "logos/langGen/Bhojpuri_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"87/70/Bhojpuri_1580459428665_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/210528532010.jpg"
},
"Kannada": {
"tvImg": IMG_PUBLIC + "logos/langGen/Kannada_1579245819981.jpg",
"promoImg": IMG_PUBLIC+"37/41/Kannada_1580458557594_promo.jpg",
"image": IMG_CATCHUP_SHOWS + "cms/2105281370026.jpg"
},
"Assamese": {
# "tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# "promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
},
"Nepali": {
# "tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# "promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
},
"French": {
# "tvImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
# "promoImg": IMG_PUBLIC + "logos/langGen/news_1579517470920.jpg",
}
}
}
80 changes: 69 additions & 11 deletions resources/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from codequick.storage import PersistentDict

# add-on imports
from resources.lib.utils import getTokenParams, getHeaders, isLoggedIn, login as ULogin, logout as ULogout, check_addon, sendOTPV2, get_local_ip, getChannelHeaders, quality_to_enum, _setup, kodi_rpc, Monitor
from resources.lib.constants import GET_CHANNEL_URL, FEATURED_SRC, CHANNELS_SRC, IMG_CATCHUP, PLAY_URL, IMG_CATCHUP_SHOWS, CATCHUP_SRC, M3U_SRC, EPG_SRC, M3U_CHANNEL, DICTIONARY_URL
from resources.lib.utils import getTokenParams, getHeaders, isLoggedIn, login as ULogin, logout as ULogout, check_addon, sendOTPV2, get_local_ip, getChannelHeaders, quality_to_enum, _setup, kodi_rpc, Monitor, busy
from resources.lib.constants import GET_CHANNEL_URL, FEATURED_SRC, CHANNELS_SRC, IMG_CATCHUP, PLAY_URL, IMG_CATCHUP_SHOWS, CATCHUP_SRC, M3U_SRC, EPG_SRC, M3U_CHANNEL, DICTIONARY_URL, IMG_CONFIG, EPG_PATH

# additional imports
import urlquick
Expand All @@ -25,6 +25,10 @@
from time import time, sleep
from datetime import datetime, timedelta, date
import m3u8
import requests
import gzip
import xml.etree.ElementTree as ET
import os

# Root path of plugin

Expand Down Expand Up @@ -147,13 +151,17 @@ def show_listby(plugin, by):
"Languages": langValues,
}
for each in CONFIG[by]:
tvImg = IMG_CONFIG[by].get(each, {}).get("tvImg", ""),
promoImg = IMG_CONFIG[by].get(each, {}).get("promoImg", "")
image = IMG_CONFIG[by].get(each, {}).get("image", tvImg),
yield Listitem.from_dict(**{
"label": each,
# "art": {
# "thumb": each.get("tvImg"),
# "icon": each.get("tvImg"),
# "fanart": each.get("promoImg")
# },
"art": {
"thumb": tvImg,
"icon": tvImg,
"fanart": promoImg,
"banner": image
},
"callback": Route.ref("/resources/lib/main:show_category"),
"params": {"categoryOrLang": each, "by": by}
})
Expand Down Expand Up @@ -418,6 +426,7 @@ def setmobile(plugin):
monitor.waitForAbort(1)
Script.notify("Jio number set", "")


@Script.register
def applyall(plugin):
ADDON_ID = 'plugin.video.jiotv'
Expand All @@ -439,7 +448,6 @@ def logout(plugin):

# M3u Generate `route`
@Script.register
@isLoggedIn
def m3ugen(plugin, notify="yes"):
channels = urlquick.get(CHANNELS_SRC).json().get("result")
r = urlquick.get(DICTIONARY_URL).text.encode('utf8')[3:].decode('utf8')
Expand Down Expand Up @@ -485,6 +493,56 @@ def m3ugen(plugin, notify="yes"):
"JioTV", "Playlist updated.")


# EPG Generate `route`
@Script.register
def epg_setup(plugin):
Script.notify("Please wait", "Epg setup in progress")
with busy():
# Download EPG XML file
url = 'https://raw.githubusercontent.com/mitthu786/tvepg/main/epg.xml.gz'
payload = {}
headers = {}
proxies = {
"http": "http://103.216.160.163:80",
"https": "http://104.223.135.178:10000",
}

response = requests.request(
"GET", url, headers=headers, data=payload, proxies=proxies)
with open(EPG_PATH, 'wb') as f:
f.write(response.content)
# for chunk in response.iter_content(chunk_size=1024):
# if chunk:
# f.write(chunk)
# Extract and parse the XML file
with gzip.open(EPG_PATH, 'rb') as f:
data = f.read()
xml_content = data.decode('utf-8')
root = ET.fromstring(xml_content)
# Modify all the programs in the EPG
# programs = root.findall('./programme')
for program in root.iterfind(".//programme"):
# Example: Modify the program and add catchupid
icon = program.find('icon')
icon_src = icon.get('src')
jpg_name = icon_src.rsplit('/', 1)[-1]
catchup_id = os.path.splitext(jpg_name)[0]
program.set('catchup-id', catchup_id)
title = program.find('title')
title.text = title.text.strip()

# create the XML declaration and add it to the top of the file
xml_declaration = '<?xml version="1.0" encoding="UTF-8"?>\n'

# create the doctype declaration
doctype_declaration = '<!DOCTYPE tv SYSTEM "xmltv.dtd">\n'
new_xml_content = xml_declaration + doctype_declaration + ET.tostring(root, encoding='unicode')
# create the root element and set its attributes
with gzip.open(EPG_PATH, 'wt') as f:
f.write(new_xml_content)
Script.notify("JioTV", "Epg generated,Now setup iptv pvr")


# PVR Setup `route` to access from Settings
@Script.register
def pvrsetup(plugin):
Expand All @@ -498,12 +556,12 @@ def set_setting(id, value):
if check_addon(IDdoADDON):
set_setting("m3uPathType", "0")
set_setting("m3uPath", M3U_SRC)
set_setting("epgPathType", "1")
set_setting("epgUrl", EPG_SRC)
set_setting("epgPathType", "0")
set_setting("epgPath", EPG_PATH)
set_setting("catchupEnabled", "true")
set_setting("catchupWatchEpgBeginBufferMins", "0")
set_setting("catchupWatchEpgEndBufferMins", "0")
_setup(M3U_SRC, EPG_SRC)
_setup(M3U_SRC, EPG_PATH)


# Cache cleanup
Expand Down
4 changes: 3 additions & 1 deletion resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def login(username, password, mode="unpw"):
headers.update(_CREDS)
with PersistentDict("headers") as db:
db["headers"] = headers
db["exp"] = time.time() + 432000
# db["exp"] = time.time() + 432000
db["exp"] = time.time() + 31536000
if mode == "unpw":
db["username"] = username
db["password"] = password
Expand Down Expand Up @@ -392,5 +393,6 @@ def _setup(m3uPath, epgUrl):
set_kodi_setting('pvrmanager.preselectplayingchannel', True)
set_kodi_setting('pvrmanager.backendchannelorder', True)
set_kodi_setting('pvrmanager.usebackendchannelnumbers', True)
Script.notify("IPTV setup", "epg and playlist updated")

return True
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</category>
<category label="Setup">
<setting label="Setup Simple IPTV PVR" type="action" id="pvrsetup" action="RunPlugin(plugin://plugin.video.jiotv/resources/lib/main/pvrsetup/)" option="close"/>
<setting label="Setup EPG" type="action" id="epgsetup" action="RunPlugin(plugin://plugin.video.jiotv/resources/lib/main/epg_setup/)"/>
<setting id="m3ugen" type="bool" label="Generate Playlist On Startup" default="true"/>
<!-- <setting id="extraPl" type="text" label="Extra Playlist"/> -->
<setting id="applyAllSettings1" type="action" label="Apply all settings" action="RunPlugin(plugin://plugin.video.jiotv/resources/lib/main/applyall/)" option="close"/>
Expand Down

0 comments on commit 6a1c5e0

Please sign in to comment.