コード例 #1
0
ファイル: main.py プロジェクト: putdotio/putio-kodi
def main():
    """Dispatches the commands."""

    handler = PutioApiHandler(SETTINGS.getSetting('oauth2_token'))
    item_id = PLUGIN_ARGS.get('item')
    if not item_id:  # Entrypoint.
        # if the user has an account but no product,
        # she could walk the files but couldn't play them. Inform.
        if not handler.is_account_active():
            xbmcgui.Dialog().ok(heading=I18N(32062), line1=I18N(32063))

        populate_dir(handler.list(parent=0))
        return

    item_id = int(item_id[0])
    item = handler.get(id_=item_id)
    if not item.content_type:
        return

    # Dispatch commands
    action = PLUGIN_ARGS.get('action')
    if not action:
        return

    action = action[0]
    if action == 'list':
        populate_dir(handler.list(parent=item_id))
        return

    if action == 'delete':
        delete(item=item)
        return

    if action == 'play':
        play(item=item)
        return
コード例 #2
0
ファイル: service.py プロジェクト: putdotio/putio-kodi
            continue

        # don't even bother to send a request if the player is at the start of the video.
        if video_is_at < 10:
            continue

        video_duration = player.getTotalTime()
        if video_duration <= 20:
            continue

        # if the player is very close to finish, set the 'start_from' parameter to the send of the video. because our
        # poll interval is not very precise. just assume user has finished watching the video.
        if (video_duration - video_is_at) < POLL_INTERVAL:
            video_is_at = video_duration

        oauth2_token = SETTINGS.getSetting('oauth2_token')
        if not oauth2_token:
            xbmc.log(msg='[putio.service] Missing OAuth2 Token', level=xbmc.LOGERROR)
            continue

        # FIXME: urlparse combined with os.path.split gives a stupid error. this is python 2.6 in 2016. screw this.
        paths = filename.strip(PUTIO_API_ENDPOINT)
        item_id = paths.split('/')[1]

        # time to send a request
        handler = Client(access_token=oauth2_token, use_retry=True)
        try:
            handler.request('/files/%s/start-from/set' % item_id,
                            method='POST',
                            data={'time': video_is_at})
        except Exception as e:
コード例 #3
0
ファイル: main.py プロジェクト: putdotio/putio-kodi
import xbmc
import xbmcgui
import xbmcplugin

from resources.lib.helper import I18N
from resources.lib.helper import SETTINGS
from resources.lib.helper import PutioApiHandler
from resources.lib.helper import PutioAuthFailureException

PLUGIN_URL = sys.argv[0]  # base URL ('plugin://plugin.video.putio/')
PLUGIN_HANDLE = int(sys.argv[1])  # process handle, as a numeric string
PLUGIN_ARGS = urlparse.parse_qs(sys.argv[2].lstrip('?'))  # query string, ('?action=list&item=3')

PUTIO_KODI_ENDPOINT = 'https://put.io/kodi'
RESOURCE_PATH = os.path.join(SETTINGS.getAddonInfo('path'), 'resources', 'media')


def build_url(action, item):
    return '{0}?action={1}&item={2}'.format(PLUGIN_URL, action, item)


def get_resource_path(filename):
    """Returns special path of the given filename."""
    if not filename:
        return
    return os.path.join(RESOURCE_PATH, filename)


def populate_dir(files):
    """Fills a directory listing with put.io files."""