2014-09-20 3 views
0

Linux의 명령을 사용하여 다음 Python 코드를 사용하여 Google 드라이브에 비디오를 업로드하고 있습니다. 리눅스 커널 기반의 안드로이드 이후 안드로이드에서 사용할 수 있습니까? 그렇지 않은 경우 백그라운드에서 비디오를 업로드 할 수있는 Android 서비스가 있습니까? (Google 드라이브 또는 DropBox로 연결) Python 코드를 사용하여 android를 Google 드라이브에 업로드하는 방법

$ 파이썬 uploader.py video_file.avi

uploader.py : 당신은 안드로이드에 파이썬을 사용하려는 이유를 정말

#!/usr/bin/python 
import smtplib 
import os.path 
import sys 
import gdata.data 
import gdata.docs.data 
import gdata.docs.client 
import ConfigParser 

from curses import ascii    


class MotionUploader: 
    def __init__(self): 


     self.password = "my Gmail password" 
     self.sender = "[email protected]"     

     # Folder (or collection) in Docs where you want the videos to go 
     self.folder = 'motion' 


     self._create_gdata_client() 

    def _create_gdata_client(self): 
     """Create a Documents List Client.""" 
     self.client = gdata.docs.client.DocsClient(source='motion_uploader') 
     self.client.http_client.debug = False 
     self.client.client_login(self.sender, self.password, service=self.client.auth_service, source=self.client.source) 

    def _get_folder_resource(self): 
     """Find and return the resource whose title matches the given folder.""" 
     col = None 
     for resource in self.client.GetAllResources(uri='/feeds/default/private/full/-/folder'): 
      if resource.title.text == self.folder: 
       col = resource 
       break  
     return col 


    def _upload(self, video_file_path, folder_resource): 
     '''Upload the video and return the doc''' 
     doc = gdata.docs.data.Resource(type='video', title=os.path.basename(video_file_path)) 
     media = gdata.data.MediaSource() 
     media.SetFileHandle(video_file_path, 'video/avi') 
     doc = self.client.CreateResource(doc, media=media, collection=folder_resource) 
     return doc 

    def upload_video(self, video_file_path): 
     """Upload a video to the specified folder""" 

     folder_resource = self._get_folder_resource() 
     if not folder_resource: 
      raise Exception('Could not find the %s folder' % self.folder) 

     doc = self._upload(video_file_path, folder_resource) 


     video_link = None 
     for link in doc.link:    
      if 'docs.google.com/file/d' in link.href: 
       video_link = link.href 
       break 


if __name__ == '__main__':   
    try: 
     if len(sys.argv) < 2: 
      exit('Usage: uploader.py {config-file-path} {video-file-path}') 

     vid_path = sys.argv[1]   
     if not os.path.exists(vid_path): 
      exit('Video file does not exist [%s]' % vid_path)  
     MotionUploader().upload_video(vid_path)   
    except gdata.client.BadAuthentication: 
     exit('Invalid user credentials given.') 
    except gdata.client.Error: 
     exit('Login Error') 
    except Exception as e: 
     exit('Error: [%s]' % e) 
+0

스크립트 작성 했습니까? 'from curses import ascii'는 스크립트가 그것을 사용하는 것으로 보이지 않기 때문에 약간 이상합니다. 그러나 빠른 인터넷 검색에서 안드로이드 파이썬에는 저주가있는 것으로 나타납니다, FWIW. –

+0

실제로 인터넷에서 가져온 코드에서 코드를 수정했지만 ascii를 제거하는 것을 잊어 버렸습니다. 그러나 코드는 Linux (Beaglebone)에서 제대로 작동합니다. –

답변

0

가 표시되지 않는 이유는 무엇입니까? Android는 Google Play 서비스를 통해 Google 드라이브 API를 사용할 수 있습니다. 여기에 아주 잘 설명되어 있습니다 : https://developers.google.com/drive/android/get-started.

공식 퀵 스타트 앱도 확인할 수 있습니다 (https://github.com/googledrive/android-quickstart).

+0

나는 안드로이드 java.beut 초보자입니다. 나는 두 번째 link.I와 함께 시도 할 것입니다 안드로이드 화면에서 아무 버튼도 클릭하지 않고 파일을 자동으로 업로드해야합니다. –

+0

작동시키기 위해서는 [시작 안내서] (https://developers.google.com/drive/android/get-started)도 확인해야합니다. – Tas

관련 문제