Skip to content

Instantly share code, notes, and snippets.

@cnbeining
Created November 3, 2015 06:34
Show Gist options
  • Save cnbeining/7af931f79fcb467c064e to your computer and use it in GitHub Desktop.
Save cnbeining/7af931f79fcb467c064e to your computer and use it in GitHub Desktop.
Replacement of getVideo of Acfun
import web
import requests
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
urls = (
'/getVideo', 'getVideo'
)
class getVideo:
def GET(self):
user_data = web.input()
try: #anti BS
id = int(user_data.id)
except ValueError, AttributeError:
return 'ERROR'
api_url = 'http://www.acfun.tv/video/getVideo.aspx?id={id}'.format(id = id)
try:
res = requests.get(api_url)
res = res.json()
except Exception as e:
return 'ERROR'
if not res['success']: #failed
return res.replace("u'", "'").replace("'", '"').replace('True', 'true') #throw the shit back
if str(res['sourceType']) == 'zhuzhan': #compressed shit
del(res['videoList']) #strip this
res['sourceType'] = 'letv' #force change back
return str(res).replace("u'", "'").replace("'", '"').replace('True', 'true')
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment