Skip to content

Instantly share code, notes, and snippets.

@Felhamed
Last active August 28, 2017 08:09
Show Gist options
  • Select an option

  • Save Felhamed/ac12834915e3599dad8577d7b229394e to your computer and use it in GitHub Desktop.

Select an option

Save Felhamed/ac12834915e3599dad8577d7b229394e to your computer and use it in GitHub Desktop.
Generate mpv playlist from url directory
#!/usr/bin/python
import sys
import requests
import subprocess
from bs4 import BeautifulSoup
url = sys.argv[1]
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
preurl='http://vid.archive'
file = open("playlist.txt", "w")
for a in soup.find_all('a', href=True):
file.write(a['href']+'\n')
file.close()
with open('playlist.txt', 'r') as fin:
data = fin.read().splitlines(True)
data = [preurl + s for s in data]
with open('playlist.txt', 'w') as fout:
fout.writelines(data[1:])
subprocess.run(["mpv", "--playlist=playlist.txt"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment