Exemplo n.º 1
0
def move_finished_to_destination():
    print "moving finished tasks to destination folder"
    security_id = General.login(session_name())
    tasks = DownloadStation.get_tasks(security_id)
    # for each task in download station
    for task in tasks["data"]["tasks"]:
        # where task has ended seeding
        if task["status"] == "finished":
            title = unicode_functions.welcome_string(task["title"])
            id = task["id"]
            for include in includes:
                # if the task was included automatically
                if include["cadena"].lower() in title.lower():
                    # we check if destination folder exists
                    info = FileStation.get_info(include["destino"], security_id)
                    if info["success"]:
                        destino = info["data"]["files"][0]
                        if "code" in destino and destino["code"] == 408:
                            print "the directory does not exist, we create it"
                            norm = os.path.normpath(destino["path"])
                            nombre = os.path.basename(norm)
                            path = os.path.dirname(norm)
                            FileStation.create_folder(path, nombre, security_id)
                        fichero_a_mover = download_dir() + "/" + title
                        if FileStation.move(fichero_a_mover, destino["path"], security_id):
                            print "moved ", fichero_a_mover, " to ", destino["path"], ", eliminando tarea"
                            if DownloadStation.delete_task(id, security_id):
                                print "deleted task ", id
                            # say.say("ya esta disponible el fichero " + title + " en el NAS")
                        else:
                            print "hubo un problema moviendo fichero ", title
                    else:
                        print "error obtaining info about ", include["destino"]
    General.logout(session_name())
Exemplo n.º 2
0
def download_previously_not_included():
    print "searching includes that were previously skipped"
    connection = get_mongo_client()
    security_id = General.login(session_name())
    torrents = connection.descargas.torrents
    """
    we go through includes checking if something that was not included neither
    excluded can be now marked as included
    """
    for include in includes:
        # print "checking include ", include['cadena'], " to see if we left something..."
        documento = {"titulo": re.compile(include["cadena"], re.IGNORECASE), "incluido": False, "excluido": False}
        for doc in torrents.find(documento):
            # we check if it has been downloaded by exact title
            titulo = doc["titulo"]
            url = doc["url"]
            if excluded(titulo):
                print "se encontro ", titulo, " que esta incluido por ", include[
                    "cadena"
                ], " pero no se descarga por estar tambien excluido"
            else:
                encontrado = torrents.find_one({"titulo": titulo})
                if "descargado" not in encontrado or encontrado["descargado"] is False:
                    print "downloading ", titulo, " at url ", url
                    html = download_file.download_url_html(url)
                    magnets = download_file.download_magnet_in_html_regex(html)
                    for magnet in magnets:
                        DownloadStation.add_task(magnet, security_id)
                    encontrado["descargado"] = True
                    encontrado["incluido"] = True
                    torrents.save(encontrado)
                    print "updated document to remember that it was already downloaded, waiting 10 seg..."
                    time.sleep(10)  # wait 10 seconds trying not to trigger server DDOS counter measures
    General.logout(session_name())
    connection.close()
def get_tasks(security_id):
    api_path = 'DownloadStation/task.cgi'
    data_dict = {'api': 'SYNO.DownloadStation.Task', 'version': 1, 'method': 'list', '_sid': security_id}
    result = General._synology_call(api_path, data_dict)
    if not result['success']:
        print 'error in get_tasks: ', General._error_to_string(result['error']['code'])
    return result
Exemplo n.º 4
0
def get_info(item, security_id):
    #api_path = 'FileStation/file_share.cgi'
    api_path = 'entry.cgi'
    data_dict = {'api': 'SYNO.FileStation.List', 'version': 1, 'method': 'getinfo', 'path': item, '_sid': security_id}
    result = General._synology_call(api_path, data_dict)
    if not result['success']:
        print 'error in get_info: ', General._error_to_string(result['error']['code'])
    return result
Exemplo n.º 5
0
def list(folder, security_id):
    #api_path = 'FileStation/file_share.cgi'
    api_path = 'entry.cgi'
    data_dict = {'api': 'SYNO.FileStation.List', 'version': 2, 'method': 'list', 'folder_path': folder, '_sid': security_id}
    result = General._synology_call(api_path, data_dict)
    if not result['success']:
        print 'error in list: ', General._error_to_string(result['error']['code'])
    return result
