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

Added plugin for blip.tv VOD #936

Merged
merged 2 commits into from
Jun 2, 2015
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
1 change: 1 addition & 0 deletions docs/plugin_matrix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ azubutv azubu.tv Yes No
beam beam.pro Yes No
beattv be-at.tv Yes Yes Playlist not implemented yet.
bambuser bambuser.com Yes Yes
bliptv blip.tv -- Yes
chaturbate chaturbate.com Yes No
connectcast connectcast.tv Yes Yes
crunchyroll crunchyroll.com -- Yes
Expand Down
73 changes: 73 additions & 0 deletions src/livestreamer/plugins/bliptv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import re

from livestreamer.plugin import Plugin, PluginError
from livestreamer.plugin.api import http
from livestreamer.stream import HTTPStream

_url_re = re.compile("(http(s)?://)?blip.tv/.*-(?P<videoid>\d+)")
VIDEO_GET_URL = 'http://player.blip.tv/file/get/{0}'
SINGLE_VIDEO_URL = re.compile('.*\.((mp4)|(mov)|(m4v)|(flv))')

QUALITY_WEIGHTS = {
"ultra": 1080,
"high": 720,
"medium": 480,
"low": 240,
}

QUALITY_WEIGHTS_ULTRA = re.compile('ultra+_(?P<level>\d+)')


def get_quality_dict(quality_list):
quality_list.sort()
quality_dict = {}
i = 0
for i, bitrate in enumerate(quality_list):
if i == 0:
quality_dict['%i' % bitrate] = 'low'
elif i == 1:
quality_dict['%i' % bitrate] = 'medium'
elif i == 2:
quality_dict['%i' % bitrate] = 'high'
elif i == 3:
quality_dict['%i' % bitrate] = 'ultra'
else:
quality_dict['%i' % bitrate] = 'ultra+_%i' % (i-3)
return quality_dict


class bliptv(Plugin):
@classmethod
def can_handle_url(cls, url):
return _url_re.match(url)

@classmethod
def stream_weight(cls, key):
match_ultra = QUALITY_WEIGHTS_ULTRA.match(key)
if match_ultra:
ultra_level = int(match_ultra.group('level'))
return 1080 * (ultra_level + 1), "bliptv"
weight = QUALITY_WEIGHTS.get(key)
if weight:
return weight, "bliptv"
return Plugin.stream_weight(key)

def _get_streams(self):
match = _url_re.match(self.url)
videoid = match.group('videoid')
get_return = http.get(VIDEO_GET_URL.format(videoid))
json_decode = http.json(get_return)
streams = {}
quality_list = []
for stream in json_decode:
if SINGLE_VIDEO_URL.match(stream['direct_url']):
quality_list.append(int(stream['video_bitrate']))
if len(quality_list) == 0:
return
quality_dict = get_quality_dict(quality_list)
for stream in json_decode:
if SINGLE_VIDEO_URL.match(stream['direct_url']):
streams[quality_dict[stream['video_bitrate']]] = HTTPStream(self.session, stream['direct_url'])
return streams

__plugin__ = bliptv