Skip to content

Commit

Permalink
Apply settings for pirateplay streams and bitrate limit where appropr…
Browse files Browse the repository at this point in the history
…iate
  • Loading branch information
Andreas Pehrson committed Jan 19, 2014
1 parent fd013fb commit bd1ef97
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
51 changes: 26 additions & 25 deletions tv.boxeeplay.svtplay3/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,31 +337,32 @@ def play_item(item):

play_item = episode_list_item_to_playable(item)
pirateplayable = False
try:
play_item = pirateplayable_item(play_item)
pirateplayable = True
except NoStreamsError:
track("Warning",
{ "title": item.GetLabel(),
"url": item.GetPath(),
"Id": mc.GetUniqueId(),
"type": item_type,
"show": item.GetProperty("show"),
"category": item.GetProperty("category"),
"error_type": "No Streams"
})
BPLog("Inga strömmar genom pirateplay. Spelar upp via websidan.", Level.ERROR)
except NoSuitableStreamError:
track("Warning",
{ "title": item.GetLabel(),
"url": item.GetPath(),
"Id": mc.GetUniqueId(),
"type": item_type,
"show": item.GetProperty("show"),
"category": item.GetProperty("category"),
"error_type": "No Suitable Streams"
})
BPLog("Inga strömmar i rätt format genom pirateplay. Spelar upp via websidan.", Level.ERROR)
if settings.use_pirateplay():
try:
play_item = pirateplayable_item(play_item, settings.bitrate_limit())
pirateplayable = True
except NoStreamsError:
track("Warning",
{ "title": item.GetLabel(),
"url": item.GetPath(),
"Id": mc.GetUniqueId(),
"type": item_type,
"show": item.GetProperty("show"),
"category": item.GetProperty("category"),
"error_type": "No Streams"
})
BPLog("Inga strömmar genom pirateplay. Spelar upp via websidan.", Level.ERROR)
except NoSuitableStreamError:
track("Warning",
{ "title": item.GetLabel(),
"url": item.GetPath(),
"Id": mc.GetUniqueId(),
"type": item_type,
"show": item.GetProperty("show"),
"category": item.GetProperty("category"),
"error_type": "No Suitable Streams"
})
BPLog("Inga strömmar i rätt format genom pirateplay. Spelar upp via websidan.", Level.ERROR)

if not pirateplayable:
play_item.SetPath("flash://boxeeplay.tv/src=%s&bx-jsactions=%s" %
Expand Down
7 changes: 6 additions & 1 deletion tv.boxeeplay.svtplay3/pirateplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def filter_path_matching(streams, matcher):
for stream in streams:
if matcher in stream["url"]: yield stream

def filter_max_bitrate(streams, limit=-1):
for stream in streams:
if limit <= 0 or bandwidth_from_stream(stream) <= limit: yield stream

def bandwidth_from_stream(stream):
return int(stream["meta"]["quality"].split(' ', 1)[0])

Expand All @@ -32,14 +36,15 @@ def boxeespecific_quality_from_stream(stream):
if bandwidth_from_stream(stream) < 1000: return '0'
else: return '1'

def pirateplayable_item(item):
def pirateplayable_item(item, bitrate_limit):
streams = get_streams(item.GetPath())

print str(streams)
if len(streams) == 0:
raise NoStreamsError()

streams_generator = filter_path_matching(streams, "m3u8")
streams_generator = filter_max_bitrate(streams, bitrate_limit)

streams = []
streams.extend(streams_generator)
Expand Down
12 changes: 6 additions & 6 deletions tv.boxeeplay.svtplay3/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def activate_stream_source_selection():

opt_pirateplay = "Pirateplay om möjligt"
opt_webonly = "Endast webbläsaren"
if get_use_pirateplay(): opt_pirateplay = "[valt] " + opt_pirateplay
if use_pirateplay(): opt_pirateplay = "[valt] " + opt_pirateplay
else: opt_webonly = "[valt] " + opt_webonly
decision = mc.ShowDialogSelect("Ändra Uppspelningskälla", [opt_pirateplay, opt_webonly])

Expand All @@ -45,7 +45,7 @@ def activate_bitrate_limit_selection():

options = [ "Obegränsat", "2500 Kbps", "2000 Kbps", "1500 Kbps", "1000 Kbps", "500 Kbps" ]
option_values = [ -1, 2500, 2000, 1500, 1000, 500 ]
limit = get_bitrate_limit()
limit = bitrate_limit()
active_value_index = 0
try: active_value_index = option_values.index(limit)
except: BPLog("Value %d not found in list of bitrate limit options" %limit, Level.WARNING)
Expand All @@ -60,13 +60,13 @@ def activate_bitrate_limit_selection():
set_bitrate_limit(chosen_limit)
BPLog("Bitrate limit set to %d kbps (%s)" %(chosen_limit, options[decision]))

def get_use_pirateplay():
def use_pirateplay():
return conf().GetValue(USE_PIRATEPLAY_KEY) == "True"

def set_use_pirateplay(use_pirateplay):
conf().SetValue(USE_PIRATEPLAY_KEY, str(use_pirateplay))

def get_bitrate_limit():
def bitrate_limit():
limit = conf().GetValue(BITRATE_LIMIT_KEY)
if limit == "": return -1
else: return int(limit)
Expand All @@ -76,15 +76,15 @@ def set_bitrate_limit(limit):

def get_option_stream_source():
opt = "Uppspelningskälla: "
if get_use_pirateplay():
if use_pirateplay():
opt += "Pirateplay"
else:
opt += "Web"
return opt

def get_option_bitrate_limit():
opt = "Bandbreddsbegränsning: "
limit = get_bitrate_limit()
limit = bitrate_limit()
if limit == -1:
opt += "Obegränsat"
else:
Expand Down

0 comments on commit bd1ef97

Please sign in to comment.