def delete_task(id, security_id):
    api_path = 'DownloadStation/task.cgi'
    data_dict = {'api': 'SYNO.DownloadStation.Task', 'version': 1, 'method': 'delete', 'id': id, '_sid': security_id,
                 'force_complete': 'false'}
    result = General._synology_call(api_path, data_dict)
    if result['success']:
        return True
    else:
        print 'error in delete_task: ', General._error_to_string(result['error']['code'])
        return False
def add_task(task_url, security_id):
    api_path = 'DownloadStation/task.cgi'
    data_dict = {'api': 'SYNO.DownloadStation.Task', 'version': 1, 'method': 'create',
                 'uri': task_url, '_sid': security_id}
    result = General._synology_call(api_path, data_dict)
    if result['success']:
        return True
    else:
        print 'error in add_task: ', General._error_to_string(result['error']['code'])
        return False
Exemplo n.º 8
0
def move(item, dest_path, security_id):
    #api_path = 'FileStation/file_MVCP.cgi'
    api_path = 'entry.cgi'
    data_dict = {'api': 'SYNO.FileStation.CopyMove', 'version': 3, 'method': 'start', 'path': item,
                 'dest_folder_path': dest_path, 'overwrite': True, 'remove_src': True, '_sid': security_id}
    result = General._synology_call(api_path, data_dict)
    if result['success']:
        return True
    else:
        print 'error requesting move: ', General._error_to_string(result['error']['code'])
        return False
Exemplo n.º 9
0
def create_folder(folder_path, name, security_id):
    #api_path = 'FileStation/file_crtfdr.cgi'
    api_path = 'entry.cgi'
    data_dict = {'api': 'SYNO.FileStation.CreateFolder', 'version': 1, 'method': 'create', 'folder_path': folder_path,
                 'name': name, '_sid': security_id}
    print data_dict
    result = General._synology_call(api_path, data_dict)
    if result['success']:
        return True
    else:
        print 'error in create_folder: ', General._error_to_string(result['error']['code'])
        return False
Exemplo n.º 10
0
def get_tasks(security_id):
    api_path = 'DownloadStation/task.cgi'
    data_dict = {
        'api': 'SYNO.DownloadStation.Task',
        'version': 1,
        'method': 'list',
        '_sid': security_id
    }
    result = General._synology_call(api_path, data_dict)
    if not result['success']:
        print 'error in get_tasks: ', General._error_to_string(
            result['error']['code'])
    return result
Exemplo n.º 11
0
def test():
    try:
        id = General.login('test')
        ds_shares = list_shares(id)
        for share in ds_shares['data']['shares']:
            print share
        ds_files = list('/public/downloaded', id)
        for file in ds_files['data']['files']:
            if not file['isdir']:
                print file

        General.logout('test')
    except:
        print "error..."
Exemplo n.º 12
0
def read_elitetorrent():
    print "reading data from elitetorrent"
    d = feedparser.parse("http://www.elitetorrent.net/rss.php")
    if d["status"] == 200:
        print ("status ok, interpreting data")
        connection = get_mongo_client()
        torrents = connection.descargas.torrents
        # respuestas_rss = connection.descargas.respuestas_rss
        security_id = General.login(session_name())
        for theEntry in d["entries"]:
            treat_entry(theEntry, security_id, torrents)
        connection.close()
        General.logout(session_name())
    else:
        print ("status received from server is not 200, giving up...")
Exemplo n.º 13
0
def read_elitetorrent():
    print "reading data from elitetorrent"
    d = feedparser.parse('http://www.elitetorrent.net/rss.php')
    if d['status'] == 200:
        print('status ok, interpreting data')
        connection = get_mongo_client()
        torrents = connection.descargas.torrents
        # respuestas_rss = connection.descargas.respuestas_rss
        security_id = General.login(session_name())
        for theEntry in d['entries']:
            treat_entry(theEntry, security_id, torrents)
        connection.close()
        General.logout(session_name())
    else:
        print("status received from server is not 200, giving up...")
Exemplo n.º 14
0
def add_task(task_url, security_id):
    api_path = 'DownloadStation/task.cgi'
    data_dict = {
        'api': 'SYNO.DownloadStation.Task',
        'version': 1,
        'method': 'create',
        'uri': task_url,
        '_sid': security_id
    }
    result = General._synology_call(api_path, data_dict)
    if result['success']:
        return True
    else:
        print 'error in add_task: ', General._error_to_string(
            result['error']['code'])
        return False
