Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video quality removed, updated links #2

Merged
merged 6 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ msgctxt "#50002"
msgid "Password"
msgstr ""

msgctxt "#50003"
msgid "Video quality"
msgstr ""

msgctxt "#50004"
msgid "Show scores"
msgstr ""
Expand Down
4 changes: 0 additions & 4 deletions resources/language/Hebrew/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ msgctxt "#50002"
msgid "Password"
msgstr "סיסמה"

msgctxt "#50003"
msgid "Video quality"
msgstr "איכות וידאו מיו-טיוב"

msgctxt "#50004"
msgid "Show scores"
msgstr "הצג ניקוד"
Expand Down
1 change: 0 additions & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<setting id="username" type="text" label="50001" default="" />
<setting id="password" type="text" label="50002" option="hidden" default="" />
<setting type="sep" />
<setting id="quality_id" type="enum" label="50003" values="Auto|1080p|720HD|720p|540p|360p|240p" default="1" />
<setting id="scores" type="bool" label="50004" default="false" />
<setting id="local_timezone" type="bool" label="50007" default="true" />
<setting id="fav_team" type="select" label="50009" values="None|Hawks|Celtics|Nets|Hornets|Bulls|Cavaliers|Mavericks|Nuggets|Pistons|Warriors|Rockets|Pacers|Clippers|Lakers|Grizzlies|Heat|Bucks|Timberwolves|Pelicans|Knicks|Thunder|Magic|76ers|Suns|Trail Blazers|Kings|Spurs|Raptors|Jazz|Wizards" default="None" />
Expand Down
67 changes: 8 additions & 59 deletions src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,76 +22,25 @@ def updateFavTeam():
def getGameUrlWithBitrate(url, video_type):
return url

def getGameUrlWithBitrate_Old(url, video_type):
if vars.target_video_height == -1:
return "%s|User-Agent=%s" % (url, vars.useragent)

# Force the bitrate by modifying the HLS url and adding the bitrate
available_bitrates = [
(72060, 6000),
(720, 3000),
(540, 1600),
(432, 1200),
(360, 800),
]

#"video" video_type starts from 3000k as bitrate
if video_type == "video":
available_bitrates.pop(0)

#Get the chosen bitrate, and all the bitrates after that one
target_bitrates = [item[1] for item in available_bitrates if item[0] <= vars.target_video_height]
log('target_bitrates: %s' % target_bitrates, xbmc.LOGDEBUG)

regex_pattern = 'whole_([0-9])_ipad'
regex_replacement_format = r'whole_\1_%s_ipad'
if video_type == "condensed":
regex_pattern = 'condensed_([0-9])_ipad'
regex_replacement_format = r'condensed_\1_%s_ipad'
elif video_type == "live":
regex_pattern = '([a-z]+)_hd_ipad'
regex_replacement_format = r'\1_hd_%s_ipad'
elif video_type == "video":
regex_pattern = '1_([0-9]+)\.mp4'
regex_replacement_format = r'1_%s.mp4'

#Try the target bitrate, and if it doesn't exists, try every bitrate lower than the chosen one
#(eg: if you chouse 3000k as bitrate, it will try 3000k, then 1600k, then 1200k,
#and so on)
selected_video_url = ""
for target_bitrate in target_bitrates:
selected_video_url = re.sub(regex_pattern, regex_replacement_format % target_bitrate, url)

#The "video" url is rtmp:// so i can't test it with urlopen().getcode(),
#so break on first iteration of the loop
if video_type == "video":
break

#If video is found, break
if urllib.urlopen(selected_video_url).getcode() == 200:
break

log("video of bitrate %d not found, trying with next height" % target_bitrate, xbmc.LOGDEBUG)

return "%s|User-Agent=%s" % (selected_video_url, vars.useragent)

def getFanartImage():
# get the feed url
feed_url = "http://smb.cdnak.neulion.com/fs/nba/feeds/common/dl.js"
req = urllib2.Request(feed_url, None);
feed_url = "https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds/common/dl.js"
xbmc.log(feed_url, xbmc.LOGINFO)
req = urllib2.Request(feed_url, None)
response = str(urllib2.urlopen(req).read())

try:
# Parse
js = json.loads(response[response.find("{"):])
dl = js["dl"]

# for now only chose the first fanart
first_id = dl[0]["id"]
fanart_image = ("http://smb.cdnllnwnl.neulion.com/u/nba/nba/thumbs/dl/%s_pc.jpg" % first_id)
fanart_image = "https://nbadsdmt.akamaized.net/media/nba/nba/thumbs/dl/%s_pc.jpg" % first_id
xbmc.log(fanart_image, xbmc.LOGINFO)
vars.settings.setSetting("fanart_image", fanart_image)
except:
#I don't care
# I don't care
pass

def getDate( default= '', heading='Please enter date (YYYY/MM/DD)', hidden=False ):
Expand All @@ -100,7 +49,7 @@ def getDate( default= '', heading='Please enter date (YYYY/MM/DD)', hidden=False
keyboard = xbmc.Keyboard( default, heading, hidden )
keyboard.doModal()
ret = datetime.date.today()
if ( keyboard.isConfirmed() ):
if keyboard.isConfirmed():
sDate = unicode( keyboard.getText(), "utf-8" )
temp = sDate.split("/")
ret = datetime.date(int(temp[0]), int(temp[1]), int(temp[2]))
Expand Down
6 changes: 2 additions & 4 deletions src/favteam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ def addFavTeamGameLinks(fromDate, favTeamAbbrs, video_type = 'archive'):
try:
if type(fromDate) is datetime.datetime:
fromDate = "%04d/%d_%d" % (fromDate.year, fromDate.month, fromDate.day)
schedule = 'http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/' + fromDate + '.js?t=' + "%d" %time.time()
schedule = 'https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds_s2019/schedule/' + fromDate + '.js?t=' + "%d" %time.time()
log('Requesting %s' % schedule, xbmc.LOGDEBUG)

now_datetime_est = nowEST()

# http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/2013/10_7.js?t=1381054350000
req = urllib2.Request(schedule, None);
req = urllib2.Request(schedule, None)
response = str(urllib2.urlopen(req).read())
js = json.loads(response[response.find("{"):])

Expand Down
17 changes: 6 additions & 11 deletions src/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,13 @@ def getGameUrl(video_id, video_type, video_ishomefeed, start_time, duration):
utils.log("live cookie: %s %s" % (querystring, livecookies), xbmc.LOGDEBUG)

url = "%s://%s/%s?%s" % (protocol, domain, arguments, querystring)
url = common.getGameUrlWithBitrate_Old(url, video_type)
url = common.getGameUrlWithBitrate(url, video_type)

selected_video_url = "%s&Cookie=%s" % (url, livecookiesencoded)
else:
# Archive and condensed flow: We now work with HLS.
# The cookies are already in the URL and the server will supply them to ffmpeg later.
if '.mpd' in url:
selected_video_url = common.getGameUrlWithBitrate(url, video_type)
else:
selected_video_url = common.getGameUrlWithBitrate_Old(url, video_type)
selected_video_url = common.getGameUrlWithBitrate(url, video_type)

if selected_video_url:
utils.log("the url of video %s is %s" % (video_id, selected_video_url), xbmc.LOGDEBUG)
Expand Down Expand Up @@ -159,9 +156,7 @@ def getHighlightGameUrl(video_id):
def addGamesLinks(date = '', video_type = "archive"):
try:
now_datetime_est = utils.nowEST()

#example: http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/2013/10_7.js?t=1381054350000
schedule = 'http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/%04d/%d_%d.js?t=%d' % \
schedule = 'https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds_s2019/schedule/%04d/%d_%d.js?t=%d' % \
(date.year, date.month, date.day, time.time())
utils.log('Requesting %s' % schedule, xbmc.LOGDEBUG)

Expand Down Expand Up @@ -243,7 +238,7 @@ def addGamesLinks(date = '', video_type = "archive"):

thumbnail_url = utils.generateCombinedThumbnail(v, h)
elif image:
thumbnail_url = "https://neulionmdnyc-a.akamaihd.net/u/nba/nba/thumbs/%s" % image
thumbnail_url = "https://nbadsdmt.akamaized.net/media/nba/nba/thumbs/%s" % image

if video_type == "live":
if future_video:
Expand Down Expand Up @@ -324,8 +319,8 @@ def playGame():
item.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha')
item.setProperty('inputstream.adaptive.manifest_update_parameter', 'full')
item.setContentLookup(False)
#TODO: get license url from config
licUrl = 'https://prod-lic2widevine.sd-ngp.net/proxy|authorization=bearer ' + currentvideo['drm'] + '|R{SSM}|';
# TODO: get license url from config
licUrl = 'https://prod-lic2widevine.sd-ngp.net/proxy|authorization=bearer ' + currentvideo['drm'] + '|R{SSM}|'
item.setProperty('inputstream.adaptive.license_key', licUrl)
xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item)

Expand Down
4 changes: 0 additions & 4 deletions src/leaguepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
from favteam import *
import vars

utils.log("Chosen quality_id: %d" % vars.quality_id)
utils.log("...mapped to target_bitrate: %d (mpd)" % vars.target_bitrate)
utils.log("...mapped to target_video_height: %d (old)" % vars.target_video_height)

