コード例 #1
0
ファイル: cutting.py プロジェクト: ekimekim/rdp-cutter
def process(sheet, row, no_update_state=False):
	"""For given row, perform the cutting process"""

	def update_state(state):
		if not no_update_state:
			update_column(sheet, row['id'], 'Processed by VST', state)

	if not os.path.exists(TMPDIR):
		try:
			os.mkdir(TMPDIR)
		except OSError as e:
			if e.errno != errno.EEXIST:
				raise

	filebase = '{}/{}'.format(TMPDIR, uuid4())
	logging.info("Processing row {id}({Song!r}) at path {filebase}".format(filebase=filebase, **row))
	logging.debug("Row values: {}".format(row))

	source_file = None
	dest_file = None
	try:
		logging.debug("Downloading {}".format(filebase))
		source_file = youtube_dl(row['YouTube Link'], '{}-source'.format(filebase))

		dest_file = '{}-cut.m4a'.format(filebase)
		logging.debug("Converting {} -> {}".format(source_file, dest_file))
		convert(
			source=source_file,
			dest=dest_file,
			start=parse_time(row['Start Time']),
			end=parse_time(row['End Time']),
			title=row['Song'],
			artist=row['Artist'],
			category=row['Category'],
			fade_in=parse_time(row['Fade In?']),
			fade_out=parse_time(row['Fade Out?']),
		)

		name = str(row['Song']) or 'no-title'.format(row['id'])
		name = name.replace(' ', '_')
		name = ''.join(c for c in name.lower() if c in string.letters + string.digits + '._-')
		name = '{}-{}'.format(row['id'], name)
		logging.debug("Uploading {} as {}".format(dest_file, name))
		url = upload(dest_file, name)
		update_column(sheet, row['id'], 'Processed Link', url)

	except Exception:
		logging.exception("Error while cutting {}".format(row))
		update_state('Errored')
		raise
	else:
		update_state('Complete')
	finally:
		for name in (source_file, dest_file):
			if name and os.path.exists(name):
				os.remove(name)

	logging.info("Processed row {id}({Song!r}) successfully".format(**row))
コード例 #2
0
ファイル: main.py プロジェクト: ekimekim/rdp-cutter
def start_jobs(jobs, sheet, no_update_state=False, **kwargs):
	"""Find any new jobs to do and start them in the background"""
	for row in get_rows_to_do(sheet, **kwargs):
		logging.debug("Trying to start job {}".format(row['id']))
		jobs.wait_available()
		if not no_update_state:
			update_column(sheet, row['id'], 'Processed by VST', 'In Progress')
		jobs.spawn(process, sheet, row, no_update_state=no_update_state)
		logging.debug("Started job {}".format(row['id']))
コード例 #3
0
ファイル: main.py プロジェクト: warandpeace/rdp-cutter
def start_jobs(jobs, sheet, no_update_state=False, **kwargs):
    """Find any new jobs to do and start them in the background"""
    for row in get_rows_to_do(sheet, **kwargs):
        logging.debug("Trying to start job {}".format(row['id']))
        jobs.wait_available()
        if not no_update_state:
            update_column(sheet, row['id'], 'Processed by VST', 'In Progress')
        jobs.spawn(process, sheet, row, no_update_state=no_update_state)
        logging.debug("Started job {}".format(row['id']))
コード例 #4
0
def process(sheet, row, no_update_state=False):
    """For given row, perform the cutting process"""
    def update_state(state):
        if not no_update_state:
            update_column(sheet, row['id'], 'Processed by VST', state)

    filebase = '{}/{}'.format(TMPDIR, uuid4())
    logging.info("Processing row {id}({Song!r}) at path {filebase}".format(
        filebase=filebase, **row))
    logging.debug("Row values: {}".format(row))

    try:
        logging.debug("Downloading {}".format(filebase))
        source_file = youtube_dl(row['YouTube Link'],
                                 '{}-source'.format(filebase))

        dest_file = '{}-cut.m4a'.format(filebase)
        logging.debug("Converting {} -> {}".format(source_file, dest_file))
        convert(
            source=source_file,
            dest=dest_file,
            start=parse_time(row['Start Time']),
            end=parse_time(row['End Time']),
            title=row['Song'],
            artist=row['Artist'],
            category=row['Category'],
            fade_in=parse_time(row['Fade In?']),
            fade_out=parse_time(row['Fade Out?']),
        )

        name = str(row['Song']) or 'no-title'.format(row['id'])
        name = name.replace(' ', '_')
        name = ''.join(c for c in name.lower()
                       if c in string.letters + string.digits + '._-')
        name = '{}-{}'.format(row['id'], name)
        logging.debug("Uploading {} as {}".format(dest_file, name))
        url = upload(dest_file, name)
        update_column(sheet, row['id'], 'Processed Link', url)

    except Exception:
        logging.exception("Error while cutting {}".format(row))
        update_state('Errored')
        raise
    else:
        update_state('Complete')

    logging.info("Processed row {id}({Song!r}) successfully".format(**row))
コード例 #5
0
 def update_state(state):
     if not no_update_state:
         update_column(sheet, row['id'], 'Processed by VST', state)
コード例 #6
0
ファイル: cutting.py プロジェクト: ekimekim/rdp-cutter
	def update_state(state):
		if not no_update_state:
			update_column(sheet, row['id'], 'Processed by VST', state)