Exemplo n.º 15
0
def delete_task(id, security_id):
    api_path = 'DownloadStation/task.cgi'
    data_dict = {
        'api': 'SYNO.DownloadStation.Task',
        'version': 1,
        'method': 'delete',
        'id': id,
        '_sid': security_id,
        'force_complete': 'false'
    }
    result = General._synology_call(api_path, data_dict)
    if result['success']:
        return True
    else:
        print 'error in delete_task: ', General._error_to_string(
            result['error']['code'])
        return False
Exemplo n.º 16
0
def download_previously_not_included():
    print "searching includes that were previously skipped"
    connection = get_mongo_client()
    security_id = General.login(session_name())
    torrents = connection.descargas.torrents
    """
    we go through includes checking if something that was not included neither
    excluded can be now marked as included
    """
    for include in includes:
        # print "checking include ", include['cadena'], " to see if we left something..."
        documento = {
            "titulo": re.compile(include['cadena'], re.IGNORECASE),
            "incluido": False,
            "excluido": False
        }
        for doc in torrents.find(documento):
            # we check if it has been downloaded by exact title
            titulo = doc['titulo']
            url = doc['url']
            if excluded(titulo):
                print "se encontro ", titulo, " que esta incluido por ", include['cadena'], \
                    " pero no se descarga por estar tambien excluido"
            else:
                encontrado = torrents.find_one({'titulo': titulo})
                if "descargado" not in encontrado or encontrado[
                        'descargado'] is False:
                    print "downloading ", titulo, " at url ", url
                    html = download_file.download_url_html(url)
                    magnets = download_file.download_magnet_in_html_regex(html)
                    for magnet in magnets:
                        DownloadStation.add_task(magnet, security_id)
                    encontrado['descargado'] = True
                    encontrado['incluido'] = True
                    torrents.save(encontrado)
                    print "updated document to remember that it was already downloaded, waiting 10 seg..."
                    time.sleep(
                        10
                    )  # wait 10 seconds trying not to trigger server DDOS counter measures
    General.logout(session_name())
    connection.close()
Exemplo n.º 17
0
def move_finished_to_destination():
    print "moving finished tasks to destination folder"
    security_id = General.login(session_name())
    tasks = DownloadStation.get_tasks(security_id)
    # for each task in download station
    for task in tasks['data']['tasks']:
        # where task has ended seeding
        if task['status'] == 'finished':
            title = unicode_functions.welcome_string(task['title'])
            id = task['id']
            for include in includes:
                # if the task was included automatically
                if include['cadena'].lower() in title.lower():
                    # we check if destination folder exists
                    info = FileStation.get_info(include['destino'],
                                                security_id)
                    if info['success']:
                        destino = info['data']['files'][0]
                        if 'code' in destino and destino['code'] == 408:
                            print "the directory does not exist, we create it"
                            norm = os.path.normpath(destino['path'])
                            nombre = os.path.basename(norm)
                            path = os.path.dirname(norm)
                            FileStation.create_folder(path, nombre,
                                                      security_id)
                        fichero_a_mover = download_dir() + '/' + title
                        if FileStation.move(fichero_a_mover, destino['path'],
                                            security_id):
                            print "moved ", fichero_a_mover, " to ", destino[
                                'path'], ", eliminando tarea"
                            if DownloadStation.delete_task(id, security_id):
                                print "deleted task ", id
                            #say.say("ya esta disponible el fichero " + title + " en el NAS")
                        else:
                            print "hubo un problema moviendo fichero ", title
                    else:
                        print "error obtaining info about ", include['destino']
    General.logout(session_name())
Exemplo n.º 18
0
def test():
    try:
        id = General.login('test')
        ds_info = get_info(id)
        print ds_info
        ds_config = get_config(id)
        print ds_config
        ds_tasks = get_tasks(id)
        for task in ds_tasks['data']['tasks']:
            print task
        delete_task('dbid_3652', id)
        #General.logout('test')
    except:
        print "error..."
Exemplo n.º 19
0
def test():
    try:
        id = General.login('test')
        ds_info = get_info(id)
        print ds_info
        ds_config = get_config(id)
        print ds_config
        ds_tasks = get_tasks(id)
        for task in ds_tasks['data']['tasks']:
            print task
        delete_task('dbid_3652', id)
        #General.logout('test')
    except:
        print "error..."