Skip to content

Commit

Permalink
Add search
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGatesIT committed Oct 11, 2023
1 parent 8504097 commit 5ee4596
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 15 deletions.
4 changes: 2 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.crackle" name="Crackle" version="2022.10.19" provider-name="eracknaphobia">
<addon id="plugin.video.crackle" name="Crackle" version="2023.10.11" provider-name="eracknaphobia">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests"/>
<import addon="script.module.inputstreamhelper"/>
<import addon="script.module.kodi-six" />
Expand Down
11 changes: 9 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@
if stream_type == "movies": media_id = get_movie_id(media_id)
get_stream(media_id)


xbmcplugin.endOfDirectory(addon_handle)
elif mode == 104:
dialog = xbmcgui.Dialog()
search_phrase = dialog.input('Search Text', type=xbmcgui.INPUT_ALPHANUM)
if search_phrase != "":
search(search_phrase)
xbmcplugin.endOfDirectory(addon_handle, cacheToDisc=True)

if mode != 104:
xbmcplugin.endOfDirectory(addon_handle)
12 changes: 12 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ msgstr ""
msgctxt "#30000"
msgid "Crackle"
msgstr ""

msgctxt "#30001"
msgid "Movies"
msgstr ""

msgctxt "#30002"
msgid "TV Shows"
msgstr ""

msgctxt "#30003"
msgid "Search"
msgstr ""
54 changes: 45 additions & 9 deletions resources/lib/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
addon_url = sys.argv[0]
addon_handle = int(sys.argv[1])
ADDON = xbmcaddon.Addon()
KODI_VERSION = float(re.findall(r'\d{2}\.\d{1}', xbmc.getInfoLabel("System.BuildVersion"))[0])
ROOTDIR = ADDON.getAddonInfo('path')
FANART = os.path.join(ROOTDIR,"resources","media","fanart.jpg")
ICON = os.path.join(ROOTDIR,"resources","media","icon.png")
Expand All @@ -19,17 +18,18 @@
# Addon Settings
LOCAL_STRING = ADDON.getLocalizedString
UA_CRACKLE = 'Crackle/7.60 CFNetwork/808.3 Darwin/16.3.0'
UA_WEB = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'
UA_WEB = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
UA_ANDROID = 'Android 4.1.1; E270BSA; Crackle 4.4.5.0'
PARTNER_KEY = 'Vk5aUUdYV0ZIVFBNR1ZWVg=='
PARTNER_ID = '77'
BASE_URL = 'https://androidtv-api-us.crackle.com/Service.svc'
WEB_KEY = '5FE67CCA-069A-42C6-A20F-4B47A8054D46'


def main_menu():
add_dir('Movies', 'movies', 99, ICON)
add_dir('TV', 'shows', 99, ICON)

add_dir(LOCAL_STRING(30001), 'movies', 99, ICON)
add_dir(LOCAL_STRING(30002), 'shows', 99, ICON)
add_dir(LOCAL_STRING(30003), 'search', 104, ICON)

def list_movies(genre_id):
url = f"/browse/movies/full/{genre_id}/alpha-asc/US?format=json"
Expand Down Expand Up @@ -151,10 +151,7 @@ def get_stream(id):
if not is_helper.check_inputstream():
sys.exit()
listitem.setPath(stream_url)
if KODI_VERSION >= 19:
listitem.setProperty('inputstream', 'inputstream.adaptive')
else:
listitem.setProperty('inputstreamaddon', 'inputstream.adaptive')
listitem.setProperty('inputstream', 'inputstream.adaptive')
listitem.setProperty('inputstream.adaptive.manifest_type', 'mpd')
listitem.setProperty('inputstream.adaptive.stream_headers', f"User-Agent={UA_WEB}")
listitem.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha')
Expand All @@ -167,6 +164,45 @@ def get_stream(id):

xbmcplugin.setResolvedUrl(addon_handle, True, listitem)

def search(search_phrase):
url = f"https://prod-api.crackle.com/contentdiscovery/search/{search_phrase}" \
"?useFuzzyMatching=false" \
"&enforcemediaRights=true" \
"&pageNumber=1&pageSize=20" \
"&contentType=Channels" \
"&searchFields=Title%2CCast"
headers = {
'User-Agent': UA_WEB,
'X-Crackle-Platform': WEB_KEY,
}

r = requests.get(url, headers=headers)
xbmc.log(r.text)
for item in r.json()['data']['items']:
metadata = item['metadata'][0]
title = metadata['title']
url = str(item['externalId'])
icon = get_image(item['assets']['images'], 220, 330)
fanart = get_image(item['assets']['images'], 1920, 1080)
info = {'plot': metadata['longDescription'],
'title':title,
'originaltitle':title,
}

if item['type'] == 'Movie':
add_stream(title,url,'movies',icon,fanart,info)
else:
add_dir(title, url, 102, icon, fanart, info, content_type='tvshows')

def get_image(images, width, height):
img = ICON
for image in images:
if image['width'] == width and image['height'] == height:
img = image['url']
break

return img


def json_request(url):
url = BASE_URL + url
Expand Down
10 changes: 8 additions & 2 deletions resources/settings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<!-- General -->
</settings>
<category label="Integration">
<setting label="Install IPTV Manager add-on" type="action" action="InstallAddon(service.iptv.manager)" option="close" visible="!System.HasAddon(service.iptv.manager)"/>
<setting label="Enable IPTV Manager integration" type="bool" id="iptv.enabled" default="true" visible="System.HasAddon(service.iptv.manager)" />
<setting label="IPTV Manager settings…" type="action" action="Addon.OpenSettings(service.iptv.manager)" enable="eq(-1,true)" option="close" visible="System.HasAddon(service.iptv.manager)" subsetting="true"/>
<setting id="iptv.channels_uri" default="plugin://plugin.video.crackle/iptv/channels" visible="false"/>
<setting id="iptv.epg_uri" default="plugin://plugin.video.crackle/iptv/epg" visible="false"/>
</category>
</settings>

0 comments on commit 5ee4596

Please sign in to comment.