Skip to content

Commit

Permalink
UPDATED: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Sep 30, 2023
1 parent 1f9da83 commit 7ba4a88
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
8 changes: 0 additions & 8 deletions src/app/AppSingleton.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
from flask_login import LoginManager
from flask_httpauth import HTTPBasicAuth

from src.app.db import db
Expand All @@ -18,13 +17,6 @@
with app.app_context():
db.create_all()

'''
login_manager = LoginManager()
login_manager.init_app(app)
# The value refers to the function name that will handle the login process.
login_manager.login_view = "services.UserService.login"
login_manager.login_message_category = "danger"
'''
auth = HTTPBasicAuth()
auth.verify_password_callback = verify_password

Expand Down
25 changes: 12 additions & 13 deletions src/app/controllers/global_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
global_bp = Blueprint('global', __name__, url_prefix='/api/global')
api = Api(global_bp, doc='/doc', title='Global REST API', version='1.0')

videoService = YoutubeService()
youtubeService = YoutubeService()
compressionService = CompressionService()
playlistService = YoutubeMusicService()

youtubeMusicService = YoutubeMusicService()
userService = UserService()

root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
Expand All @@ -38,7 +37,7 @@ def download_playlist():
playlist_url = data['playlist_url']
request_uuid = uuid.uuid4()
current_download_path = os.path.join(download_path, "playlists", str(request_uuid))
directory_name = videoService.download_audio_playlist(playlist_url, current_download_path)
directory_name = youtubeService.download_audio_playlist(playlist_url, current_download_path)
print("Directory name for playlist is " + directory_name)
compressionService.zip_folder(os.path.join(current_download_path, directory_name),
os.path.join(current_download_path, directory_name + ".zip"))
Expand All @@ -52,7 +51,7 @@ def download_audio():
audio_url = data['audio_url']
request_uuid = uuid.uuid4()
current_download_path = os.path.join(download_path, "audios", str(request_uuid))
file_name = videoService.download_audio(audio_url, current_download_path)
file_name = youtubeService.download_audio(audio_url, current_download_path)
return send_file(os.path.join(current_download_path, file_name), as_attachment=True)


Expand All @@ -63,8 +62,8 @@ def upload_audio():
audio_url = data['audio_url']
request_uuid = uuid.uuid4()
current_download_path = os.path.join(download_path, "audios", str(request_uuid))
file_name = videoService.download_audio(audio_url, current_download_path)
return str(playlistService.upload_audio(os.path.join(current_download_path, file_name)))
file_name = youtubeService.download_audio(audio_url, current_download_path)
return str(youtubeMusicService.upload_audio(os.path.join(current_download_path, file_name)))


@global_bp.route('/uploadPlaylist', methods=['POST'])
Expand All @@ -74,9 +73,9 @@ def upload_playlist():
playlist_url = data['playlist_url']
request_uuid = uuid.uuid4()
current_download_path = os.path.join(download_path, "playlists", str(request_uuid))
directory_name = videoService.download_audio_playlist(playlist_url, current_download_path)
directory_name = youtubeService.download_audio_playlist(playlist_url, current_download_path)
print("DOWNLOADING FINISHED. STARTING UPLOAD<")
upload_infos = playlistService.upload_playlist(os.path.join(current_download_path, directory_name))
upload_infos = youtubeMusicService.upload_playlist(os.path.join(current_download_path, directory_name))
return "".join(str(upload_infos)) + "\n"


Expand All @@ -98,10 +97,10 @@ def upload_to_playlist():
playlist_url = data['playlist_url']
request_uuid = uuid.uuid4()
current_download_path = os.path.join(download_path, "playlists", str(request_uuid))
directory_name = playlistService.download_audio_playlist(playlist_url, current_download_path)
upload_infos = playlistService.upload_playlist(os.path.join(current_download_path, directory_name))
title, description = playlistService.download_playlist_data(playlist_url)
playlistService.save_playlist({'title': title, 'description': description})
directory_name = youtubeMusicService.download_audio_playlist(playlist_url, current_download_path)
upload_infos = youtubeMusicService.upload_playlist(os.path.join(current_download_path, directory_name))
title, description = youtubeMusicService.download_playlist_data(playlist_url)
youtubeMusicService.save_playlist({'title': title, 'description': description})


@global_bp.route('/secure_hello', methods=['GET'])
Expand Down
7 changes: 3 additions & 4 deletions src/app/controllers/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

userService = UserService()


@user_bp.route('/signup', methods=['POST'])
def register_user():
data = request.get_json()
Expand All @@ -24,21 +25,19 @@ def register_user():
if user_model is not None:
return "User with email " + email + " already exists in the database\n", 400
userService.create_user(email, password)
return "User created", 200
return "User created", 201


@user_bp.route('/login', methods=['POST'])
def log_in():
data = request.get_json()
email = data["email"]
password = data["password"]
print("LOG IN EMAIL:\t", email)
print("LOG IN PASSWORD:\t", password)
user_model = userService.get_user(email)
if user_model is None:
return "User with email " + email + " does not exist in the database\n", 404
elif user_model.password.__eq__(password):
# TODO implement authentication for the front-end
return "Logged in\n", 200
else:
return "Incorrect password\n", 404
return "Incorrect password\n", 401
2 changes: 1 addition & 1 deletion src/app/controllers/youtube_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from src.app.AppSingleton import auth
from src.app.services.YoutubeService import YoutubeService

youtube_bp = Blueprint('video', __name__, url_prefix='/api/youtube')
youtube_bp = Blueprint('video', __name__, url_prefix='/api/video')
api = Api(youtube_bp, doc='/doc', title='Video REST API', version='1.0')

video_fields = api.model('Video', {
Expand Down
1 change: 0 additions & 1 deletion src/app/services/YoutubeMusicService.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self):
elif os.path.isfile(token_absolute_path):
self.ytmusic = ytmusicapi.YTMusic(token_absolute_path)


def upload_audio(self, audio_path):
upload_info = self.ytmusic.upload_song(audio_path)
return upload_info
Expand Down

0 comments on commit 7ba4a88

Please sign in to comment.