├── docs ├── authors.rst ├── history.rst ├── readme.rst ├── contributing.rst ├── .gitignore ├── _static │ └── logo.png ├── index.rst ├── installation.rst ├── usage.rst ├── Makefile ├── make.bat └── conf.py ├── tests ├── __init__.py └── test_playlistfromsong.py ├── playlistfromsong ├── __init__.py ├── cli.py ├── server.py ├── assets │ ├── js │ │ ├── index.js │ │ ├── prefixfree.min.js │ │ ├── html5media.min.js │ │ └── jquery.min.js │ └── css │ │ ├── style.css │ │ └── style2.css ├── templates │ └── index.html └── playlistfromsong.py ├── requirements_dev.txt ├── AUTHORS.rst ├── HISTORY.rst ├── MANIFEST.in ├── setup.cfg ├── .travis.yml ├── .gitattributes ├── tox.ini ├── .gitignore ├── LICENSE ├── README.rst ├── setup.py ├── Makefile └── CONTRIBUTING.rst /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst 2 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | /playlistfromsong.rst 2 | /playlistfromsong.*.rst 3 | /modules.rst 4 | -------------------------------------------------------------------------------- /docs/_static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/schollz/playlistfromsong/HEAD/docs/_static/logo.png -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """Unit test package for playlistfromsong.""" 4 | -------------------------------------------------------------------------------- /playlistfromsong/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """Top-level package for playlistfromsong.""" 4 | 5 | __author__ = """Zack""" 6 | __email__ = 'hypercube.platforms@gmail.com' 7 | __version__ = '2.1.1' 8 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | pip==9.0.1 2 | bumpversion==0.5.3 3 | wheel==0.29.0 4 | watchdog==0.8.3 5 | flake8==3.5.0 6 | tox==2.7.0 7 | coverage==4.4.1 8 | Sphinx==1.6.5 9 | 10 | pytest==3.2.3 11 | pytest-runner==3.0 12 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Zack 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? 14 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | History 3 | ======= 4 | 5 | 2.0.0 (2017-07-04) 6 | ------------------ 7 | 8 | * New ``--server`` option for starting a music server 9 | 10 | 1.0.0 (2017-06-25) 11 | ------------------ 12 | 13 | * Move to cookiecutter for improved packaging and tests 14 | 15 | 0.21.0 (2017-03-29) 16 | ------------------ 17 | 18 | * First stable release -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to playlistfromsong's documentation! 2 | ====================================== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | readme 10 | installation 11 | usage 12 | modules 13 | contributing 14 | authors 15 | history 16 | 17 | Indices and tables 18 | ================== 19 | 20 | * :ref:`genindex` 21 | * :ref:`modindex` 22 | * :ref:`search` 23 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | 7 | recursive-include tests * 8 | recursive-include playlistfromsong/assets * 9 | recursive-include playlistfromsong/templates * 10 | recursive-exclude * __pycache__ 11 | recursive-exclude * *.py[co] 12 | 13 | recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif 14 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 2.1.1 3 | commit = True 4 | tag = True 5 | 6 | [bumpversion:file:setup.py] 7 | search = version='{current_version}' 8 | replace = version='{new_version}' 9 | 10 | [bumpversion:file:playlistfromsong/__init__.py] 11 | search = __version__ = '{current_version}' 12 | replace = __version__ = '{new_version}' 13 | 14 | [bdist_wheel] 15 | universal = 1 16 | 17 | [flake8] 18 | exclude = docs 19 | 20 | [aliases] 21 | test = pytest 22 | 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "3.5" 5 | before_script: 6 | - sudo apt-get install -y libav-tools 7 | - sudo apt-get install -y libavcodec-extra-* 8 | - wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz 9 | - tar xvfJ ffmpeg-git-64bit-static.tar.xz 10 | - sudo mv ffmpeg-git-*/ffmpeg /usr/bin/ffmpeg 11 | - sudo pip install playlistfromsong 12 | install: 13 | # python 14 | - pip install -e . 15 | script: 16 | - make test 17 | after_success: 18 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Basic .gitattributes for a python repo. 2 | 3 | docs/* linguist-vendored 4 | playlistfromsong/assets/* linguist-vendored 5 | playlistfromsong/templates/* linguist-vendored 6 | 7 | # Source files 8 | # ============ 9 | *.pxd text 10 | *.py text 11 | *.py3 text 12 | *.pyw text 13 | *.pyx text 14 | 15 | # Binary files 16 | # ============ 17 | *.db binary 18 | *.p binary 19 | *.pkl binary 20 | *.pyc binary 21 | *.pyd binary 22 | *.pyo binary 23 | 24 | # Note: .db, .p, and .pkl files are associated 25 | # with the python modules ``pickle``, ``dbm.*``, 26 | # ``shelve``, ``marshal``, ``anydbm``, & ``bsddb`` 27 | # (among others). 28 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py26, py27, py33, py34, py35, flake8 3 | 4 | [travis] 5 | python = 6 | 3.5: py35 7 | 3.4: py34 8 | 3.3: py33 9 | 2.7: py27 10 | 2.6: py26 11 | 12 | [testenv:flake8] 13 | basepython=python 14 | deps=flake8 15 | commands=flake8 playlistfromsong 16 | 17 | [testenv] 18 | setenv = 19 | PYTHONPATH = {toxinidir} 20 | deps = 21 | -r{toxinidir}/requirements_dev.txt 22 | commands = 23 | pip install -U pip 24 | py.test --basetemp={envtmpdir} 25 | 26 | 27 | ; If you want to make tox run the tests with the same versions, create a 28 | ; requirements.txt with the pinned versions and uncomment the following lines: 29 | ; deps = 30 | ; -r{toxinidir}/requirements.txt 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | # pyenv python configuration file 62 | .python-version 63 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | MIT License 3 | 4 | Copyright (c) 2017, Zack 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | 12 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ============ 4 | Installation 5 | ============ 6 | 7 | 8 | Stable release 9 | -------------- 10 | 11 | To install playlistfromsong, run this command in your terminal: 12 | 13 | .. code-block:: console 14 | 15 | $ pip install playlistfromsong 16 | 17 | This is the preferred method to install playlistfromsong, as it will always install the most recent stable release. 18 | 19 | If you don't have `pip`_ installed, this `Python installation guide`_ can guide 20 | you through the process. 21 | 22 | .. _pip: https://pip.pypa.io 23 | .. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/ 24 | 25 | 26 | From sources 27 | ------------ 28 | 29 | The sources for playlistfromsong can be downloaded from the `Github repo`_. 30 | 31 | You can either clone the public repository: 32 | 33 | .. code-block:: console 34 | 35 | $ git clone git://github.com/schollz/playlistfromsong 36 | 37 | Or download the `tarball`_: 38 | 39 | .. code-block:: console 40 | 41 | $ curl -OL https://github.com/schollz/playlistfromsong/tarball/master 42 | 43 | Once you have a copy of the source, you can install it with: 44 | 45 | .. code-block:: console 46 | 47 | $ python setup.py install 48 | 49 | 50 | .. _Github repo: https://github.com/schollz/playlistfromsong 51 | .. _tarball: https://github.com/schollz/playlistfromsong/tarball/master 52 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Usage 3 | ===== 4 | 5 | Generate a playlist from song 6 | ------------------------------ 7 | 8 | Download a playlist from a song by specifying the artist and the song:: 9 | 10 | playlistfromsong -s 'Miles Davis Blue In Green' 11 | 12 | By default, three songs are downloaded (the original song plus 2 that are similar), but you can change this with ``-n``:: 13 | 14 | playlistfromsong -s 'Miles Davis Blue In Green' -n 30 15 | 16 | By default, the similar songs are found using last.fm, but you can choose to use Spotify instead, by providing a bearer token. Obtain a bearer token by going to https://developer.spotify.com/web-api/console/get-track/ and click "Get OAUTH_TOKEN". Then apply your token::: 17 | 18 | playlistfromsong -s 'Miles Davis Blue In Green' -n 30 -b 'TOKEN' 19 | 20 | 21 | Finally, you can specify a specific place to store the files by using the ``-f`` flag:: 22 | 23 | playlistfromsong -s 'Miles Davis Blue In Green' -f /music 24 | 25 | 26 | Simple music server 27 | -------------------- 28 | 29 | There is a built-in simple music server that you can use to play your music, but also includes an API for webhooks for automatically generating playlists from songs. 30 | 31 | Star the server using:: 32 | 33 | playlistfromsong --serve -f /path/to/music 34 | 35 | The default port is 5000, and you should be able to see your server at http://localhost:5000. You can also specify the port with ``--port X``. 36 | 37 | There are routes for directly downloading songs. For instance, to generate a playlist in the current folder, just open:: 38 | 39 | http://localhost:5000/download/10/Miles Davis Blue In Green 40 | 41 | This is very effective for using with IFTTT to automatically download playlists based on songs that are liked on Youtube / Spotify. 42 | 43 | 44 | -------------------------------------------------------------------------------- /tests/test_playlistfromsong.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """Tests for `playlistfromsong` package.""" 5 | 6 | import pytest 7 | 8 | from click.testing import CliRunner 9 | from os.path import isfile 10 | from os import remove 11 | 12 | from playlistfromsong import playlistfromsong 13 | from playlistfromsong import cli 14 | 15 | 16 | @pytest.fixture 17 | def response(): 18 | """Sample pytest fixture. 19 | 20 | See more at: http://doc.pytest.org/en/latest/fixture.html 21 | """ 22 | # import requests 23 | # return requests.get('https://github.com/audreyr/cookiecutter-pypackage') 24 | 25 | 26 | def test_content(response): 27 | """Sample pytest test function with the pytest fixture as an argument.""" 28 | # from bs4 import BeautifulSoup 29 | # assert 'GitHub' in BeautifulSoup(response.content).title.string 30 | 31 | def test_mainfunctions(response): 32 | """Test the main functions from playlistfrom song""" 33 | assert playlistfromsong.getYoutubeURLFromSearch('Led Zepplin Stairway to Heaven') == "https://www.youtube.com/watch?v=IS6n2Hx9Ykk" 34 | assert playlistfromsong.getCodecAndQuality() == ('mp3', '192') 35 | # assert playlistfromsong.downloadURL("https://www.youtube.com/watch?v=IS6n2Hx9Ykk") != None 36 | # assert isfile('Led Zeppelin - Stairway To Heaven (NOT LIVE) (Perfect Audio)-IS6n2Hx9Ykk.mp3') 37 | # remove('Led Zeppelin - Stairway To Heaven (NOT LIVE) (Perfect Audio)-IS6n2Hx9Ykk.mp3') 38 | assert len(playlistfromsong.useLastFM("Led Zepplin Stairway to Heaven",3)) == 3 39 | 40 | def test_command_line_interface(): 41 | """Test the CLI.""" 42 | runner = CliRunner() 43 | result = runner.invoke(cli.main) 44 | assert result.exit_code == 0 45 | help_result = runner.invoke(cli.main, ['--help']) 46 | assert help_result.exit_code == 0 47 | # assert '--help Show this message and exit.' in help_result.output 48 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | playlistfromsong 3 | ================ 4 | 5 | 6 | .. image:: https://img.shields.io/pypi/v/playlistfromsong.svg 7 | :target: https://pypi.python.org/pypi/playlistfromsong 8 | 9 | .. image:: https://img.shields.io/travis/schollz/playlistfromsong.svg 10 | :target: https://travis-ci.org/schollz/playlistfromsong 11 | 12 | .. image:: https://readthedocs.org/projects/playlistfromsong/badge/?version=latest 13 | :target: https://playlistfromsong.readthedocs.io/en/latest/?badge=latest 14 | :alt: Documentation Status 15 | 16 | .. image:: https://pyup.io/repos/github/schollz/playlistfromsong/shield.svg 17 | :target: https://pyup.io/repos/github/schollz/playlistfromsong/ 18 | :alt: Updates 19 | 20 | 21 | Generate an offline playlist from a single song. 22 | 23 | Features 24 | --------- 25 | 26 | - Similar song matching using last.fm or Spotify 27 | - Automatic downloading of songs 28 | - Builtin music server for webhooks 29 | 30 | Quickstart 31 | ------------ 32 | 33 | First install `ffmpeg`_: 34 | 35 | :: 36 | 37 | sudo apt-get install ffmpeg (DEBIAN) 38 | brew install ffmpeg (MAC) 39 | 40 | .. _ffmpeg: https://ffmpeg.org/download.html 41 | 42 | Install with ``pip``:: 43 | 44 | pip install playlistfromsong 45 | 46 | 47 | Download a playlist of 5 songs similar to Miles Davis' *Blue In Green*:: 48 | 49 | playlistfromsong --song 'Miles Davis Blue In Green' --num 5 -f /path/to/save 50 | 51 | .. image:: http://i.imgur.com/ldVHZcc.gif 52 | :target: http://i.imgur.com/ldVHZcc.gif 53 | :alt: Demo1 54 | 55 | Use a bearer token ``--bearer`` to use Spotify to find suggestions:: 56 | 57 | playlistfromsong --song 'Miles Davis Blue In Green' --num 5 -f /path/to/save -b 'BEARER' 58 | 59 | .. image:: http://i.imgur.com/uzEEEFh.gif 60 | :target: http://i.imgur.com/uzEEEFh.gif 61 | :alt: Demo1 62 | 63 | 64 | For more complete usage, see the docs. 65 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """The setup script.""" 5 | 6 | from setuptools import setup, find_packages 7 | 8 | with open('README.rst') as readme_file: 9 | readme = readme_file.read() 10 | 11 | with open('HISTORY.rst') as history_file: 12 | history = history_file.read() 13 | 14 | requirements = [ 15 | 'Click>=6.0', 16 | "requests", 17 | "youtube_dl", 18 | 'appdirs', 19 | 'pyyaml', 20 | 'beautifulsoup4', 21 | "flask", 22 | "waitress", 23 | ] 24 | 25 | setup_requirements = [ 26 | # 'pytest-runner', 27 | ] 28 | 29 | test_requirements = [ 30 | 'pytest', 31 | ] 32 | 33 | setup( 34 | name='playlistfromsong', 35 | version='2.2.2', 36 | description="Generate an offline playlist from a single song", 37 | long_description=readme + '\n\n' + history, 38 | author="Zack", 39 | author_email='hypercube.platforms@gmail.com', 40 | url='https://github.com/schollz/playlistfromsong', 41 | packages=find_packages(include=['playlistfromsong']), 42 | entry_points={ 43 | 'console_scripts': [ 44 | 'playlistfromsong=playlistfromsong.cli:main' 45 | ] 46 | }, 47 | include_package_data=True, 48 | install_requires=requirements, 49 | license="MIT license", 50 | zip_safe=False, 51 | keywords='playlistfromsong', 52 | classifiers=[ 53 | 'Development Status :: 2 - Pre-Alpha', 54 | 'Intended Audience :: Developers', 55 | 'License :: OSI Approved :: MIT License', 56 | 'Natural Language :: English', 57 | "Programming Language :: Python :: 2", 58 | 'Programming Language :: Python :: 2.6', 59 | 'Programming Language :: Python :: 2.7', 60 | 'Programming Language :: Python :: 3', 61 | 'Programming Language :: Python :: 3.3', 62 | 'Programming Language :: Python :: 3.4', 63 | 'Programming Language :: Python :: 3.5', 64 | ], 65 | test_suite='tests', 66 | tests_require=test_requirements, 67 | setup_requires=setup_requirements, 68 | ) 69 | -------------------------------------------------------------------------------- /playlistfromsong/cli.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """Console script for playlistfromsong.""" 4 | 5 | import click 6 | from sys import exit 7 | from os import getcwd 8 | 9 | # For running as package 10 | try: 11 | from .playlistfromsong import run, getTopFromLastFM 12 | from .server import run_server 13 | except: 14 | from playlistfromsong import run, getTopFromLastFM 15 | from server import run_server 16 | 17 | from sys import version_info 18 | 19 | # # For running as script 20 | # from playlistfromsong import run 21 | # from server import run_server 22 | 23 | 24 | @click.command() 25 | @click.option('--num', '-n', default=3, help='Number of songs.') 26 | @click.option('--song', '-s', default=None, help='Artist + Song to seed.') 27 | @click.option('--bearer', '-b', default=None, help='Bearer token for Spotify.') 28 | @click.option('--folder', '-f', default=None, help='Folder to save files.') 29 | @click.option('--serve', is_flag=True, help='Start personal web server.') 30 | @click.option('--port', default="5000", help='Internal port to run server (e.g. 5000).') 31 | def main(num, song, bearer, folder, serve, port): 32 | """Console script for playlistfromsong.""" 33 | if folder is None: 34 | folder = getcwd() 35 | if serve: 36 | run_server(folder, port) 37 | elif song != None: 38 | while True: 39 | song = getTopFromLastFM(song) 40 | if (version_info > (3, 0)): 41 | getinput = input 42 | else: 43 | getinput = raw_input 44 | c = getinput('Did you mean "' + 45 | song + '"? (y/n) ') 46 | if c is "y": 47 | click.echo( 48 | "Generating playlist for %d songs from '%s' \n(for generating more songs, use -n NUMBER)" % (num, song)) 49 | run(song.replace(" - ", " "), num, bearer=bearer, folder=folder) 50 | break 51 | song = getinput( 52 | "Please enter the artist and song (e.g. The Beatles Let It Be): ") 53 | else: 54 | click.echo("Specify a song with --song 'The Beatles Let It Be'") 55 | 56 | 57 | if __name__ == "__main__": 58 | main() 59 | -------------------------------------------------------------------------------- /playlistfromsong/server.py: -------------------------------------------------------------------------------- 1 | from distutils.spawn import find_executable 2 | from os.path import realpath, abspath, join, dirname 3 | from subprocess import call 4 | import fnmatch 5 | from os import chdir, walk, getcwd 6 | import re 7 | 8 | from flask import Flask, jsonify, send_from_directory, render_template, request 9 | from waitress import serve 10 | 11 | app = Flask(__name__) 12 | 13 | playlistfromsong = find_executable("playlistfromsong") 14 | folder_to_save_data = getcwd() 15 | port_for_server = "5000" 16 | SERVER_DEBUG = True 17 | 18 | 19 | 20 | def get_songs(): 21 | matches = [] 22 | num = 0 23 | for root, dirnames, filenames in walk(folder_to_save_data): 24 | for filename in fnmatch.filter(filenames, '*.mp3'): 25 | filename = join(root, filename).replace( 26 | folder_to_save_data, '') 27 | filename = filename.replace('.mp3', '') 28 | if filename[0] == "/": 29 | filename = filename[1:] 30 | songname = filename 31 | if songname[-12:-11] == "-": 32 | songname = songname[:-12] 33 | songname = re.sub(r"[\(\[].*?[\)\]]", "", songname).strip() 34 | num += 1 35 | matches.append({'file': filename, 'name': songname, 'id': num}) 36 | return matches 37 | 38 | 39 | @app.route('/download//') 40 | def download(n, song): 41 | cmd = "python3 -m pip install --upgrade playlistfromsong" 42 | call(cmd.split()) 43 | cmd = [playlistfromsong, "-s", song, "-n", n, "-f", folder_to_save_data] 44 | call(cmd) 45 | return jsonify({'success': True}) 46 | 47 | 48 | @app.route('/playlistfromsong') 49 | def playlistfromsong_route(): 50 | song = request.args.get('song') 51 | n = request.args.get('n') 52 | download(n, song) 53 | return play() 54 | 55 | 56 | @app.route('/') 57 | def play(): 58 | cwd = getcwd() 59 | chdir(dirname(realpath(__file__))) 60 | rendered_template = render_template('index.html', songs=get_songs()) 61 | chdir(cwd) 62 | return rendered_template 63 | 64 | 65 | @app.route('/assets/') 66 | def static_stuff(path): 67 | return send_from_directory('assets', path) 68 | 69 | 70 | @app.route('/song/') 71 | def send_song(path): 72 | if SERVER_DEBUG: 73 | print("Getting %s / %s" % (folder_to_save_data, path)) 74 | return send_from_directory(folder_to_save_data, path) 75 | 76 | 77 | def run_server(f, port): 78 | global folder_to_save_data, port_for_server 79 | if f != None: 80 | folder_to_save_data = abspath(f) 81 | if port != None: 82 | port_for_server = port 83 | print("\n\nStarting server, saving data to %s" % folder_to_save_data) 84 | serve(app, listen='*:' + port_for_server) 85 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean clean-test clean-pyc clean-build docs help clean-mp3 2 | .DEFAULT_GOAL := help 3 | define BROWSER_PYSCRIPT 4 | import os, webbrowser, sys 5 | try: 6 | from urllib import pathname2url 7 | except: 8 | from urllib.request import pathname2url 9 | 10 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) 11 | endef 12 | export BROWSER_PYSCRIPT 13 | 14 | define PRINT_HELP_PYSCRIPT 15 | import re, sys 16 | 17 | for line in sys.stdin: 18 | match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) 19 | if match: 20 | target, help = match.groups() 21 | print("%-20s %s" % (target, help)) 22 | endef 23 | export PRINT_HELP_PYSCRIPT 24 | BROWSER := python -c "$$BROWSER_PYSCRIPT" 25 | 26 | help: 27 | @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) 28 | 29 | clean: clean-mp3 clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts 30 | 31 | clean-mp3: 32 | find . -name '*.mp3' -exec rm -f {} + 33 | 34 | clean-build: ## remove build artifacts 35 | rm -fr build/ 36 | rm -fr dist/ 37 | rm -fr .eggs/ 38 | find . -name '*.egg-info' -exec rm -fr {} + 39 | find . -name '*.egg' -exec rm -f {} + 40 | 41 | clean-pyc: ## remove Python file artifacts 42 | find . -name '*.pyc' -exec rm -f {} + 43 | find . -name '*.pyo' -exec rm -f {} + 44 | find . -name '*~' -exec rm -f {} + 45 | find . -name '__pycache__' -exec rm -fr {} + 46 | 47 | clean-test: ## remove test and coverage artifacts 48 | rm -fr .tox/ 49 | rm -f .coverage 50 | rm -fr htmlcov/ 51 | 52 | lint: ## check style with flake8 53 | flake8 playlistfromsong tests 54 | 55 | test: ## run tests quickly with the default Python 56 | py.test 57 | 58 | 59 | test-all: ## run tests on every Python version with tox 60 | tox 61 | 62 | coverage: ## check code coverage quickly with the default Python 63 | coverage run --source playlistfromsong -m pytest 64 | coverage report -m 65 | coverage html 66 | $(BROWSER) htmlcov/index.html 67 | 68 | docs: ## generate Sphinx HTML documentation, including API docs 69 | rm -f docs/playlistfromsong.rst 70 | rm -f docs/modules.rst 71 | sphinx-apidoc -o docs/ playlistfromsong 72 | $(MAKE) -C docs clean 73 | $(MAKE) -C docs html 74 | $(BROWSER) docs/_build/html/index.html 75 | 76 | servedocs: docs ## compile the docs watching for changes 77 | watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . 78 | 79 | release: dist ## package and upload a release 80 | twine upload dist/* 81 | #python3 setup.py sdist upload 82 | #python3 setup.py bdist_wheel upload 83 | 84 | dist: clean ## builds source and wheel package 85 | python3 setup.py sdist 86 | python3 setup.py bdist_wheel 87 | ls -l dist 88 | 89 | install: clean ## install the package to the active Python's site-packages 90 | python3 setup.py install 91 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ============ 4 | Contributing 5 | ============ 6 | 7 | Contributions are welcome, and they are greatly appreciated! Every 8 | little bit helps, and credit will always be given. 9 | 10 | You can contribute in many ways: 11 | 12 | Types of Contributions 13 | ---------------------- 14 | 15 | Report Bugs 16 | ~~~~~~~~~~~ 17 | 18 | Report bugs at https://github.com/schollz/playlistfromsong/issues. 19 | 20 | If you are reporting a bug, please include: 21 | 22 | * Your operating system name and version. 23 | * Any details about your local setup that might be helpful in troubleshooting. 24 | * Detailed steps to reproduce the bug. 25 | 26 | Fix Bugs 27 | ~~~~~~~~ 28 | 29 | Look through the GitHub issues for bugs. Anything tagged with "bug" 30 | and "help wanted" is open to whoever wants to implement it. 31 | 32 | Implement Features 33 | ~~~~~~~~~~~~~~~~~~ 34 | 35 | Look through the GitHub issues for features. Anything tagged with "enhancement" 36 | and "help wanted" is open to whoever wants to implement it. 37 | 38 | Write Documentation 39 | ~~~~~~~~~~~~~~~~~~~ 40 | 41 | playlistfromsong could always use more documentation, whether as part of the 42 | official playlistfromsong docs, in docstrings, or even on the web in blog posts, 43 | articles, and such. 44 | 45 | Submit Feedback 46 | ~~~~~~~~~~~~~~~ 47 | 48 | The best way to send feedback is to file an issue at https://github.com/schollz/playlistfromsong/issues. 49 | 50 | If you are proposing a feature: 51 | 52 | * Explain in detail how it would work. 53 | * Keep the scope as narrow as possible, to make it easier to implement. 54 | * Remember that this is a volunteer-driven project, and that contributions 55 | are welcome :) 56 | 57 | Get Started! 58 | ------------ 59 | 60 | Ready to contribute? Here's how to set up `playlistfromsong` for local development. 61 | 62 | 1. Fork the `playlistfromsong` repo on GitHub. 63 | 2. Clone your fork locally:: 64 | 65 | $ git clone git@github.com:your_name_here/playlistfromsong.git 66 | 67 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 68 | 69 | $ mkvirtualenv playlistfromsong 70 | $ cd playlistfromsong/ 71 | $ python setup.py develop 72 | 73 | 4. Create a branch for local development:: 74 | 75 | $ git checkout -b name-of-your-bugfix-or-feature 76 | 77 | Now you can make your changes locally. 78 | 79 | 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: 80 | 81 | $ flake8 playlistfromsong tests 82 | $ python setup.py test or py.test 83 | $ tox 84 | 85 | To get flake8 and tox, just pip install them into your virtualenv. 86 | 87 | 6. Commit your changes and push your branch to GitHub:: 88 | 89 | $ git add . 90 | $ git commit -m "Your detailed description of your changes." 91 | $ git push origin name-of-your-bugfix-or-feature 92 | 93 | 7. Submit a pull request through the GitHub website. 94 | 95 | Pull Request Guidelines 96 | ----------------------- 97 | 98 | Before you submit a pull request, check that it meets these guidelines: 99 | 100 | 1. The pull request should include tests. 101 | 2. If the pull request adds functionality, the docs should be updated. Put 102 | your new functionality into a function with a docstring, and add the 103 | feature to the list in README.rst. 104 | 3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check 105 | https://travis-ci.org/schollz/playlistfromsong/pull_requests 106 | and make sure that the tests pass for all supported Python versions. 107 | 108 | Tips 109 | ---- 110 | 111 | To run a subset of tests:: 112 | 113 | $ py.test tests.test_playlistfromsong 114 | 115 | -------------------------------------------------------------------------------- /playlistfromsong/assets/js/index.js: -------------------------------------------------------------------------------- 1 | // html5media enables