def mainMenu():
if isLiveUsable():
addListItem('Live games', 'live', 'live','', True)
Expand Down
12 changes: 5 additions & 7 deletions src/nbatvlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ def episodeMenu():
date = nowEST().replace(hour=4, minute=0, second=0)

log("date for episodes: %s (from %s)" % (date, nowEST()), xbmc.LOGDEBUG)

schedule = 'http://smb.cdnak.neulion.com/fs/nba/feeds/epg/2016/%s_%s.js?t=%d' % (
schedule = 'https://nlnbamdnyc-a.akamaihd.net/fs/nba/feeds/epg/2019/%s_%s.js?t=%d' % (
date.month, date.day, time.time())
log('Requesting %s' % schedule, xbmc.LOGDEBUG)

now_timestamp = int(calendar.timegm(date.timetuple()))
now_timestamp_milliseconds = now_timestamp * 1000;
now_timestamp_milliseconds = now_timestamp * 1000

# http://smb.cdnak.neulion.com/fs/nba/feeds_s2012/schedule/2013/10_7.js?t=1381054350000
req = urllib2.Request(schedule, None);
req = urllib2.Request(schedule, None)
response = str(urllib2.urlopen(req).read())
json_response = json.loads(response[response.find("["):])

Expand Down Expand Up @@ -148,7 +146,7 @@ def getLiveUrl(force_login=False):
if not vars.cookies:
return ""

failsafe = True;
failsafe = True

url = vars.config['publish_endpoint']
headers = {
Expand Down Expand Up @@ -232,7 +230,7 @@ def getLiveUrl(force_login=False):
for streamdata in streamdata_list:
video_height = streamdata.getElementsByTagName("video")[0].attributes["height"].value

if int(video_height) == vars.target_video_height:
if int(video_height) == vars.target_video_height: # TODO
selected_video_path = streamdata.attributes["url"].value
http_servers = streamdata.getElementsByTagName("httpserver")

Expand Down
14 changes: 0 additions & 14 deletions src/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,9 @@
show_cameras = json.loads(settings.getSetting(id="cameras"))
useragent = "iTunes-AppleTV/4.1"

# Map the quality_id to a bitrate (mpd) or a video height (old)
quality_id = int(settings.getSetting(id="quality_id"))
bitrates_per_quality = [-1, 10000, 4500, 3000, 1600, 800, 400]
video_heights_per_quality = [-1, 72060, 72060, 720, 540, 360, 360]
target_bitrate = bitrates_per_quality[quality_id]
target_video_height = video_heights_per_quality[quality_id]

cache = StorageServer.StorageServer("nbaleaguepass", 1)
cache.table_name = "nbaleaguepass"

# Delete the video urls cached if the video quality setting has changed
if cache.get("target_bitrate") != str(target_bitrate) or cache.get("target_video_height") != str(target_video_height):
cache.delete("video_%")
cache.set("target_bitrate", str(target_bitrate))
cache.set("target_video_height", str(target_video_height))
print "deleting video url cache"

cookies = ''
player_id = binascii.b2a_hex(os.urandom(16))
addon_dir = xbmc.translatePath( settings.getAddonInfo('path') ).decode('utf-8')
Expand Down
8 changes: 4 additions & 4 deletions src/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def videoMenu():
})

def videoListMenu():
date = vars.params.get("date");
date = vars.params.get("date")
video_tag = vars.params.get("video_tag")
video_query = vars.params.get("video_query")
page = int(vars.params.get("page", 0))
Expand Down Expand Up @@ -80,7 +80,7 @@ def videoListMenu():
selected_date.strftime('%Y-%m-%dT23:59:59.000Z')
)

base_url = "http://smbsolr.cdnak.neulion.com/solr_nbav6/nba/nba/usersearch/?"
base_url = "https://neulionscnba-a.akamaihd.net/solr/nba_program/usersearch/?"
params = urllib.urlencode({
"wt": "json",
"json.wrf": "updateVideoBoxCallback",
Expand All @@ -90,7 +90,7 @@ def videoListMenu():
"rows": per_page
})

url = base_url + params;
url = base_url + params
log("videoListMenu: %s: url of date is %s" % (video_tag, url), xbmc.LOGDEBUG)

response = urllib2.urlopen(url).read()
Expand Down Expand Up @@ -180,7 +180,7 @@ def videoPlay():

xml = parseString(str(content))
video_url = xml.getElementsByTagName("path")[0].childNodes[0].nodeValue
video_url = getGameUrlWithBitrate_Old(video_url, "video")
video_url = getGameUrlWithBitrate(video_url, "video")
log("videoPlay: video url is %s" % video_url, xbmc.LOGDEBUG)

#remove query string
Expand Down