Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- '''
- if __name__ == "__main__":
- import sys, os, pickle, threading, pprint, shutil, re
- addon_path = dirname(__file__)
- libs = os.path.join(addon_path, 'lib')
- sys.path.append(libs)
- from dropbox import client, rest, session
- pp = pprint.PrettyPrinter(indent=4)
- def log(msg):
- pp.pprint(msg)
- # Get your app key and secret from the Dropbox developer website
- APP_KEY = 'key'
- APP_SECRET = 'secret' #changed these for obvious reasons
- # ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
- ACCESS_TYPE = 'app_folder'
- sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
- access_token_location = os.path.join(addon_path, 'access_token.txt')
- out = open(access_token_location, 'rb')
- access_token = pickle.load(out)
- log("SKDownloader: access_token: %s" % access_token)
- out.close()
- sess.set_token(access_token=access_token['key'], access_token_secret=access_token['secret'])
- client = client.DropboxClient(sess)
- #__settings__ = xbmcaddon.Addon(script.service.skplayer)
- #c_ipaddr = __settings__.getSetting("oath")
- path = '/storage/download'
- #path = ADDON.getSetting('lcl_path')
- #log("SKDownloader: directory %s" % ADDON.getSetting('lcl_path'))
- #pp = pprint.PrettyPrinter(indent=4)
- access_token_location = os.path.join(addon_path, 'access_token.txt')
- cursor_location = os.path.join(addon_path, 'cursor.txt')
- out = open(cursor_location, 'rb')
- try:
- cursor = pickle.load(out)
- except EOFError:
- cursor = None
- out.close()
- db_path = '/devices/device1'
- regex = re.compile("^" + db_path)
- def checkdb():
- global cursor
- log("SKDownloader: polling for delta")
- delta = client.delta(cursor=cursor)
- log("SKDownloader: received delta: %s" % delta)
- for entry in delta['entries']:
- if regex.match(entry[0]) is None:
- continue
- log("SKDownloader, reading: %s" % entry[0])
- cpath = os.path.join(path, entry[0][1:])
- if entry[1] is None:
- if not os.path.exists(cpath):
- continue
- if os.path.isdir(cpath):
- shutil.rmtree(cpath)
- log("SKDownloader: removing path: %s" % cpath)
- else:
- os.remove(cpath)
- log("SKDownloader: removing file: %s" % cpath)
- else:
- if os.path.exists(cpath):
- continue
- if entry[1]['is_dir']:
- os.makedirs(cpath)
- log("SKDownloader: created directory: %s" % cpath)
- else:
- f, metadata = client.get_file_and_metadata(entry[0])
- out = open(cpath, 'wb')
- log("SKDownloader: writing to: %s" % cpath)
- out.write(f.read())
- out.close()
- cursor = delta['cursor']
- out = open(cursor_location, 'wb')
- pickle.dump(cursor, out, -1)
- out.close()
- if len(delta['entries']):
- pass
- #xbmc.executebuiltin("XBMC.RecursiveSlideShow(" + path + ")")
- threading.Timer(20, checkdb).start()
- # start calling f now and every 60 sec thereafter
- checkdb()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement