def Lookup(id): oc = ObjectContainer() client = putio2.Client(Prefs['access_token']) f = client.File.get(id) if f.content_type.startswith('video/'): oc.add(VideoClipObject( key = Callback(Lookup, id = f.id), items = [ MediaObject(parts = [ PartObject(key = Callback(PlayMedia, url = f.stream_url)) ]) ], rating_key = f.id, title = f.name, thumb = f.screenshot)) elif f.content_type.startswith('audio/'): oc.add(TrackObject( key = Callback(Lookup, id = f.id), items = [ MediaObject(parts = [ PartObject(key = Callback(PlayMedia, url = f.stream_url)) ]) ], rating_key = f.id, title = f.name, thumb = f.screenshot)) else: Log.Info("Unsupported content type '%s'" % f.content_type) return oc
def PlayMedia(id, **kwargs): id = int(id) client = putio2.Client(Prefs['access_token']) f = client.File.get(id) return Redirect(f.stream_url)
def ParseDirectory(id, name): oc = ObjectContainer(title1 = name, view_group = 'InfoList') client = putio2.Client(Prefs['access_token']) for f in client.File.list(id): if f.content_type == 'application/x-directory': oc.add(DirectoryObject( key = Callback(ParseDirectory, id = f.id, name = f.name), title = f.name)) elif f.content_type.startswith('video/'): oc.add(VideoClipObject( key = Callback(Lookup, id = f.id), items = [ MediaObject(parts = [ PartObject(key = Callback(PlayMedia, url = f.stream_url)) ]) ], rating_key = f.id, title = f.name, thumb = f.screenshot)) elif f.content_type.startswith('audio/'): oc.add(TrackObject( key = Callback(Lookup, id = f.id), items = [ MediaObject(parts = [ PartObject(key = Callback(PlayMedia, url = f.stream_url)) ]) ], rating_key = f.id, title = f.name, thumb = f.screenshot)) else: Log.Info("Unsupported content type '%s'" % f.content_type) return oc
def ParseDirectory(id, name): oc = ObjectContainer(title1=name, view_group='InfoList') oc.add(PrefsObject(title=L('Preferences'))) token = Prefs['access_token'] if token == "": Log.Info("login olunmamis hic!") return ObjectContainer( header="Login", message="Enter your access token in Preferences.") client = putio2.Client(token) try: for f in client.File.list(id): if f.content_type == 'application/x-directory': oc.add( DirectoryObject(key=Callback(ParseDirectory, id=f.id, name=f.name), title=f.name)) elif f.content_type.startswith('video/'): oc.add( VideoClipObject( key=Callback(Lookup, id=f.id), items=[ MediaObject(parts=[ PartObject( key=Callback(PlayMedia, url=f.stream_url)) ]) ], rating_key=f.id, title=f.name, thumb=f.screenshot)) elif f.content_type.startswith('audio/'): oc.add( TrackObject( key=Callback(Lookup, id=f.id), items=[ MediaObject(parts=[ PartObject( key=Callback(PlayMedia, url=f.stream_url)) ]) ], rating_key=f.id, title=f.name, thumb=f.screenshot)) else: Log.Info("Unsupported content type '%s'" % f.content_type) except: Log.Exception( "Files couldn't fetch. Access token is wrong or missing.") return oc