Skip to content

Commit

Permalink
adding updated sorce apis
Browse files Browse the repository at this point in the history
  • Loading branch information
datta07 committed Feb 20, 2023
0 parents commit b40c1b3
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn main:app
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Tv Channel Schedule Api
API for Indian Tv channel schedule.

## List of api services:-
/getCategories:-
Json response of languages list and channel categories list.
/searchChannel:-
args:- lang(optional),cate(optional)
Json response of sorted Channels on bases of language and categories.
/TodaySchedule:-
args:- channel
Json response for todays schedule of respective Channel.
/Schedule:-
args:- channel,offset(optional)
offset values as -1 for yesterday,0 for today,1 for tomorrow
Json response for channel schedule on offset day
/GetTodaysMovies:-
args- lang,offset(optional)
offset values as -1 for yesterday,0 for today,1 for tomorrow
Text for particular day movies in a language

## List of Test urls:-
Click here :- https://rapidapi.com/Garuda07/api/indian-tv-schedule


## You can fork the repo and deploy on VPS or deploy it on Heroku :)
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/datta07/tv-channel-schedule-api/tree/master)
13 changes: 13 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Channel-Schedule-Api",
"description": "Api for getting indian Channels dialy schedule",
"keywords": [
"flask",
"python",
"Channels",
"schedule",
"Channel-Schedule"
],
"success_url": "https://github.com/datta07/tv-channel-schedule-api",
"repository": "https://github.com/datta07/tv-channel-schedule-api"
}
58 changes: 58 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from sch import main_fun
from flask import Flask,send_file,current_app,request,jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)


@app.route('/')
def home():
return "generic api services @garudadev.com"

@app.route('/getCategories')
def getCategories():
return jsonify(main_fun.getCategories())

@app.route('/searchChannel')
def searchChannel():
lang,cate=False,False
if ("lang" in request.args):
lang=request.args["lang"]
if ("cate" in request.args):
cate=request.args["cate"]
try:
return jsonify(main_fun.searchChannel(lang,cate))
except Exception as e:
print(str(e))
return "failed:invalid parameters or no parameters,<br>search /getCategories"

@app.route('/TodaySchedule')
def TodaySchedule():
channel=False
offset=0
if ("channel" in request.args):
channel=request.args["channel"]
return jsonify(main_fun.TodaySchedule(channel,offset))

@app.route('/Schedule')
def Schedule():
channel=False
offset=0
if ("channel" in request.args):
channel=request.args["channel"]
if ("offset" in request.args):
offset=request.args["offset"]
return jsonify(main_fun.TodaySchedule(channel,offset))

@app.route('/GetTodaysMovies')
def GetTodaysMovies():
lang=False
offset=0
if ("lang" in request.args):
lang=request.args["lang"]
if ("offset" in request.args):
offset=request.args["offset"]
return main_fun.GetTodaysMovies(lang,offset)

#app.run()
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Flask
gunicorn
requests
flask-cors
33 changes: 33 additions & 0 deletions sch/Details.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- Heroku App for All Channel Schedule:-
(Integrate with github)
- Create a Github public repo on name "all tv channel schedule"
- Create a Heroku app for its deployment "Garudadev


- python file deals with routing (main.py)
- /TodaySchedule?chnl=maatv
- /getCategories
- /searchChannel?lang=Telugu&cate=Movies

- json file for categories (sch/categories.json)

- json file for All Channel list (sch/channel.json)

- python file to update the other json files (sch/update.py)

- python file for all routing functions (sch/main_fun.py)

Folder Structure:-
- Garudadev
-sch
-categories.json
-channel.json
-Details.txt
-updater.py
-main.py
e
"previous schedules will be soon"




Empty file added sch/__init__.py
Empty file.
Binary file added sch/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added sch/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added sch/__pycache__/main_fun.cpython-310.pyc
Binary file not shown.
Binary file added sch/__pycache__/main_fun.cpython-37.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions sch/categories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"categories": {"Entertainment": 5, "Movies": 6, "Kids": 7, "Sports": 8, "Lifestyle": 9, "Infotainment": 10, "Religious": 11, "News": 12, "Music": 13, "Regional": 14, "Devotional": 15, "Business News": 16, "Educational": 17, "Shopping": 18, "Jio Darshan": 19}, "languages": {"Hindi": 1, "Marathi": 2, "Punjabi": 3, "Urdu": 4, "Bengali": 5, "English": 6, "Malayalam": 7, "Tamil": 8, "Gujarati": 9, "Odia": 10, "Telugu": 11, "Bhojpuri": 12, "Kannada": 13, "Assamese": 14, "Nepali": 15, "French": 16}}
1 change: 1 addition & 0 deletions sch/channel.json

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions sch/main_fun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import requests
import json
from threading import Thread
import threading


class ThreadWithReturnValue(Thread):
def __init__(self, group=None, target=None, name=None,args=(), kwargs={}, Verbose=None):
Thread.__init__(self, group, target, name, args, kwargs)
self._return = None
self._stop_event = threading.Event()
def run(self):
#print(type(self._target))
if self._target is not None:
self._return = self._target(*self._args,**self._kwargs)
def join(self, *args):
Thread.join(self, *args)
return self._return
def terminate(self):
self._stop_event.set()

path='sch'
headers={"appkey":"l7xx938b6684ee9e4bbe8831a9a682b8e19f","usergroup":"tvYR7NSNn7rymo3F","User-Agent":"Dalvik/2.1.0 (Linux; U; Android 10.0.0; Redmi 4A Build/OMC28.71-56)"}

def getCategories():
with open(path+'/categories.json','r') as f:
data=json.loads(f.read())
data_json={"categories":list(data["categories"].keys()),"languages":list(data["languages"].keys())}
return data_json# jsonify before sending it

def searchChannel(lang=False,cate=False):
with open(path+'/categories.json','r') as f:
data=json.loads(f.read())
categories,languages=data["categories"],data["languages"]
try:
if (lang):
lang=languages[lang]
except Exception:
return "invalid language search /getCategories"
try:
if (cate):
cate=categories[cate]
except Exception:
return "invalid categories search /getCategories"
with open(path+'/channel.json','r') as f:
data=json.loads(f.read())
data.pop("Updated-on")
data_json=[]
if (lang&cate):
for i in data:
if (data[i]['lang']==lang)&(data[i]['cate']==cate):
data_json.append(i)
elif (lang):
for i in data:
if (data[i]['lang']==lang):
data_json.append(i)
elif (cate):
for i in data:
if (data[i]['cate']==cate):
data_json.append(i)
return data_json

def TodaySchedule(channel=False,offset=0):
with open(path+'/channel.json','r') as f:
data=json.loads(f.read())
try:
channel=data[channel]['id']
except Exception:
return "invalid categories search /searchChannel"
res=requests.get("https://sagraecdnems10.cdnsrv.jio.com/jiotv.data.cdn.jio.com/apis/v1.3/getepg/get?offset="+str(offset)+"&channel_id="+str(channel)+"&langId=6",headers=headers).json()
data_json={}
for i in res['epg']:
data_json[i["showtime"]]={"name":i["showname"],"type":i["showCategory"],"other-details":i["description"]}
return data_json

def GetChannelMovie(i,offset=0):
k={}
res=requests.get("https://sagraecdnems10.cdnsrv.jio.com/jiotv.data.cdn.jio.com/apis/v1.3/getepg/get?offset="+str(offset)+"&channel_id="+str(i)+"&langId=6",headers=headers).json()
for i in res['epg']:
if (i["showCategory"]=="Film"):
k[i["showtime"]+' :- '+res["channel_name"]]=i["showname"]+' ('+i["starCast"]+')'
#data_json[i["showtime"]]={"name":i["showname"],"type":i["showCategory"],"other-details":i["description"]}
return k

def GetTodaysMovies(lang=False,offset=0):
with open(path+'/channel.json','r') as f:
data=json.loads(f.read())
if (not lang):
return "invalid language entry /getCategories"
data.pop("Updated-on")
with open(path+'/categories.json','r') as f:
lang=json.loads(f.read())["languages"][lang]
channels=[]
for i in data:
if (data[i]["lang"]==lang):
if (data[i]["cate"]==6)|(data[i]["cate"]==5):
channels.append(data[i]['id'])
k={}
arr=[]
for no,i in enumerate(channels):
arr.append(ThreadWithReturnValue(target=GetChannelMovie,args=(i,offset)))
arr[no].start()

for i in arr:
temp_k=i.join()
for j in temp_k:
k[j]=temp_k[j]

key=list(k.keys())
key.sort()
matter=''
for i in key:
hin=i+' : '+k[i]+'<br>'
matter+=hin
return matter

33 changes: 33 additions & 0 deletions sch/updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import requests
import json
import time
import os

try:
os.environ['TZ']='Asia/Kolkata'
time.tzset()
except Exception as e:
pass

def RefreshJson():
res=requests.get("https://sagraecdnems05.cdnsrv.jio.com/jiotv.data.cdn.jio.com/apis/v1.3/getMobileChannelList/get/?langId=6&os=android&devicetype=phone&usergroup=tvYR7NSNn7rymo3F&version=6.0.8&langId=6").json()
chnl={}
for i in res['result']:
chnl[i["channel_name"].replace("+"," ")]={"id":i["channel_id"],"lang":i["channelLanguageId"],"cate":i["channelCategoryId"]}
chnl["Updated-on"]=time.strftime("%D-%T")
with open("channel.json","w") as f:
f.write(json.dumps(chnl))
res=requests.get("http://sjpurecdnems05.cdnsrv.jio.com/jiotv.data.cdn.jio.com/apis/v1.3/dictionary/?langId=6&langId=6")
res=json.loads(res.text[1:])
chnlCate={}
for i in res['channelCategoryMapping']:
chnlCate[res['channelCategoryMapping'][i]]=int(i)
chnlLang={}
for i in res['languageIdMapping']:
chnlLang[res['languageIdMapping'][i]]=int(i)
with open("categories.json","w") as f:
f.write(json.dumps({"categories":chnlCate,"languages":chnlLang}))

RefreshJson()


0 comments on commit b40c1b3

Please sign in to comment.