Пример #1
0
def formattedSearch(query):
	if query == "":
		return "<p>You didn't enter a search query. Please go back to the original window and enter a search query.</p>"
	song_request = TinySongRequest(api_key='164b76e7347518c2e737ca2ebc2b7830')
	songs = song_request.search(query)
	html_list = "<ul>\n"
	for song in songs:
		html_list += "<li>\n" + song.song_name + "\n<ul>\n<li>Artist: " + song.artist_name + "</li>\n<li>Song ID: " + str(song.song_id) + "</li>\n</ul>\n</li>\n"
	html_list += "</ul>"
	return html_list
Пример #2
0
def my_form_post():
    os.system("rm files.txt")
    os.system("rm *.mp4")

    youtube_url = request.form["text"]

    # os.system("cd #{RAILS_ROOT}/tmp/")

    p = subprocess.Popen("youtube-dl -e --get-title " + youtube_url, stdout=subprocess.PIPE, shell=True)
    (youtube_title, err) = p.communicate()

    os.system("youtube-dl " + youtube_url)

    os.system("ls > files.txt")

    f = open("files.txt", "r")

    while True:
        filename = f.readline()

        if ".mp4" in filename:
            break

        if filename == "":
            break

    f.close()

    # load metadata using pytinysong
    song = TinySongRequest(api_key=os.environ["TINYSONG_APIKEY"])
    results = song.request_metadata(youtube_title)

    artist_name = results.artist_name
    song_name = results.song_name
    album_name = results.album_name

    # do i need this?
    filename = filename.replace(" ", "\ ")
    filename = filename.replace("\n", "")
    filename_parsed = filename.replace("\ ", "_")
    filename_parsed = filename_parsed.replace("\n", "")

    os.system("mv " + filename + " " + filename_parsed)

    mp3_file = filename_parsed[0 : len(filename_parsed) - 4] + ".mp3"

    # build string
    ffmpeg_path = "/app/.heroku/vendor/ffmpeg/bin/"

    ffmpeg = ffmpeg_path + "ffmpeg -y -i " + filename_parsed  # issue: i want a prettier .mp3 file
    ffmpeg = ffmpeg + " -metadata title=" + '"' + song_name + '"' + " "
    ffmpeg = ffmpeg + " -metadata artist=" + '"' + artist_name + '"' + " "
    ffmpeg = ffmpeg + " -metadata album=" + '"' + album_name + '"' + " " + mp3_file

    os.system(ffmpeg)

    # p = subprocess.Popen("ls -l", stdout=subprocess.PIPE, shell=True)
    # (final_download, err) = p.communicate()

    # upload to aws s3
    AWS_ACCESS_KEY_ID = os.environ["S3_KEY"]
    AWS_SECRET_ACCESS_KEY = os.environ["S3_SECRET"]

    conn = boto.connect_s3()

    bucket = conn.get_bucket("downloader-proj-assets")

    # testfile = "Battles_-_Tras_3-Blfi00qCQs4.mp3" #mp3_file
    testfile = mp3_file

    # return final_download

    import sys

    def percent_cb(complete, total):  # might not need this
        sys.stdout.write(".")
        sys.stdout.flush()

    from boto.s3.key import Key

    k = Key(bucket)
    k.key = testfile
    k.set_contents_from_filename(testfile, cb=percent_cb, num_cb=10)  # or this

    k.set_acl("public-read")

    final_download = "https://s3.amazonaws.com/downloader-proj-assets/" + k.key
    return render_template("my_form_2.html", final_download=final_download)  # final_download = amazon link
Пример #3
0
def test_request_search():
    song = TinySongRequest(api_key=KEY)
    results = song.search('Overseer')
    ok_(len(results) > 0)
Пример #4
0
def test_bad_api_key():
    song = TinySongRequest(api_key='bad_api_key_test')
    results = song.search('Wanda Sa')
Пример #5
0
def test_request_metadata():
    song = TinySongRequest(api_key=KEY)
    result = song.request_metadata('Kylie - Better Than Today (Bellatrax Remix)')
    ok_(len(result.url) > 0)
Пример #6
0
def test_request_link():
    song = TinySongRequest(api_key=KEY)
    results = song.request_link('Beethoven - Moonlight Sonata')
    ok_(len(results) > 0)
Пример #7
0
def test_request_link():
    song = TinySongRequest(api_key=KEY)
    data = song.request_link('Zero 7 - Destiny')
    ok_(data.startswith("http://tinysong.com"))
Пример #8
0
def test_request_metadata_old_property():
    song = TinySongRequest(api_key=KEY)
    data = song.request_metadata('Zero 7 - Destiny')
    ok_(data.ArtistID)
Пример #9
0
def test_request_metadata():
    song = TinySongRequest(api_key=KEY)
    data = song.request_metadata('Overseer - Supermoves')
    ok_("Overseer" in data.artist_name or "Supermoves" in data.song_name)