Skip to content

Instantly share code, notes, and snippets.

@saga
Created June 15, 2013 01:12
Show Gist options
  • Save saga/5786340 to your computer and use it in GitHub Desktop.
Save saga/5786340 to your computer and use it in GitHub Desktop.
oo-uu.rhcloud.com
#!/usr/bin/env python
#*_* coding=utf8 *_*
from flask import Flask
#app = Flask(__name__)
import simplejson
import logging
import random
import re
import datetime
import string
import time
import sys
import urllib
import xmlrpclib
import base64
import os
import json
from flask import Flask, Request, Response
from werkzeug.routing import BaseConverter
import urllib2
from urllib import quote, unquote, urlencode
import argparse
from os import path
from urlparse import parse_qs
from urllib2 import URLError
import StringIO
class VideoInfo(object):
def __init__(self, video_url):
request_url = 'http://www.youtube.com/get_video_info?video_id='
if 'http://www.youtube.com/watch?v' in parse_qs(video_url).keys():
request_url += parse_qs(video_url)['http://www.youtube.com/watch?v'][0]
elif 'v' in parse_qs(video_url).keys():
request_url += parse_qs(video_url)['v'][0]
request = urllib2.Request(request_url)
try:
self.video_info = parse_qs(urllib2.urlopen(request).read())
except URLError :
pass
def video_file_urls(videoinfo):
url_encoded_fmt_stream_map = videoinfo.video_info['url_encoded_fmt_stream_map'][0].split(',')
entrys = [parse_qs(entry) for entry in url_encoded_fmt_stream_map]
url_maps = [dict(url=entry['url'][0]+'&signature='+entry['sig'][0], type=entry['type']) for entry in entrys]
return url_maps
def GetYoutubeUrlMp4_1(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/mp4':
url = entry['url']
break
return url
def GetYoutubeUrlMp4_2(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/mp4':
url = entry['url']
index = index + 1
if index >= 2:
break
return url
def GetYoutubeUrlMp4_3(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/mp4':
url = entry['url']
index = index + 1
if index >= 3:
break
return url
def GetYoutubeUrlMp4_4(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/mp4':
url = entry['url']
index = index + 1
if index >= 4:
break
return url
def GetYoutubeUrlMp4_Last(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/mp4':
url = entry['url']
return url
def GetYoutubeUrl2(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/webm':
url = entry['url']
break
return url
def GetYoutubeUrl2_2(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/webm':
url = entry['url']
index = index + 1
if index >= 2:
break
return url
def GetYoutubeUrl2_3(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/webm':
url = entry['url']
index = index + 1
if index >= 3:
break
return url
def GetYoutubeUrl2_4(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
index = 0
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/webm':
url = entry['url']
index = index + 1
if index >= 4:
break
return url
def GetYoutubeUrl3(url_str):
video_info = VideoInfo(url_str)
video_url_map = video_file_urls(video_info)
url = ''
for entry in video_url_map:
entry_type = entry['type'][0]
entry_type = entry_type.split(';')[0]
if entry_type.lower() == 'video/x-flv':
url = entry['url']
break
return url
application = app = Flask(__name__)
@app.errorhandler(404)
def not_found(error):
resp = make_response(render_template('error.html'), 404)
resp.headers['X-Something'] = 'A value'
return resp
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
app.url_map.converters['regex'] = RegexConverter
@app.route('/webm1/<regex(".*"):filename>')
def FetchWebm1(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrl2("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/webm")
@app.route('/webm2/<regex(".*"):filename>')
def FetchWebm2(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrl2_2("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/webm")
@app.route('/webm3/<regex(".*"):filename>')
def FetchWebm3(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrl2_3("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/webm")
@app.route('/webm4/<regex(".*"):filename>')
def FetchWebm4(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrl2_4("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/webm")
@app.route('/m4v/<regex(".*"):filename>')
def FetchM4V(filename):
response1 = urllib2.urlopen(filename)
content = response1.read()
return Response(content, content_type="video/m4v")
@app.route('/mp4/<regex(".*"):filename>')
def FetchMP4(filename):
response1 = urllib2.urlopen(filename)
content = response1.read()
return Response(content, content_type="video/mp4")
@app.route('/mp3/<regex(".*"):filename>')
def FetchMP3(filename):
response1 = urllib2.urlopen(filename)
content = response1.read()
return Response(content, content_type="audio/mp3")
@app.route('/htm/<regex(".*"):filename>')
def FetchHTM(filename):
response1 = urllib2.urlopen(filename)
content = response1.read()
return Response(content, content_type="text/html")
@app.route('/jpg/<regex(".*"):filename>')
def FetchJPGMain(filename):
response1 = urllib2.urlopen(filename)
content = response1.read()
return Response(content, content_type="image/jpeg")
@app.route('/img/<regex(".*"):filename>')
def FetchImageImg(filename):
urlnew = base64.urlsafe_b64decode(filename)
response1 = urllib2.urlopen(urlnew)
content = response1.read()
return Response(content, content_type="image/jpeg")
@app.route('/jpg1/<regex(".*"):filename>')
def FetchJPG1(filename):
import StringIO
output = StringIO.StringIO()
content1 = GetYoutubeUrlMp4_1("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/mp4")
@app.route('/jpg2/<regex(".*"):filename>')
def FetchJPG2(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrlMp4_2("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/mp4")
@app.route('/jpg3/<regex(".*"):filename>')
def FetchJPG3(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrlMp4_3("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/mp4")
@app.route('/jpg4/<regex(".*"):filename>')
def FetchJPG4(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrlMp4_4("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/mp4")
@app.route('/jpg5/<regex(".*"):filename>')
def FetchJPG5(filename):
output = StringIO.StringIO()
content1 = GetYoutubeUrlMp4_Last("http://www.youtube.com/watch?v=" + filename)
response1 = urllib2.urlopen(content1, timeout=80)
buff_size = 96000000
while True:
buffer = response1.read(buff_size)
if not buffer:
break
output.write(buffer)
contents = output.getvalue()
return Response(contents, content_type="video/mp4")
@app.route('/pod/<regex(".*"):filename>')
def Podfeed(filename):
response1 = urllib2.urlopen(filename)
content = response1.read()
content = content.replace("enclosure url=\"", "enclosure url=\"http://oo-uu.rhcloud.com/mp3/")
return Response(content, content_type="text/xml")
@app.route('/nbcnightlynews')
def RawFetchMSNBCNightly():
thisUrl = "http://podcastfeeds.nbcnews.com/audio/podcast/MSNBC-Nightly.xml"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
content = content.replace("enclosure url=\"", "enclosure url=\"http://oo-uu.rhcloud.com/mp3/")
except:
pass
return Response(content, content_type="text/xml")
@app.route('/googletechtalks')
def RawFetchFeedGoogleTechTalks():
thisUrl = "http://gdata.youtube.com/feeds/api/users/GoogleTechTalks/uploads"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/Confreaks')
def RawFetchFeedConfreaks():
thisUrl = "http://gdata.youtube.com/feeds/api/users/Confreaks/uploads"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/MarakanaTechTV')
def RawFetchFeedMarakanaTechTV():
thisUrl = "http://gdata.youtube.com/feeds/api/users/MarakanaTechTV/uploads"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/userfeed/<regex(".*"):filename>')
def FetchFeedUserYoutube(filename):
thisUrl = "http://gdata.youtube.com/feeds/api/users/" + filename +"/uploads"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/playlist/<regex(".*"):filename>')
def FetchFeedPlaylist(filename):
thisUrl = "http://gdata.youtube.com/feeds/api/playlists/" + filename
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/playlists/<regex(".*"):filename>')
def FetchFeedAllPlaylists(filename):
thisUrl = "http://gdata.youtube.com/feeds/api/users/" + filename + "/playlists"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/youtube')
def RawFetchYOUTUBEWEB():
thisUrl = "http://www.youtube.com"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/html")
@app.route('/mostrecentvideo')
def RawFetchMOSTRECENTVIDEO():
thisUrl = "http://gdata.youtube.com/feeds/api/standardfeeds/most_recent"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
except:
pass
return Response(content, content_type="text/xml")
@app.route('/jjj/<regex(".*"):filename>')
def FetchImageVenueSrc(filename):
content = u""
try:
url = "http://subimg.net/" + filename
result = urllib2.urlopen(url)
content = result.read()
return Response(content, content_type="image/jpeg")
except:
pass
return ""
@app.route('/nbctoday')
def RawFetchMSNBCToday():
thisUrl = "http://podcastfeeds.nbcnews.com/audio/podcast/MSNBC-TDY-PODCAST-MP3.xml"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
content = content.replace("enclosure url=\"", "enclosure url=\"http://oo-uu.rhcloud.com/mp3/")
except:
pass
return Response(content, content_type="text/xml")
@app.route('/businessenglishpod')
def RawFetchBEP():
thisUrl = "http://feeds2.feedburner.com/BusinessEnglishPod"
content = u""
try:
result = urllib2.urlopen(thisUrl)
content = result.read()
content = content.replace("enclosure url=\"", "enclosure url=\"http://oo-uu.rhcloud.com/mp3/")
except:
pass
return Response(content, content_type="text/xml")
@app.route('/wallbasecc')
def Fetchwallbase():
output = StringIO.StringIO()
urllib2.urlopen('http://wallbase.cc/user/logout')
form_fields = {
"usrname": "",
"pass": "",
"nopass_email": "Type+in+your+e-mail+and+press+enter",
"nopass": "0"
}
form_data = urllib.urlencode(form_fields)
resp = urllib2.urlopen('http://wallbase.cc/user/login', form_data)
findStr2 = "'+B('"
findStr3 = "')"
baseurl = "http://wallbase.cc/toplist/0/213/eqeq/0x0/0.000/011/60/3d/"
result = resp.read()
imagesContent = result.content
while True:
posThumb1 = imagesContent.find('id="thumb', posThumb1)
if posThumb1 < 0:
break
posThumb2 = imagesContent.find('"', posThumb1 + 8)
wallnum = imagesContent[posThumb1 + 9 : posThumb2]
posThumb1 = posThumb2 + 1
if wallnum.isdigit() == False:
continue
url2 = "http://wallbase.cc/wallpaper/" + wallnum
self.response.out.write(url2 + " ")
result33 = urllib2.urlopen(url2).read()
content33 = result33.content
position2 = content33.find(findStr2, 0)
position3 = content33.find(findStr3, position2 + len(findStr2) + 1)
big = content33[position2 + len(findStr2) : position3]
big = funcB(big)
output.write(big + "<br />")
contents = output.getvalue()
return Response(contents, content_type="text/html")
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment