CC-5709: Airtime Analyzer

* Overhauled Add Media screen, now shows state of recent uploads
* Dropped old unused "state" column, added new file_import column to cc_files
* New PluploadController methods
* Save the filename as the track title for unprocessed uploads
* Hide pending files from the library until they've been processed.
* Don't overwrite files with duplicate names, we rename them instead.
This commit is contained in:
Albert Santoni 2014-03-21 13:22:00 -04:00
parent 2b696dbee5
commit 878dd11ccc
7 changed files with 122 additions and 37 deletions

View file

@ -2,6 +2,8 @@ import logging
import multiprocessing
import shutil
import os, errno
import time
import uuid
from metadata_analyzer import MetadataAnalyzer
class AnalyzerPipeline:
@ -33,6 +35,9 @@ class AnalyzerPipeline:
# back to the main process.
#Import the file over to it's final location.
#TODO: Move all this file moving stuff to its own Analyzer class.
# Also, handle the case where the move fails and write some code
# to possibly move the file to problem_files.
final_file_path = import_directory
if results.has_key("artist_name"):
@ -44,16 +49,28 @@ class AnalyzerPipeline:
#Ensure any redundant slashes are stripped
final_file_path = os.path.normpath(final_file_path)
#final_audio_file_path = final_directory + os.sep + os.path.basename(audio_file_path)
#If a file with the same name already exists in the "import" directory, then
#we add a unique string to the end of this one. We never overwrite a file on import
#because if we did that, it would mean Airtime's database would have
#the wrong information for the file we just overwrote (eg. the song length would be wrong!)
if os.path.exists(final_file_path) and not os.path.samefile(audio_file_path, final_file_path):
raise Exception("File exists and will not be overwritten.") # by design
#Overwriting a file would mean Airtime's database has the wrong information...
#If the final file path is the same as the file we've been told to import (which
#you often do when you're debugging), then don't move the file at all.
base_file_path, file_extension = os.path.splitext(final_file_path)
final_file_path = "%s_%s%s" % (base_file_path, time.strftime("%m-%d-%Y-%H-%M-%S", time.localtime()), file_extension)
#If THAT path exists, append a UUID instead:
while os.path.exists(final_file_path):
base_file_path, file_extension = os.path.splitext(final_file_path)
final_file_path = "%s_%s%s" % (base_file_path, str(uuid.uuid4()), file_extension)
#Ensure the full path to the file exists
mkdir_p(os.path.dirname(final_file_path))
#Move the file into its final destination directory
shutil.move(audio_file_path, final_file_path)
#Ensure the full path to the file exists
mkdir_p(os.path.dirname(final_file_path))
#Move the file into its final destination directory
shutil.move(audio_file_path, final_file_path)
#Pass the full path back to Airtime
results["full_path"] = final_file_path

View file

@ -100,7 +100,9 @@ class MetadataAnalyzer(Analyzer):
#Airtime <= 2.5.x nonsense:
metadata["ftype"] = "audioclip"
#Other fields we'll want to set for Airtime:
metadata["cueout"] = metadata["length"]
metadata["hidden"] = False
return metadata