mirror of
				https://github.com/bspeice/Melodia
				synced 2025-11-04 02:10:42 -05:00 
			
		
		
		
	Add code to convert songs using audiotools
This commit is contained in:
		@ -78,3 +78,18 @@ class Song (models.Model):
 | 
				
			|||||||
			from Melodia.melodia_settings import HASH_FUNCTION as hash
 | 
								from Melodia.melodia_settings import HASH_FUNCTION as hash
 | 
				
			||||||
			f              = open(self.url, 'rb')
 | 
								f              = open(self.url, 'rb')
 | 
				
			||||||
			self.file_hash = hash(f.read())
 | 
								self.file_hash = hash(f.read())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						def convert(self, output_location, output_format, progress_func = lambda x, y: None):
 | 
				
			||||||
 | 
							"Convert a song to a new format, optionally specifying what format to convert to."
 | 
				
			||||||
 | 
							#Note that output_format over-rides the format guessed by output_location
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							from Melodia.resources import add_resource_dir
 | 
				
			||||||
 | 
							add_resource_dir()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							import audiotools
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							convert_from = audiotools.open(self.url)
 | 
				
			||||||
 | 
							convert_from.convert(output_location,
 | 
				
			||||||
 | 
													output_format,
 | 
				
			||||||
 | 
													progress_func)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user