mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2026-01-31 10:26:36 -06:00
begin clearing out old sound functions, add downloader function
most of these are untested and definitely very buggy, just moving stuff around for now
This commit is contained in:
+9
-1
@@ -15,10 +15,14 @@ class YouTubeAudio(db.Model):
|
||||
download_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||
last_access_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||
|
||||
def getPath(self):
|
||||
return os.path.join('app', 'sounds', 'youtube', self.filename)
|
||||
|
||||
def file_exists(self):
|
||||
return os.path.exists(os.path.join('app', 'sounds', 'youtube', self.filename))
|
||||
return os.path.exists(self.getPath())
|
||||
|
||||
def fill_metadata(self):
|
||||
# Use stdout=PIPE, [Python 3.6] production server support instead of 'capture_output=True' => 'process.stdout'
|
||||
self.url = f'https://www.youtube.com/watch?v={self.id}'
|
||||
processFilename = subprocess.Popen(['youtube-dl', '-x', '--audio-format', 'mp3', '--restrict-filenames', '--get-filename', self.url],
|
||||
encoding='utf-8', stdout=subprocess.PIPE)
|
||||
@@ -31,6 +35,10 @@ class YouTubeAudio(db.Model):
|
||||
self.uploader = data['uploader'] or data['creator']
|
||||
self.title = data['title'] or data['alt_title'] # Do not trust alt-title ; it is volatile and uploader set, e.x. https://i.imgur.com/Tgff4rI.png
|
||||
|
||||
def download(self):
|
||||
subprocess.run(['youtube-dl', '-x', '--restrict-filenames', '--audio-format', 'mp3', self.id])
|
||||
os.rename(self.filename, self.getPath())
|
||||
|
||||
class SoundcloudAudio(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True) # hidden API-accessible only ID
|
||||
url = db.Column(db.String(256))
|
||||
|
||||
Reference in New Issue
Block a user