Code Monkey home page Code Monkey logo

youstatanalyzer's Introduction

YOUStatAnalyzer

YOUStatAnalyzer is a tool written in Python able to capture the popularity metrics of YouTube's videos. Since in June 2013 YouTube removed the API that allowed to retrieve the statistics available below each video, we needed to find a new way of obtain those kind of data. The result is this piece of software that allows to automatically and in a fast way to download YouTube's videos statistics with the final purpose of creating a dataset for analysis. In order to extract these data from YouTube, the tool obtains a session token that is later used for making the request to YouTube's servers. Once the data have been downloaded thay are parsed in order to save them in a known format inside a MongoDB Server.

Dependencies and Libraries

The Libraries we are using within YOUStatAnalyzer are listed below:

  • urllib2
  • cookielib
  • parse and parseString from xml.dom.minidom
  • re
  • BeautifulSoup from bs4
  • MongoClient from pymongo
  • random
  • linecache

In order to get YOUStatAnalyzer to work you need to have those libraries installed in your system.

Usage

The software is very easy to use, just need to configure it and run.

To run it use the command: python youtube_script.py config.xml where config.xml is of course the configuration file. The tool will automatically read it and react accordingly.

The Database

As database system we used MongoDB through the pymongo library. If you are not confortable with it you can just replace the only functions that interacts with the database: insertEntry() in functions.py:

def insertEntry(video):
	try:
		client = MongoClient(getServerIp(), getServerPort())
		db = client[getServerDB()][getServerCollection()]
		db.insert(video)
	except pymongo.errors.DuplicateKeyError:
		print 'Insert Error: Duplicate'
		pass

This function takes as argument the dictionary containing all the information about the video that needs to be inserted into the database. In particular, this function creates an Instance of MongoClient with the IP and Port of the Server. Then Creates an instance of the database with Database Name and Collection Name and in the end inserts the dictionary. We surrounded it with try...catch to avoid duplicates: if a duplicated _id occurs, the script throws a DuplicateKeyError exception.

Tha database contains 1006469 videos for 31488523593bytes.

The Data Structure

youstatanalyzer's People

Contributors

mattiazeni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

youstatanalyzer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.