def url_get(url, params={}, headers={}, with_immunicity=True):
    import urllib2
    from contextlib import closing
    from streamajoker import plugin
    from streamajoker.common import USER_AGENT

    if params:
        import urllib
        url = "%s?%s" % (url, urllib.urlencode(params))

    req = urllib2.Request(url)
    req.add_header("User-Agent", USER_AGENT)
    for k, v in headers.items():
        req.add_header(k, v)

    if with_immunicity and plugin.get_setting("immunicity", bool):
        from streamajoker import immunicity
        proxy = immunicity.get_proxy_for(url)
        if proxy:
            from urlparse import urlsplit
            parts = urlsplit(url)
            req.set_proxy(proxy, parts[0])

    try:
        with closing(urllib2.urlopen(req)) as response:
            data = response.read()
            if response.headers.get("Content-Encoding", "") == "gzip":
                import zlib
                return zlib.decompressobj(16 + zlib.MAX_WBITS).decompress(data)
            return data
    except urllib2.HTTPError:
        return None
def track_event(*args, **kwargs):
    if not plugin.get_setting("ga_disable", bool) or kwargs.pop("force", False):
        try:
            from pyga.requests import Event
            tracker, session, visitor = get_ga()
            plugin.log.info("GA: Tracking event %s" % repr(args))
            tracker.track_event(Event(*args, **kwargs), session, visitor)
        except Exception, e:
            import traceback
            plugin.log.error("GA: Call failed.")
            plugin.log.error(traceback.format_exc())
def track_page(path, force=False):
    if not plugin.get_setting("ga_disable", bool) or force:
        try:
            from pyga.requests import Page
            tracker, session, visitor = get_ga()
            plugin.log.info("GA: Tracking %s" % path)
            tracker.track_pageview(Page(path), session, visitor)
        except Exception, e:
            import traceback
            plugin.log.error("GA: Call failed.")
            plugin.log.error(traceback.format_exc())
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route
from streamajoker.utils import ensure_fanart


# Temporary, will be fixed later by them
BASE_URL = "%s/" % plugin.get_setting("base_nyaa")
HEADERS = {
    "Referer": BASE_URL,
}


CATEGORIES = [
    ("Anime", "1_0", (
        ("English-translated Anime", "1_37"),
        ("Raw Anime", "1_11"),
        ("Non-English-translated Anime", "1_38"),
        ("Anime Music Video", "1_32"),
    )),
    ("Live Action (movies)", "5_0", (
        ("English-translated Live Action", "5_19"),
        ("Raw Live Action", "5_20"),
        ("Non-English-translated Live Action", "5_21"),
        ("Live Action Promotional Video", "5_22"),
    )),
]

SORT_DATE = 1
SORT_SEEDERS = 2
import sys
import stat
import subprocess
import xbmcaddon
from streamajoker.common import RESOURCES_PATH
from streamajoker.platform import PLATFORM
from streamajoker.utils import url_get
from streamajoker import plugin


ANDROID_XBMC_IDS = [
    "org.xbmc.xbmc",                        # Stock XBMC
    "tv.ouya.xbmc",                         # OUYA XBMC
    "com.semperpax.spmc",                   # SemPer Media Center (OUYA XBMC fork)
    "hk.minix.xbmc",                        # Minix XBMC
    plugin.get_setting("android_app_id"),   # Whatever the user sets
]


def ensure_exec_perms(file_):
    st = os.stat(file_)
    os.chmod(file_, st.st_mode | stat.S_IEXEC)
    return file_


def get_torrent2http_binary():
    binary = "torrent2http%s" % (PLATFORM["os"] == "windows" and ".exe" or "")

    platform = PLATFORM.copy()
    if platform["os"] == "darwin": # 64 bits anyway on Darwin
        platform["arch"] = "x64"
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route, shelf
from streamajoker.utils import ensure_fanart
from streamajoker.library import library_context


BASE_URL = "%s/" % plugin.get_setting("base_eztv")
HEADERS = {
    "Referer": BASE_URL,
}
SHOW_LIST_CACHE_TTL = 24 * 3600 # 24 hours caching


# Logo found on http://thesimurg.deviantart.com/art/Logo-for-EZTV-57874544
@scraper("EZTV - Series", "http://i.imgur.com/XcH6WOg.jpg")
@plugin.route("/eztv")
@ensure_fanart
@tracked
def eztv_index():
    import string
    for letter in ["0-9"] + list(string.ascii_uppercase):
        yield {
            "label": letter,
            "path": plugin.url_for("eztv_shows_by_letter", letter=letter),
            "is_playable": False,
        }


@plugin.route("/eztv/shows/<letter>")
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route
from streamajoker.utils import ensure_fanart


BASE_URL = "%s/" % plugin.get_setting("base_extratorrent")
HEADERS = {
    "Referer": BASE_URL,
}
# Cache TTLs
DEFAULT_TTL = 24 * 3600 # 24 hours

MOVIES_CATEGORIES = [
    ("Action", "419"),
    ("Adventure", "28"),
    ("Animation", "29"),
    ("Asian", "30"),
    ("Automotive/Cars", "32"),
    ("Biography", "628"),
    ("Bollywood", "558"),
    ("Comedy", "33"),
    ("Concerts", "34"),
    ("Crime", "600"),
    ("Documentary", "35"),
    ("Drama", "37"),
    ("Dubbed Movies", "742"),
    ("DVD / Film Extras", "36"),
    ("Family", "149"),
    ("Fantasy", "38"),
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route
from streamajoker.utils import ensure_fanart
from streamajoker.library import library_context


BASE_URL = "%s/" % plugin.get_setting("base_bitsnoop")
HEADERS = {
    "Referer": BASE_URL,
}
# Cache TTLs
DEFAULT_TTL = 24 * 3600 # 24 hours


@scraper("BitSnoop - Search Engine", "%s/i/logo.png" % BASE_URL)
@plugin.route("/bitsnoop")
@ensure_fanart
@tracked
def bitsnoop_index():
    plugin.redirect(plugin.url_for("bitsnoop_search"))


@plugin.route("/bitsnoop/browse/<root>/<page>")
@library_context
@ensure_fanart
@tracked
def bitsnoop_page(root, page):
    from urlparse import urljoin
    from streamajoker.scrapers import rss
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route
from streamajoker.utils import ensure_fanart
from streamajoker.library import library_context


# Temporary, will be fixed later by them
IMMUNICITY_TPB_URL = "http://thepiratebay.pe"
BASE_URL = "%s/" % (plugin.get_setting("immunicity", bool) and IMMUNICITY_TPB_URL or plugin.get_setting("base_tpb"))
HEADERS = {
    "Referer": BASE_URL,
}


CATEGORIES = [
    ("Movies", 201, [
        ("in HD", 207),
        ("in 3D", 209),
    ]),
    ("Music videos", 203),
    ("TV shows", 205, [
        ("in HD", 208),
    ]),
    ("Other", 299),
]

if plugin.get_setting("p**n", bool):
    CATEGORIES += [
        ("XXX", 500, [
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route
from streamajoker.utils import ensure_fanart
from streamajoker.library import library_context


BASE_URL = "%s/" % plugin.get_setting("base_yify")
HEADERS = {"Referer": BASE_URL}
YOUTUBE_ACTION = "plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=%s"
MOVIES_PER_PAGE = 20
GENRES = [
    "Action",
    "Adventure",
    "Animation",
    "Biography",
    "Comedy",
    "Crime",
    "Documentary",
    "Drama",
    "Family",
    "Fantasy",
    "Film-Noir",
    "Game-Show",
    "History",
    "Horror",
    "Music",
    "Musical",
    "Mystery",
    "News",
from streamajoker import plugin
from streamajoker.scrapers import scraper
from streamajoker.ga import tracked
from streamajoker.caching import cached_route
from streamajoker.utils import ensure_fanart
from streamajoker.library import library_context


BASE_URL = plugin.get_setting("base_btdigg")
HEADERS = {
    "Referer": BASE_URL,
}
SORT_RELEVANCE = 0
SORT_POPULARITY = 1
SORT_ADDTIME = 2
SORT_SIZE = 3
SORT_FILES = 4


@scraper("BTDigg - DHT Search Engine", "%s/logo.png" % BASE_URL)
@plugin.route("/btdigg")
@ensure_fanart
@tracked
def btdigg_index():
    plugin.redirect(plugin.url_for("btdigg_search"))


@plugin.route("/btdigg/search/<query>/<sort>/<page>")
@library_context
@ensure_fanart
@tracked