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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, redirect, url_for
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
from base64 import b64decode
|
| 5 |
+
from Crypto.Cipher import AES
|
| 6 |
+
from Crypto.Util.Padding import unpad
|
| 7 |
+
|
| 8 |
+
app = Flask(__name__,static_url_path='/static', static_folder='static')
|
| 9 |
+
|
| 10 |
+
def homeFetch():
|
| 11 |
+
response = requests.get('https://www.shemaroome.com/')
|
| 12 |
+
soup = BeautifulSoup(response.text,features="html5lib")
|
| 13 |
+
|
| 14 |
+
# fetches all slider images
|
| 15 |
+
slider = soup.find_all("div",{"class": "masthead-card"})
|
| 16 |
+
sliderImages = []
|
| 17 |
+
for element in slider:
|
| 18 |
+
tempImage = element.find("img")
|
| 19 |
+
sliderImages.append(tempImage['src'])
|
| 20 |
+
|
| 21 |
+
# fetches all catagories with images
|
| 22 |
+
catagory = soup.find_all("div",{"class": "float-left w-100 slick-container slick-gap"})
|
| 23 |
+
catagoryObject =[]
|
| 24 |
+
for element in catagory:
|
| 25 |
+
tempTitle = element.find("h2")
|
| 26 |
+
if tempTitle != None:
|
| 27 |
+
tempTitle = str(tempTitle).split(">")[1].split("<")[0]
|
| 28 |
+
tempImages = element.find_all("a")
|
| 29 |
+
tempImagesArr = []
|
| 30 |
+
for image in tempImages:
|
| 31 |
+
try:
|
| 32 |
+
imgLink = image.find("img")["src"]
|
| 33 |
+
except:
|
| 34 |
+
imgLink = ""
|
| 35 |
+
tempImagesArr.append([image["href"],imgLink])
|
| 36 |
+
catagoryObject.append([tempTitle,tempImagesArr])
|
| 37 |
+
return sliderImages,catagoryObject
|
| 38 |
+
|
| 39 |
+
def movieDetailFetch(title):
|
| 40 |
+
response = requests.get('https://www.shemaroome.com/'+title)
|
| 41 |
+
soup = BeautifulSoup(response.text,features="html5lib")
|
| 42 |
+
pathList = []
|
| 43 |
+
pathsContainer = soup.find("section",{"class": "main-content"})
|
| 44 |
+
paths = pathsContainer.find("ul").find_all("li")
|
| 45 |
+
for path in paths:
|
| 46 |
+
if path.find("a"):
|
| 47 |
+
pathList.append([path.find("a")["href"],path.text.strip()])
|
| 48 |
+
|
| 49 |
+
title = soup.find("h1",{"class": "float-left w-100 app-color1 font-black margin-bottom-10 section-title2"}).text
|
| 50 |
+
|
| 51 |
+
catagoriesArr = []
|
| 52 |
+
|
| 53 |
+
catagories = soup.find_all("li",{"class":"float-left font-regular app-color5 app-color1"})
|
| 54 |
+
for catagory in catagories:
|
| 55 |
+
catagoriesArr.append(catagory.text.strip())
|
| 56 |
+
|
| 57 |
+
movieDataArr = []
|
| 58 |
+
|
| 59 |
+
Synopsis = soup.find_all("p",{"class":"float-left w-100 app-color1 font-regular"})
|
| 60 |
+
for data in Synopsis:
|
| 61 |
+
movieDataArr.append(data.text.strip())
|
| 62 |
+
|
| 63 |
+
youMayLikeArr = []
|
| 64 |
+
|
| 65 |
+
youMayLikeContainer = soup.find("div",{"class":"float-left w-100 app-slick-slider-container"})
|
| 66 |
+
youMayLike = youMayLikeContainer.find_all("a")
|
| 67 |
+
for data in youMayLike:
|
| 68 |
+
youMayLikeArr.append([data["href"],data.find("img")["src"]])
|
| 69 |
+
|
| 70 |
+
return {"pathList":pathList,"title":title,"catagoriesArr":catagoriesArr,"movieDataArr":movieDataArr,"youMayLikeArr":youMayLikeArr}
|
| 71 |
+
|
| 72 |
+
def showDetailFetch(title):
|
| 73 |
+
response = requests.get('https://www.shemaroome.com/'+title)
|
| 74 |
+
soup = BeautifulSoup(response.text,features="html5lib")
|
| 75 |
+
|
| 76 |
+
pathsContainer = soup.find("section",{"class": "main-content"})
|
| 77 |
+
paths = pathsContainer.find("ul").find_all("li")
|
| 78 |
+
pathList = []
|
| 79 |
+
for path in paths:
|
| 80 |
+
if path.find("a"):
|
| 81 |
+
pathList.append([path.find("a")["href"],path.text.strip()])
|
| 82 |
+
|
| 83 |
+
title = soup.find("h1",{"class": "float-left w-100 app-color1 font-black margin-bottom-10 section-title2"}).text.strip()
|
| 84 |
+
|
| 85 |
+
catagories = soup.find_all("li",{"class":"float-left font-regular app-color5"})
|
| 86 |
+
catagoriesArr = []
|
| 87 |
+
for catagory in catagories:
|
| 88 |
+
catagoriesArr.append(catagory.text.strip())
|
| 89 |
+
|
| 90 |
+
Synopsis = soup.find_all("p",{"class":"float-left w-100 app-color1 font-regular"})
|
| 91 |
+
movieDataArr = []
|
| 92 |
+
for data in Synopsis:
|
| 93 |
+
movieDataArr.append(data.text.strip())
|
| 94 |
+
|
| 95 |
+
episodeContainer = soup.find_all("div",{"class":"float-left w-100 app-slick-slider-container"})[0]
|
| 96 |
+
episodes = episodeContainer.find_all("a")
|
| 97 |
+
episodesArr = []
|
| 98 |
+
for episode in episodes:
|
| 99 |
+
episodesArr.append([episode["href"],episode.find("img")["src"]])
|
| 100 |
+
|
| 101 |
+
youMayLikeContainer = soup.find_all("div",{"class":"float-left w-100 app-slick-slider-container"})[1]
|
| 102 |
+
youMayLike = youMayLikeContainer.find_all("a")
|
| 103 |
+
youMayLikeArr = []
|
| 104 |
+
for data in youMayLike:
|
| 105 |
+
youMayLikeArr.append([data["href"],data.find("img")["src"]])
|
| 106 |
+
|
| 107 |
+
poster = soup.find("div",{"class":"player_section w-100 embed-responsive embed-responsive-16by9"}).find("img")["src"]
|
| 108 |
+
return {"pathList":pathList,"title":title,"catagoriesArr":catagoriesArr,"movieDataArr":movieDataArr,"episodesArr":episodesArr,"youMayLikeArr":youMayLikeArr,"poster":poster}
|
| 109 |
+
|
| 110 |
+
def decryptLink(encrypted,key,type):
|
| 111 |
+
key = b64decode(key)
|
| 112 |
+
iv = b'0000000000000000'
|
| 113 |
+
ct = b64decode(encrypted)
|
| 114 |
+
cipher = AES.new(key, AES.MODE_CBC, iv)
|
| 115 |
+
pt = unpad(cipher.decrypt(ct), AES.block_size)
|
| 116 |
+
link = pt.decode()
|
| 117 |
+
tempUrl = "https://d1fcqrzxghru70.cloudfront.net/"+link.split("cloudfront.net/")[1]
|
| 118 |
+
response = requests.request("GET", tempUrl)
|
| 119 |
+
tempArr = response.text.split("RESOLUTION=")
|
| 120 |
+
tempArr.pop(0)
|
| 121 |
+
tempUrl2 = '/'.join(tempUrl.split("/")[:-1])
|
| 122 |
+
if type == "movie":
|
| 123 |
+
resolutionLink = tempUrl2+"/"+tempArr[0].split("\n")[-2]
|
| 124 |
+
else:
|
| 125 |
+
resolutionLink = tempUrl2+"/"+tempArr[0].split("\n")[-2]
|
| 126 |
+
return resolutionLink
|
| 127 |
+
|
| 128 |
+
def stremKeyAPI(catalog_id,content_id,item_category,content_definition):
|
| 129 |
+
url = "https://www.shemaroome.com/users/user_all_lists"
|
| 130 |
+
payload = 'catalog_id='+catalog_id+'&content_id='+content_id + \
|
| 131 |
+
'&category='+item_category+'&content_def='+content_definition
|
| 132 |
+
response = requests.request("POST", url, data=payload)
|
| 133 |
+
try:
|
| 134 |
+
return {"streamKey":response.json()['stream_key'],"key":response.json()['key'],"newPlayUrl":response.json()['new_play_url'],"ios_key":response.json()['ios_key'],"ios_play_url":response.json()['ios_play_url'],"subtitle":response.json()['subtitle']}
|
| 135 |
+
except:
|
| 136 |
+
return {"error":"There's an error in data."}
|
| 137 |
+
|
| 138 |
+
def pageLoderAPI(title):
|
| 139 |
+
response = requests.request("GET", "https://www.shemaroome.com/"+title)
|
| 140 |
+
soup = BeautifulSoup(response.text, features="html5lib")
|
| 141 |
+
catalog_id = soup.find("input", {"id": "catalog_id"})['value']
|
| 142 |
+
content_id = soup.find("input", {"id": "content_id"})['value']
|
| 143 |
+
item_category = soup.find("input", {"id": "item_category"})['value']
|
| 144 |
+
content_definition = soup.find("input", {"id": "content_definition"})['value']
|
| 145 |
+
try:
|
| 146 |
+
return {"catalog_id":catalog_id,"content_id":content_id,"item_category":item_category,"content_definition":content_definition}
|
| 147 |
+
except:
|
| 148 |
+
return {"error":"There's an error in URL."}
|
| 149 |
+
|
| 150 |
+
@app.route('/')
|
| 151 |
+
def home():
|
| 152 |
+
sliderImages,catagoryObject = homeFetch()
|
| 153 |
+
return render_template('home.html',sliderImages=sliderImages,catagoryObject=catagoryObject)
|
| 154 |
+
|
| 155 |
+
@app.route('/movies/<title>')
|
| 156 |
+
def movieDetail(title):
|
| 157 |
+
try:
|
| 158 |
+
dataObj = movieDetailFetch("movies/"+title)
|
| 159 |
+
contentObj = pageLoderAPI("movies/"+title)
|
| 160 |
+
keyData = stremKeyAPI(contentObj["catalog_id"],contentObj["content_id"],contentObj["item_category"],"AVOD")
|
| 161 |
+
movieUrl = decryptLink(keyData["ios_play_url"],keyData["ios_key"],"movie")
|
| 162 |
+
return render_template('detailMovie.html',dataObj=dataObj,movieUrl=movieUrl)
|
| 163 |
+
except:
|
| 164 |
+
return redirect(url_for('home'))
|
| 165 |
+
|
| 166 |
+
@app.route('/gujarati-plays/<title>')
|
| 167 |
+
def detailsGujaratiPlays(title):
|
| 168 |
+
try:
|
| 169 |
+
dataObj = movieDetailFetch("gujarati-plays/"+title)
|
| 170 |
+
contentObj = pageLoderAPI("gujarati-plays/"+title)
|
| 171 |
+
keyData = stremKeyAPI(contentObj["catalog_id"],contentObj["content_id"],contentObj["item_category"],"AVOD")
|
| 172 |
+
movieUrl = decryptLink(keyData["ios_play_url"],keyData["ios_key"],"movie")
|
| 173 |
+
return render_template('detailsGujaratiPlays.html',dataObj=dataObj,movieUrl=movieUrl)
|
| 174 |
+
except:
|
| 175 |
+
return redirect(url_for('home'))
|
| 176 |
+
|
| 177 |
+
@app.route('/shows/<title>')
|
| 178 |
+
def detailShowHome(title):
|
| 179 |
+
try:
|
| 180 |
+
dataObj = showDetailFetch("shows/"+title)
|
| 181 |
+
return render_template('detailShowHome.html',dataObj=dataObj)
|
| 182 |
+
except:
|
| 183 |
+
return redirect(url_for('home'))
|
| 184 |
+
|
| 185 |
+
@app.route('/shows/<title>/<episode>')
|
| 186 |
+
def detailShowEpisode(title,episode):
|
| 187 |
+
try:
|
| 188 |
+
dataObj = showDetailFetch("shows/"+title+"/"+episode)
|
| 189 |
+
contentObj = pageLoderAPI("shows/"+title+"/"+episode)
|
| 190 |
+
keyData = stremKeyAPI(contentObj["catalog_id"],contentObj["content_id"],contentObj["item_category"],"AVOD")
|
| 191 |
+
movieUrl = decryptLink(keyData["ios_play_url"],keyData["ios_key"],"show")
|
| 192 |
+
return render_template('detailShowEpisode.html',dataObj=dataObj,movieUrl=movieUrl)
|
| 193 |
+
except:
|
| 194 |
+
return redirect(url_for('home'))
|
| 195 |
+
|
| 196 |
+
app.run(host="0.0.0.0",port="7860",debug="true")
|