RedTube json Python


In [0]:


In [0]:


In [1]:
import requests
import json
import random

Requests and json are the two main modules used for this. Random can also be handy


In [2]:
getPrn = requests.get('http://api.redtube.com/?output=json&data=redtube.Videos.searchVideos&page=1')

Simple requests command to get the json object. This could be any json object - not just RedTube


In [25]:
loaPrn = json.loads(getPrn.text)
#print loaUrl

Convert it into readable text that you can work with


In [26]:
naoPrn = loaPrn[u'videos'][0]
print naoPrn


{u'video': {u'rating': u'0.00', u'thumb': u'http://img.ec.cdn.redtubefiles.com/_thumbs/0000842/0842918/0842918_015m.jpg', u'ratings': u'0', u'url': u'http://www.redtube.com/842918', u'views': 6, u'video_id': u'842918', u'publish_date': u'2014-08-06 01:36:03', u'duration': u'5:51', u'title': u'Older boner nails young ass', u'tags': [{u'tag_name': u'Big Ass'}, {u'tag_name': u'Couple'}], u'default_thumb': u'http://img.ec.cdn.redtubefiles.com/_thumbs/0000842/0842918/0842918_015m.jpg'}}

Compress down - look at first element of json object. You could cycle through older elements by increasing the int


In [27]:
ngePrn = naoPrn[u'video']
print ngePrn


{u'rating': u'0.00', u'thumb': u'http://img.ec.cdn.redtubefiles.com/_thumbs/0000842/0842918/0842918_015m.jpg', u'ratings': u'0', u'url': u'http://www.redtube.com/842918', u'views': 6, u'video_id': u'842918', u'publish_date': u'2014-08-06 01:36:03', u'duration': u'5:51', u'title': u'Older boner nails young ass', u'tags': [{u'tag_name': u'Big Ass'}, {u'tag_name': u'Couple'}], u'default_thumb': u'http://img.ec.cdn.redtubefiles.com/_thumbs/0000842/0842918/0842918_015m.jpg'}

Compress down again - this time video. It's always a bit of a trial and error to figure out navagating json objects, IPython is perfect for this.

Individual Data!

This could be imporoved by turning the following unicode into a list and get the program to cycle though - saving off each element. Maybe save to a list?


In [28]:
ratPrn = ngePrn[u'rating']

In [31]:
thumPrn = ngePrn[u'thumb']

In [32]:
print thumPrn


http://img.ec.cdn.redtubefiles.com/_thumbs/0000842/0842918/0842918_015m.jpg

In [33]:
ratPrn = ngePrn[u'ratings']
print ratPrn


0

In [34]:
urlPrn = ngePrn[u'url']
print urlPrn


http://www.redtube.com/842918

In [35]:
viwPrn = ngePrn[u'views']
print viwPrn


6

In [36]:
idPrn = ngePrn[u'video_id']
print idPrn


842918

In [37]:
pdaPrn = ngePrn[u'publish_date']
print pdaPrn


2014-08-06 01:36:03

In [38]:
timPrn = ngePrn[u'duration']
print timPrn


5:51

In [39]:
titPrn = ngePrn[u'title']
print titPrn


Older boner nails young ass

In [40]:
tagPrn = ngePrn[u'tags']
print tagPrn


[{u'tag_name': u'Big Ass'}, {u'tag_name': u'Couple'}]

In [41]:
derbPrn = (tagPrn, 'tag_name')
print derbPrn


([{u'tag_name': u'Big Ass'}, {u'tag_name': u'Couple'}], 'tag_name')

In [42]:
thNum = 0
taTrn = tagPrn[thNum]
print taTrn
thNum + 1


{u'tag_name': u'Big Ass'}
Out[42]:
1

TODO: Cycle the list and print all tags


In [44]:
naTrn = taTrn['tag_name']
print naTrn


Big Ass

In [44]:

Saving Data


In [48]:
import dominate

In [45]:
savPrn = open('savPrn','w')
savPrn.write('<h3 style="text-align: center;"><a href="' + urlPrn + '">')
savPrn.write(titPrn + '</a></h3>')
savPrn.write('<p style="text-align: right;">' + pdaPrn)
savPrn.write('</a></h3><img class="aligncenter" alt="null" src="' + thumPrn)
savPrn.write('" />')
savPrn.close()

In [24]:
opPrn = open('savPrn','r')
for op in opPrn:
    print op


<h3 style="text-align: center;"><a href="http://www.redtube.com/842918">Older boner nails young ass</a></h3><p style="text-align: right;">2014-08-06 01:36:03</a></h3><img class="aligncenter" alt="null" src="http://img.ec.cdn.redtubefiles.com/_thumbs/0000842/0842918/0842918_015m.jpg" />

In [24]:


In [24]:


In [ ]: