Skip to content

Instantly share code, notes, and snippets.

@uahim
Last active April 10, 2020 17:26
Show Gist options
  • Save uahim/c660992d1934c2dd0b53fdcbc7ef9731 to your computer and use it in GitHub Desktop.
Save uahim/c660992d1934c2dd0b53fdcbc7ef9731 to your computer and use it in GitHub Desktop.
import json
import os
import re
import shutil
import string
import sys
import tempfile
import urllib.request
import win32clipboard
from bs4 import BeautifulSoup
# vidurl = os.popen("getclip").read()
win32clipboard.OpenClipboard()
vidurl = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
pattern = "www.spiegel.de"
if not re.search(pattern, vidurl):
exit()
response = urllib.request.urlopen(vidurl)
html = response.read()
soup = BeautifulSoup(html, "lxml")
feedtag = soup.find("div", {"data-component":"Defer"})['data-settings']
mid = "/v2/media/"
distros_dict = json.loads(feedtag)
response = urllib.request.urlopen(distros_dict['apiUrl']+mid+distros_dict['mediaId'])
html = response.read()
stream = json.loads(html)
vlc = stream['playlist'][0]['sources'][0]['file']
with urllib.request.urlopen(vlc) as response:
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
shutil.copyfileobj(response, tmp_file)
file = open(tmp_file.name, "r")
for line in file:
if re.search("1280x720", line):
stream = next(file, '').strip()
os.system('"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" '+stream)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment