Created
April 27, 2015 16:12
-
-
Save dvv/d17bc8eb588c4d25fbf6 to your computer and use it in GitHub Desktop.
1torrenttv playlist rip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import sys | |
import urllib | |
from HTMLParser import HTMLParser | |
import json | |
import time | |
import random | |
cats = dict() | |
cids = set() | |
class OneTorrentTvParser(HTMLParser): | |
collecting = True | |
cat = False | |
playlist = [] | |
def handle_starttag(self, tag, attrs): | |
if tag == "div": | |
id = [y for (x, y) in attrs if x == "id"] | |
if len(id) > 0: | |
id = id[0] | |
if id.startswith("tcap_"): | |
self.cat = "tcon_" + id[5:] | |
elif id.startswith("tcon_"): | |
self.collecting = False | |
self.cat = id | |
if tag == "a": | |
href = [y for (x, y) in attrs if x == "href"] | |
if len(href) > 0: | |
href = href[0] | |
if href.startswith("/ru/channelonline.php?channel="): | |
cid = href[30:] | |
if not cid in cids: | |
cids.add(cid) | |
#print cid, cats.get(self.cat) | |
#return | |
#time.sleep(random.uniform(0.1, 1.5)) | |
x = json.loads(urllib.urlopen("http://1torrent.tv/sc_current_stream.php?cid=" + cid).read()) | |
try: | |
print '#EXTINF:-1 group-title="{2}" tvg-logo="http://1torrent.tv/uploads/{1}",{0}'.format( | |
x.get("name").encode("utf8"), | |
x.get("logo").encode("utf8"), | |
cats.get(self.cat) | |
) | |
except Exception as e: | |
print e, x | |
raise | |
print "{0}".format(x.get("stream_url")) | |
#sys.exit(0) | |
def handle_data(self, data): | |
if self.collecting and self.cat: | |
cats.update({self.cat: data.strip()}) | |
self.cat = False | |
parser = OneTorrentTvParser() | |
print "#EXTM3U,tvg-shift=3" | |
parser.feed(urllib.urlopen("http://1torrent.tv/ru/channels.php").read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment