Created
August 25, 2014 19:07
-
-
Save lyuboraykov/eeb5134fcf53d730fdcf to your computer and use it in GitHub Desktop.
Download songs from youtube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import pafy | |
import requests | |
from multiprocessing import Pool | |
import pyglet | |
import os | |
import sys | |
def get_url_from_name(name): | |
words = name.split() | |
query = '+'.join(words) | |
url = 'https://www.youtube.com/results?search_query={}'.format(query) | |
response_html = requests.get(url).content | |
index = response_html.find('href="/watch?v=') | |
print('index: {}'.format(index)) | |
watch_url = response_html[index:index+26] | |
print('watch_url: {}'.format(watch_url)) | |
watch_url = watch_url.replace('href="', '') | |
watch_url = 'http://youtube.com' + watch_url | |
return watch_url | |
if __name__ == '__main__': | |
playlist_file = sys.argv[1] | |
lines = [] | |
with open('citroen.playlist', 'r') as reader: | |
lines = reader.readlines() | |
for line in lines: | |
url = get_url_from_name(line) | |
video = pafy.new(url) | |
bestaudio = video.getbestaudio() | |
bestaudio.download() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment