Skip to content

Commit

Permalink
Merge pull request #6 from relaytheurgency/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
relaytheurgency authored Jul 13, 2016
2 parents 25882fa + 6964d0b commit f5a61fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ Archive.org has begun cataloging thousands of mixtapes from various collections
## caveats

I have included a bash script for those that don't want to register at archive.org. The caveat here is that this script uses a pretty sloppy `curl` and is not guaranteed to work for any forseeable future. To use the bash script just clone the repo and execute as you would any other script. It only requires mplayer if you're on linux. If you are on OS X you will need to `brew install coreutils`

## future work
* Command line options for things like continuous play of random tapes
* Create mixtape from individual songs pulled from other mixtapes by criteria (artist, year, genre)
* Better formatting
* Bundle for pip install
* Versions for python 2.x and 3.x that don't require hacky workarounds
8 changes: 4 additions & 4 deletions mixtape
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ else
fi

if [[ "$os" == "Darwin" ]]; then
if hash gsort 2>/dev/null; then
sortcommand="gsort"
if hash gshuf 2>/dev/null; then
shufcommand="gshuf"
else
echo "You need to install coreutils!"
exit 1
fi
elif [[ "$os" == "Linux" ]]; then
sortcommand="sort"
shufcommand="shuf"
fi

mixtape=`curl -s https://archive.org/advancedsearch.php\?q\=collection%3A%28hiphopmixtapes%29\&fl%5B%5D\=identifier\&sort%5B%5D\=\&sort%5B%5D\=\&sort%5B%5D\=\&rows\=100000\&page\=1\&output\=json\&callback\=callback\&save\=yes | grep identifier | cut -f2 -d ":" | cut -f2 -d "\"" | $sortcommand -R | head -n 1`
mixtape=`curl -s https://archive.org/advancedsearch.php\?q\=collection%3A%28hiphopmixtapes%29\&fl%5B%5D\=identifier\&sort%5B%5D\=\&sort%5B%5D\=\&sort%5B%5D\=\&rows\=100000\&page\=1\&output\=json\&callback\=callback\&save\=yes | grep identifier | cut -f2 -d ":" | cut -f2 -d "\"" | $shufcommand | head -n 1`

playlist="http://archive.org/download/${mixtape}/${mixtape}_vbr.m3u"

Expand Down
25 changes: 17 additions & 8 deletions mixtape.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/python
'''Play a random mixtape from archive.org hiphopmixtapes collection using python and mplayer'''
#!/usr/bin/env python
__author__ = "Brandon Jones"
__copyright__ = "Copyright 2016, Brandon Jones"
__license__ = "MIT License"
__version__ = "1.0.0"
__email__ = "[email protected]"

'''Play a random mixtape from archive.org hiphopmixtapes collection using python and mplayer'''
import internetarchive
from random import randint
import os
Expand All @@ -10,6 +15,7 @@
real_raw_input = vars(__builtins__).get('raw_input',input)

def random_or_artist():
'''Have the user choose whether to search for a specific artist or play a random tape'''

choice = real_raw_input("\
Would you like to: \n\
Expand All @@ -24,7 +30,7 @@ def random_or_artist():
elif choice == "q":
exit()
else:
print("You didn't choose either. Please make a valid choice!")
print("Please make a valid choice!")
random_or_artist()

def get_artist():
Expand All @@ -34,13 +40,14 @@ def get_artist():
return artist_name

def search_artist(artist_name):
'''Search archive.org for tapes from an artist'''
'''Search archive.org for tapes from an artist and return those tapes'''

artist_tapes = internetarchive.search_items('collection:hiphopmixtapes AND title:' + artist_name)
return artist_tapes

def random_mixtape():

'''Return a random mixtape item'''

mixtapes=[]

for i in internetarchive.search_items('collection:hiphopmixtapes'):
Expand All @@ -51,7 +58,8 @@ def random_mixtape():
return mixtape

def artist_mixtape(artist_search):

'''Returns an artist specific mixtape the user chooses from'''

mixtapes = []
for i in artist_search:
mixtapes.append(i['identifier'])
Expand All @@ -74,13 +82,14 @@ def artist_mixtape(artist_search):
mixtape = mixtapes[int(choice)]
return mixtape



def play_tape(mixtape):
'''Calls mplayer to play a mixtape'''

print("Now playing " + mixtape)
command = "mplayer -msgcolor -msglevel all=0:demux=5:statusline=5 -playlist http://archive.org/download/" + mixtape + "/" + mixtape + "_vbr.m3u 2>/dev/null"
os.system(command)
print("\n")

random_or_artist()

random_or_artist()

0 comments on commit f5a61fb

Please sign in to comment.