GithubHelp home page GithubHelp logo

lomank123 / shared-music Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 2.0 1.29 MB

Listen to music together

License: GNU General Public License v3.0

Python 50.36% HTML 7.20% JavaScript 26.57% CSS 11.96% Dockerfile 0.98% Shell 2.92%
django docker python websocket channels nginx-docker

shared-music's Introduction

shared-music

Alt text

Shared Music service provides you rooms where you can listen to music with friends or anyone else who wants to come in. All you have to do is click create room button and share the link. It's that simple! See all the features here.

Main goals:

  • Provide useful service which will let anyone create music rooms for shared listening and communicating
  • Construct WebSocket-based application
  • Gain team work experience

Live version can be visited at: sharedmusic.me

License: GPL v3 codecov

Table of contents

Requirements (Prerequisites)

Installation

  • Clone repository:
git clone https://github.com/Lomank123/shared-music.git
  • Go to project root folder, create .env file and copy the contents of .env.sample to it.

For Linux:

cd path/to/project/shared-music
cp .env.sample .env

Create /backups folder (if you want to use backups):

mkdir backups

Docker setup

  • Open /sharedmusic/sharedmusic/settings/settings.py and find CHANNEL_LAYERS variable. Replace
"hosts": [(REDIS_HOST, 6379)],

with

"hosts": [('redis', 6379)],
  • Build everything:
docker-compose build

For the first time it may take 5-20 minutes to build everything (depends on your internet connection and PC hardware)

Local setup (without Docker containers)

  • First, set appropriate channel layer. In /sharedmusic/sharedmusic/settings/settings.py you can find CHANNEL_LAYERS:
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'main.channel_layers.CustomChannelLayer',
        'CONFIG': {
            "hosts": [(REDIS_HOST, 6379)],
        },
    },
}
  • There are 2 supported ones:

    • channels.layers.InMemoryChannelLayer
    • main.channel_layers.CustomChannelLayer - custom implementation of channels_redis.pubsub.RedisPubSubChannelLayer
  • Next is venv setup:

mkdir venv
cd venv
py -m venv ./venv
  • Install requirements:
pip install -r requirements.txt
  • Create Postgres db and user (credentials should be the same as in .env file)

  • Also change DB_HOST env var in .env file from 'db' to 'localhost':

DB_HOST=localhost
  • Go to /sharedmusic dir:
cd sharedmusic
  • Migrations:
py manage.py makemigrations
py manage.py migrate
  • Create superuser:
py manage.py createsuperuser

Screenshots

  • Home page:

Home page

  • Navbar:

Navbar

  • Authorization:

Authorization

  • Room page:

Room page

  • Mobile version

Mobile version

Features

Main features

  • Create room in one click
  • Invite anyone by sharing the link
  • Communicate by sending messages to room chat
  • Load tracks from YouTube (other services WIP)
  • User playlist (WIP)
  • Save/Load room playlist (WIP)
  • Download urls from room or user playlist (WIP)

Tech features

  • CI/CD
  • Both asgi and wsgi apps (daphne and gunicorn) to serve http and WebSocket connections.
  • WebSocket protocol to keep changes in rooms
  • Nginx reverse proxy to serve static files and WebSockets
  • Celery tasks
    • To remove abandoned rooms (periodically)

Room host features

  • Change permissions
    • change/add/delete track
    • pause/play track
    • change time of current track
  • Transfer ownership to any listener
  • Ban/unban any listener
  • Mute/unmute any listener

Usage

Run project

Locally

  • Run Redis if you use CustomChannelLayer

  • Run these commands:

cd sharedmusic
py manage.py runserver

Using Docker

  • Run:
docker-compose up

Fixtures

  • To fill the database:
docker-compose up filldb

dev.json fixtures contain

  • Superuser
  • Regular user
  • Room
  • Room playlist
  • Soundtrack
  • Room playlist track
  • Chat messages

Users credentials

  • Superuser:
    • username: admin
    • password: 12345
  • User:
    • username: test1
    • password: 123123123Aa

Backup

  • Assuming you have created /backups dir you can just run pgbackups container
docker-compose up pgbackups

If you want to configure it follow here

Restore

  • Run db container
docker-compose up db
  • Enter there via docker exec sh:
docker exec -t -i shared-music_db_1 sh
  • In db container create backups folder:
mkdir backups
  • Copy backup file to db container (here I used path from my pc):
docker cp D:\path\to\folder\backups\last\backupfile.sql.gz shared-music_db_1:/backups

Replace backupfile.sql.gz with your actual backup file name (located at backups\last for example)

  • Run restoration command (replace $USERNAME and $DBNAME with .env variables (DB_USER and DB_NAME), and also $BACKUPFILE with previously copied file name)
docker exec --tty --interactive shared-music_db_1 /bin/sh -c "zcat backups/$BACKUPFILE | psql --username=$USERNAME --dbname=$DBNAME -W"
  • Enter password (DB_PASS variable in .env)

  • Check restored db

Tests

  • To run tests:
docker-compose up test

Tests description

These tests cover:

  • channels Consumers
  • Services
  • Celery tasks
  • Views

Services and consumers tests run using InMemoryChannelLayer.

Deployment

Assuming remote host OS is Linux, and Docker, docker-compose and Git have been installed recently:

  • Enter remote host's console via ssh (where IP is your host ip address):
ssh -l username IP

Fill in password after this command.

  • Follow installation guide

  • To run production version you should use:

docker-compose -f docker-compose-deploy.yml up

Tech stack

  • Backend:
    • Django 3
    • channels
    • Redis
    • Gunicorn
    • Daphne
    • PostgreSQL
    • Coverage
    • Celery
    • Nginx
  • Frontend:
    • YouTube API
    • jQuery
  • Other:
    • GitHub
    • Codecov
    • Docker
    • docker-compose

Authors

shared-music's People

Contributors

erikgab01 avatar lomank123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

shared-music's Issues

Bug fix please

  • 150 символов ник
  • русские символы

unknown

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.