├── manage.py ├── musics ├── __init__.py ├── admin.py ├── apps.py ├── form.py ├── helper.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py ├── templatetags │ ├── __init__.py │ └── music_tags.py ├── tests.py ├── urls.py ├── validators.py └── views.py ├── requirements.txt ├── spotify_clone ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── templates ├── addPage.html └── home.html └── theme ├── __init__.py ├── apps.py ├── static └── css │ ├── styles.css │ └── styles.css.map ├── static_src ├── package-lock.json ├── package.json ├── postcss.config.js ├── src │ └── styles.scss └── tailwind.config.js └── templates └── base.html /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spotify_clone.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /musics/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OtchereDev/django-spotify-clone/d42215f7bec8db3fbbee66624dd3289fc6c91ae2/musics/__init__.py -------------------------------------------------------------------------------- /musics/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Music,Album 3 | 4 | admin.site.register(Music) 5 | admin.site.register(Album) -------------------------------------------------------------------------------- /musics/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class MusicsConfig(AppConfig): 5 | name = 'musics' 6 | -------------------------------------------------------------------------------- /musics/form.py: -------------------------------------------------------------------------------- 1 | from django.forms import widgets 2 | from musics.models import Music 3 | from django import forms 4 | 5 | class AddMusicForm(forms.ModelForm): 6 | album=forms.CharField(max_length=500,required=False) 7 | 8 | class Meta: 9 | model=Music 10 | fields=[ 11 | 'title', 12 | 'artiste', 13 | 14 | 'audio_file', 15 | 'cover_image', 16 | ] 17 | -------------------------------------------------------------------------------- /musics/helper.py: -------------------------------------------------------------------------------- 1 | from mutagen.mp3 import MP3 2 | 3 | def get_audio_length(file): 4 | audio = MP3(file) 5 | return audio.info.length 6 | -------------------------------------------------------------------------------- /musics/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.5 on 2021-03-19 14:48 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | import musics.validators 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='Album', 18 | fields=[ 19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('name', models.CharField(max_length=400)), 21 | ], 22 | ), 23 | migrations.CreateModel( 24 | name='Music', 25 | fields=[ 26 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 27 | ('title', models.CharField(max_length=500)), 28 | ('artiste', models.CharField(max_length=500)), 29 | ('time_length', models.DecimalField(blank=True, decimal_places=2, max_digits=20)), 30 | ('audio_file', models.FileField(upload_to='musics/', validators=[musics.validators.validate_is_audio])), 31 | ('cover_image', models.ImageField(upload_to='music_images/')), 32 | ('album', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='musics.album')), 33 | ], 34 | ), 35 | ] 36 | -------------------------------------------------------------------------------- /musics/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OtchereDev/django-spotify-clone/d42215f7bec8db3fbbee66624dd3289fc6c91ae2/musics/migrations/__init__.py -------------------------------------------------------------------------------- /musics/models.py: -------------------------------------------------------------------------------- 1 | from musics.helper import get_audio_length 2 | from django.db import models 3 | from .validators import validate_is_audio 4 | 5 | class Music(models.Model): 6 | title=models.CharField(max_length=500) 7 | artiste=models.CharField(max_length=500) 8 | album=models.ForeignKey('Album',on_delete=models.SET_NULL,null=True,blank=True) 9 | time_length=models.DecimalField(max_digits=20, decimal_places=2,blank=True) 10 | audio_file=models.FileField(upload_to='musics/',validators=[validate_is_audio]) 11 | cover_image=models.ImageField(upload_to='music_images/') 12 | 13 | def save(self,*args, **kwargs): 14 | if not self.time_length: 15 | # logic for getting length of audio 16 | audio_length=get_audio_length(self.audio_file) 17 | self.time_length =f'{audio_length:.2f}' 18 | 19 | return super().save(*args, **kwargs) 20 | 21 | class META: 22 | ordering="id" 23 | 24 | 25 | class Album(models.Model): 26 | name=models.CharField(max_length=400) -------------------------------------------------------------------------------- /musics/templatetags/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OtchereDev/django-spotify-clone/d42215f7bec8db3fbbee66624dd3289fc6c91ae2/musics/templatetags/__init__.py -------------------------------------------------------------------------------- /musics/templatetags/music_tags.py: -------------------------------------------------------------------------------- 1 | from django import template 2 | import math 3 | 4 | register=template.Library() 5 | 6 | @register.filter 7 | def time_formater(time): 8 | print(type(time)) 9 | time=int(time) 10 | min=math.floor((time%3600)/60) 11 | sec=math.floor(time%60) 12 | 13 | if (sec<10): 14 | sec=f"0{sec}" 15 | 16 | return f"{min}:{sec}" 17 | -------------------------------------------------------------------------------- /musics/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /musics/urls.py: -------------------------------------------------------------------------------- 1 | from musics.views import addMusic, homePage, musicList 2 | from django.urls import path 3 | 4 | app_name='musics' 5 | 6 | urlpatterns = [ 7 | path('',homePage,name='home_page'), 8 | path('add/',addMusic,name='add_music'), 9 | ] 10 | -------------------------------------------------------------------------------- /musics/validators.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from django.core.exceptions import ValidationError 4 | 5 | from mutagen.mp3 import MP3 6 | 7 | 8 | def validate_is_audio(file): 9 | 10 | try: 11 | audio = MP3(file) 12 | 13 | if not audio : 14 | raise TypeError() 15 | 16 | first_file_check=True 17 | 18 | except Exception as e: 19 | first_file_check=False 20 | 21 | if not first_file_check: 22 | raise ValidationError('Unsupported file type.') 23 | valid_file_extensions = ['.mp3'] 24 | ext = os.path.splitext(file.name)[1] 25 | if ext.lower() not in valid_file_extensions: 26 | raise ValidationError('Unacceptable file extension.') 27 | 28 | -------------------------------------------------------------------------------- /musics/views.py: -------------------------------------------------------------------------------- 1 | from musics.models import Album, Music 2 | from django.shortcuts import redirect, render 3 | from django.http import JsonResponse 4 | from .form import AddMusicForm 5 | 6 | def homePage(request): 7 | musics=list(Music.objects.all().values()) 8 | return render(request,'home.html',{ 9 | 'musics':musics 10 | }) 11 | 12 | def addMusic(request): 13 | form=AddMusicForm() 14 | 15 | if request.POST: 16 | form=AddMusicForm(request.POST,request.FILES) 17 | 18 | if form.is_valid(): 19 | instance=form.save(commit=False) 20 | album=form.cleaned_data.get('album') 21 | if album: 22 | music_album=Album.objects.get_or_create(name=album) 23 | print(music_album) 24 | instance.album=music_album[0] 25 | instance.save() 26 | return redirect("music:home_page") 27 | else: 28 | instance.save() 29 | return redirect("music:home_page") 30 | 31 | else: 32 | print("no",form.data) 33 | 34 | return render(request,'addPage.html',{ 35 | 'form':form 36 | }) 37 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.3.1 2 | Django==3.1.7 3 | django-tailwind==1.2.0 4 | mutagen==1.45.1 5 | Pillow==8.1.2 6 | pytz==2021.1 7 | sqlparse==0.4.1 8 | -------------------------------------------------------------------------------- /spotify_clone/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OtchereDev/django-spotify-clone/d42215f7bec8db3fbbee66624dd3289fc6c91ae2/spotify_clone/__init__.py -------------------------------------------------------------------------------- /spotify_clone/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for spotify_clone project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spotify_clone.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /spotify_clone/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for spotify_clone project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | import os 15 | 16 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 17 | BASE_DIR = Path(__file__).resolve().parent.parent 18 | 19 | 20 | # Quick-start development settings - unsuitable for production 21 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 22 | 23 | # SECURITY WARNING: keep the secret key used in production secret! 24 | SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY') 25 | 26 | # SECURITY WARNING: don't run with debug turned on in production! 27 | DEBUG = True 28 | 29 | ALLOWED_HOSTS = [] 30 | 31 | 32 | # Application definition 33 | 34 | INSTALLED_APPS = [ 35 | 'django.contrib.admin', 36 | 'django.contrib.auth', 37 | 'django.contrib.contenttypes', 38 | 'django.contrib.sessions', 39 | 'django.contrib.messages', 40 | 'django.contrib.staticfiles', 41 | 'musics', 42 | 'tailwind', 43 | 'theme' 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'spotify_clone.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [BASE_DIR/'templates'], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'spotify_clone.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': BASE_DIR / 'db.sqlite3', 84 | } 85 | } 86 | 87 | 88 | # Password validation 89 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 90 | 91 | AUTH_PASSWORD_VALIDATORS = [ 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 100 | }, 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 103 | }, 104 | ] 105 | 106 | 107 | # Internationalization 108 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 109 | 110 | LANGUAGE_CODE = 'en-us' 111 | 112 | TIME_ZONE = 'UTC' 113 | 114 | USE_I18N = True 115 | 116 | USE_L10N = True 117 | 118 | USE_TZ = True 119 | 120 | 121 | # Static files (CSS, JavaScript, Images) 122 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 123 | 124 | STATIC_URL = '/static/' 125 | MEDIA_URL='/media/' 126 | 127 | STATIC_ROOT= BASE_DIR/'static_root' 128 | MEDIA_ROOT= BASE_DIR/ 'media_root' 129 | 130 | STATICFILES_DIRS=[ 131 | BASE_DIR/'static' 132 | ] 133 | 134 | 135 | # Tailwind 136 | TAILWIND_APP_NAME = 'theme' -------------------------------------------------------------------------------- /spotify_clone/urls.py: -------------------------------------------------------------------------------- 1 | 2 | from django.conf.urls import include 3 | from django.contrib import admin 4 | from django.urls import path 5 | from django.conf import settings 6 | from django.conf.urls.static import static 7 | 8 | urlpatterns = [ 9 | path('admin/', admin.site.urls), 10 | path('',include('musics.urls',namespace='music')) 11 | ] 12 | 13 | 14 | if settings.DEBUG: 15 | urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) 16 | urlpatterns+=static(settings.STATIC_URL,document_root=settings.STATIC_ROOT) -------------------------------------------------------------------------------- /spotify_clone/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for spotify_clone project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'spotify_clone.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /templates/addPage.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block content %} 4 |