Example #1
0
 def get(self, path):
     """List content in path"""
     filetypes = ['.mp3', '.mp4', '.ogg', '.wav']
     user = get_current_youtify_user_model()
     if user is None:
         self.error(403)
         self.response.out.write('User not logged in')
         return
     access_token = OAuthToken.from_string(user.dropbox_access_token)
     session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY, config.DROPBOX_APP_SECRET, config.DROPBOX_ACCESS_TYPE)
     session.token = access_token
     client = dropbox.client.DropboxClient(session)
     
     path = '/' + path
     dirs = []
     mediafiles = []
     
     try:
         metadata = client.metadata(path)
         if 'contents' in metadata:
             for item in metadata['contents']:
                 if item['is_dir']:
                     dirs.append(item['path'])
                 else:
                     for filetype in filetypes:
                         if item['path'].lower().endswith(filetype):
                             # all currently supported filetypes are 4 chars long
                             title = ' - '.join(item['path'].split('/'))[3:-4]
                             track = { 'videoId': item['path'], 'title': title, 'type': 'dropbox' }
                             mediafiles.append(track)
                             break
     except:
         pass
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps({'dirs': dirs, 'media': mediafiles}))
Example #2
0
    def get(self):
        # Maybe the user pressed cancel
        if self.request.path.lower().find('not_approved=true') > 0:
            self.redirect('/')
            return
        
        session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY, config.DROPBOX_APP_SECRET, config.DROPBOX_ACCESS_TYPE)
        user = get_current_youtify_user_model()
        if user:
            # get access token
            request_token = OAuthToken.from_string(user.dropbox_access_token)
            session.request_token = request_token
            access_token = session.obtain_access_token(request_token)
            user.dropbox_access_token = access_token.to_string()

            # get user name
            session.token = access_token
            client = dropbox.client.DropboxClient(session)
            info = client.account_info()
            user.dropbox_user_name = info['display_name']
            user.save()
            self.redirect('/')
        else:
            self.error(403)
            self.response.out.write('User not logged in')
Example #3
0
    def get(self):
        # Maybe the user pressed cancel
        if self.request.path.lower().find('not_approved=true') > 0:
            self.redirect('/')
            return

        session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY,
                                                 config.DROPBOX_APP_SECRET,
                                                 config.DROPBOX_ACCESS_TYPE)
        user = get_current_youtify_user_model()
        if user:
            # get access token
            request_token = OAuthToken.from_string(user.dropbox_access_token)
            session.request_token = request_token
            access_token = session.obtain_access_token(request_token)
            user.dropbox_access_token = access_token.to_string()

            # get user name
            session.token = access_token
            client = dropbox.client.DropboxClient(session)
            info = client.account_info()
            user.dropbox_user_name = info['display_name']
            user.save()
            self.redirect('/')
        else:
            self.error(403)
            self.response.out.write('User not logged in')
Example #4
0
    def get(self, path):
        """List content in path"""
        filetypes = ['.mp3', '.mp4', '.ogg', '.wav']
        user = get_current_youtify_user_model()
        if user is None:
            self.error(403)
            self.response.out.write('User not logged in')
            return
        access_token = OAuthToken.from_string(user.dropbox_access_token)
        session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY,
                                                 config.DROPBOX_APP_SECRET,
                                                 config.DROPBOX_ACCESS_TYPE)
        session.token = access_token
        client = dropbox.client.DropboxClient(session)

        path = '/' + path
        dirs = []
        mediafiles = []

        try:
            metadata = client.metadata(path)
            if 'contents' in metadata:
                for item in metadata['contents']:
                    if item['is_dir']:
                        dirs.append(item['path'])
                    else:
                        for filetype in filetypes:
                            if item['path'].lower().endswith(filetype):
                                # all currently supported filetypes are 4 chars long
                                title = ' - '.join(
                                    item['path'].split('/'))[3:-4]
                                track = {
                                    'videoId': item['path'],
                                    'title': title,
                                    'type': 'dropbox'
                                }
                                mediafiles.append(track)
                                break
        except:
            pass
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(
            simplejson.dumps({
                'dirs': dirs,
                'media': mediafiles
            }))
Example #5
0
 def get(self):
     """Get the dropbox stream path, which is valid for 4 hours"""
     path = self.request.path
     path_separator = '/api/dropbox/stream/'
     path = path[path.find(path_separator) + len(path_separator):]
     filetypes = ['.mp3', '.mp4', '.ogg', '.wav']
     user = get_current_youtify_user_model()
     if user is None:
         self.error(403)
         self.response.out.write('User not logged in')
         return
     if user.dropbox_access_token is None:
         self.error(401)
         self.response.out.write('User has not connected to dropbox.')
         return
     access_token = OAuthToken.from_string(user.dropbox_access_token)
     session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY, config.DROPBOX_APP_SECRET, config.DROPBOX_ACCESS_TYPE)
     session.token = access_token
     client = dropbox.client.DropboxClient(session)
     stream = client.media(unquote(path))
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps(stream))
Example #6
0
 def get(self):
     """Get the dropbox stream path, which is valid for 4 hours"""
     path = self.request.path
     path_separator = '/api/dropbox/stream/'
     path = path[path.find(path_separator) + len(path_separator):]
     filetypes = ['.mp3', '.mp4', '.ogg', '.wav']
     user = get_current_youtify_user_model()
     if user is None:
         self.error(403)
         self.response.out.write('User not logged in')
         return
     if user.dropbox_access_token is None:
         self.error(401)
         self.response.out.write('User has not connected to dropbox.')
         return
     access_token = OAuthToken.from_string(user.dropbox_access_token)
     session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY,
                                              config.DROPBOX_APP_SECRET,
                                              config.DROPBOX_ACCESS_TYPE)
     session.token = access_token
     client = dropbox.client.DropboxClient(session)
     stream = client.media(unquote(path))
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps(stream))