Skip to content

Instantly share code, notes, and snippets.

@gfjardim
Last active November 13, 2015 02:14
Show Gist options
  • Save gfjardim/a56dc62e3defb3152418 to your computer and use it in GitHub Desktop.
Save gfjardim/a56dc62e3defb3152418 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import re, sys, os, json, datetime, urllib.request, unicodedata, pprint
from pyriscope.__main__ import main
from bs4 import BeautifulSoup
def unique(items):
found = set([])
keep = []
for item in items:
if item not in found:
found.add(item)
keep.append(item)
return keep
def makeSafeFilename(filename):
keepcharacters = (' ','.','_','-','(',')')
filename = unicodedata.normalize('NFKD', filename).encode('ascii', 'ignore').decode()
return "".join(c for c in filename if c.isalnum() or c in keepcharacters).rstrip()
Url = sys.argv[1]
for user in sys.argv[1:]:
Url = "https://www.periscope.tv/" + user
with urllib.request.urlopen(Url) as response:
Response = response.read()
soup = BeautifulSoup( Response ,"html.parser")
json_data = json.loads( soup.find("meta", id="user-broadcasts")['content'] )
for broadcast in json_data['broadcasts']:
state = broadcast['state']
id = broadcast['id']
name = broadcast['user_display_name']
title = broadcast['status']
start = datetime.datetime.strptime(broadcast['start'][:19],'%Y-%m-%dT%H:%M:%S' )
time = start.strftime('%d-%m-%Y %Hh%Mm%S')
file = makeSafeFilename( "%s - %s (%s).ts" % (name, title, time) )
query = "%s/%s" % (Url,id)
cmd = "%s '%s' --name '%s'" % ("/usr/local/bin/pyriscope", query, file)
if os.path.isfile(file):
print("Already downloaded stream '%s' from user '%s'" %(id, name) )
else:
os.system(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment