mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2026-01-31 06:26:31 -06:00
add access timestamp and count updates with session commits
not sure how well I'm doing the session commits, I need help lol
This commit is contained in:
+6
-2
@@ -8,11 +8,14 @@ import re
|
|||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
# Retrieves the YouTubeAudio object relevant to the mediaid if available. If not, it facilitiates the creation and writing of one.
|
||||||
|
# Also helps with access times.
|
||||||
def get_youtube(mediaid):
|
def get_youtube(mediaid):
|
||||||
audio = YouTubeAudio.query.filter_by(id=mediaid).first()
|
audio = YouTubeAudio.query.filter_by(id=mediaid).first()
|
||||||
if audio is not None:
|
if audio is not None:
|
||||||
return audio
|
return audio.access()
|
||||||
|
|
||||||
|
# Returns the duration of a specificed media
|
||||||
@app.route('/stream/<service>/<mediaid>')
|
@app.route('/stream/<service>/<mediaid>')
|
||||||
def stream(service, mediaid):
|
def stream(service, mediaid):
|
||||||
if service == 'youtube':
|
if service == 'youtube':
|
||||||
@@ -24,7 +27,8 @@ def stream(service, mediaid):
|
|||||||
return Response('Not implemented', status=501, mimetype='application/json')
|
return Response('Not implemented', status=501, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
return Response('Bad request', status=400, mimetype='application/json')
|
return Response('Bad request', status=400, mimetype='application/json')
|
||||||
# Prepares a URL for download, returning the duration it should play for if streamed
|
|
||||||
|
# Returns the duration of a specific media
|
||||||
@app.route('/duration/<service>/<mediaid>')
|
@app.route('/duration/<service>/<mediaid>')
|
||||||
def duration(service, mediaid):
|
def duration(service, mediaid):
|
||||||
if service == 'youtube':
|
if service == 'youtube':
|
||||||
|
|||||||
@@ -12,9 +12,16 @@ class YouTubeAudio(db.Model):
|
|||||||
uploader = db.Column(db.String(32)) # 20 -> 32
|
uploader = db.Column(db.String(32)) # 20 -> 32
|
||||||
filename = db.Column(db.String(156)) # 128 + 11 + 1 -> 156
|
filename = db.Column(db.String(156)) # 128 + 11 + 1 -> 156
|
||||||
duration = db.Column(db.Integer)
|
duration = db.Column(db.Integer)
|
||||||
|
access_count = db.Column(db.Integer)
|
||||||
download_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
download_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||||
last_access_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
last_access_timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||||
|
|
||||||
|
def access(self):
|
||||||
|
self.access_count += 1
|
||||||
|
self.last_access_timestamp = datetime.utcnow()
|
||||||
|
db.session.commit()
|
||||||
|
return self
|
||||||
|
|
||||||
def getPath(self):
|
def getPath(self):
|
||||||
return os.path.join('app', 'sounds', 'youtube', self.filename)
|
return os.path.join('app', 'sounds', 'youtube', self.filename)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user