|
| 1 | +import sys |
| 2 | +import urllib |
| 3 | +import pycurl |
| 4 | +from io import StringIO,BytesIO |
| 5 | +import re |
| 6 | +import random |
| 7 | +import subprocess |
| 8 | +from subprocess import check_output |
| 9 | +from bs4 import BeautifulSoup |
| 10 | +import os |
| 11 | +import os.path |
| 12 | +from subprocess import check_output |
| 13 | +import shutil |
| 14 | +import json |
| 15 | +from player_functions import ccurl,naturallysorted |
| 16 | + |
| 17 | + |
| 18 | +class Shoutcast(): |
| 19 | + def __init__(self,tmp): |
| 20 | + self.hdr = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:45.0) Gecko/20100101 Firefox/45.0' |
| 21 | + self.tmp_dir = tmp |
| 22 | + def getOptions(self): |
| 23 | + criteria = ['History','Genre'] |
| 24 | + return criteria |
| 25 | + |
| 26 | + def getFinalUrl(self,name,epn,mir,quality): |
| 27 | + return epn |
| 28 | + |
| 29 | + def process_page(self,content): |
| 30 | + content = re.sub(r'\\',"-",content) |
| 31 | + #print(content) |
| 32 | + #f = open('/tmp/tmp.txt','w') |
| 33 | + #f.write(content) |
| 34 | + #f.close() |
| 35 | + try: |
| 36 | + l = json.loads(content) |
| 37 | + except: |
| 38 | + o = re.findall('{[^}]*}',content) |
| 39 | + l = [] |
| 40 | + for i in o: |
| 41 | + print(i) |
| 42 | + try: |
| 43 | + j = json.loads(i) |
| 44 | + print(j['ID'],j['Name']) |
| 45 | + l.append(j) |
| 46 | + except: |
| 47 | + pass |
| 48 | + print('----------------------error---------------') |
| 49 | + s = [] |
| 50 | + for i in l: |
| 51 | + try: |
| 52 | + #print(i['ID'],i['Name'],i['Bitrate'],i['Listeners']) |
| 53 | + s.append(i['Name'].replace('/','-')+' id='+str(i['ID'])+'\nBitrate='+str(i['Bitrate'])+'\nListeners='+str(i['Listeners'])+'\n') |
| 54 | + except: |
| 55 | + pass |
| 56 | + return s |
| 57 | + |
| 58 | + def search(self,name): |
| 59 | + strname = str(name) |
| 60 | + print(strname) |
| 61 | + if name.lower() == 'tv': |
| 62 | + m = self.getCompleteList(name.upper(),1) |
| 63 | + else: |
| 64 | + url = "https://www.shoutcast.com/Home/BrowseByGenre" |
| 65 | + #content = ccurl(url,name,1) |
| 66 | + post = "genrename="+name |
| 67 | + content = ccurl(url+'#'+'-d'+'#'+post) |
| 68 | + m = self.process_page(content) |
| 69 | + return m |
| 70 | + |
| 71 | + def getCompleteList(self,opt,genre_num): |
| 72 | + if opt == 'Genre' and genre_num == 0: |
| 73 | + url = "http://www.shoutcast.com/" |
| 74 | + #content = ccurl(url,"",1) |
| 75 | + content = ccurl(url) |
| 76 | + m = re.findall('Genre[^"]name[^"]*',content) |
| 77 | + #print m |
| 78 | + j = 0 |
| 79 | + for i in m: |
| 80 | + m[j] = re.sub('Genre[^"]name=','',i) |
| 81 | + m[j] = re.sub("[+]|%20",' ',m[j]) |
| 82 | + j = j+1 |
| 83 | + m.sort() |
| 84 | + print(m) |
| 85 | + #n = ["History","Genre","TV"] |
| 86 | + n = ["History","Genre"] |
| 87 | + m = n + m |
| 88 | + elif opt == 'History': |
| 89 | + a =0 |
| 90 | + elif opt == 'TV': |
| 91 | + name = [] |
| 92 | + track = [] |
| 93 | + aformat = [] |
| 94 | + listeners = [] |
| 95 | + bitrate = [] |
| 96 | + idr = [] |
| 97 | + url = "http://thugie.nl/streams.php" |
| 98 | + #content = ccurl(url,"",4) |
| 99 | + content = ccurl(url) |
| 100 | + soup = BeautifulSoup(content,'lxml') |
| 101 | + tmp = soup.prettify() |
| 102 | + #m = soup.findAll('div',{'class':'boxcenterdir fontstyle'}) |
| 103 | + #soup = BeautifulSoup(tmp,'lxml') |
| 104 | + m = [] |
| 105 | + links = soup.findAll('div',{'class':'dirOuterDiv1 clearFix'}) |
| 106 | + for i in links: |
| 107 | + j = i.findAll('a') |
| 108 | + q = i.find_next('h2') |
| 109 | + g = i.find_next('h4') |
| 110 | + z = g.find_next('h4') |
| 111 | + for k in j: |
| 112 | + idr.append(k['href'].split('=')[-1][:-1]) |
| 113 | + l = i.text |
| 114 | + n = re.findall('Station:[^"]*',l) |
| 115 | + p = re.sub('Playing','\nPlaying',n[0]) |
| 116 | + p=p.rstrip() |
| 117 | + a = p.split('\n') |
| 118 | + name.append(a[0].split(":")[1]) |
| 119 | + track.append(a[1].split(':')[1]) |
| 120 | + aformat.append(q.text) |
| 121 | + listeners.append(g.text) |
| 122 | + bitrate.append(z.text) |
| 123 | + for i in range(len(idr)): |
| 124 | + m.append(name[i].strip().replace('/','-')+'-TV id='+str(idr[i]).replace('\\','')+'\nBitrate='+str(bitrate[i])+'\nListeners='+str(listeners[i])+'\n') |
| 125 | + else: |
| 126 | + url = "https://www.shoutcast.com/Home/BrowseByGenre" |
| 127 | + #content = ccurl(url,opt,1) |
| 128 | + post = 'genrename='+opt |
| 129 | + content = ccurl(url+'#'+'-d'+'#'+post) |
| 130 | + m = self.process_page(content) |
| 131 | + print(opt,url) |
| 132 | + return m |
| 133 | + |
| 134 | + def getEpnList(self,name,opt,depth_list,extra_info,siteName,category): |
| 135 | + name_id = (re.search('id=[^\n]*',extra_info).group()).split('=')[1] |
| 136 | + #nm = name.rsplit('-',1) |
| 137 | + #name = nm[0] |
| 138 | + #name_id = nm[1] |
| 139 | + #name = nm[0] |
| 140 | + file_arr = [] |
| 141 | + id_station = int(name_id) |
| 142 | + station_url = '' |
| 143 | + if opt == "TV" or '-TV' in name: |
| 144 | + url = "http://thugie.nl/streams.php?tunein="+str(id_station) |
| 145 | + #content = ccurl(url,'',1) |
| 146 | + content = ccurl(url) |
| 147 | + final = re.findall('http://[^\n]*',content) |
| 148 | + station_url = final[0].rstrip() |
| 149 | + if 'stream.nsv' not in station_url: |
| 150 | + #print "Hello" + station_url |
| 151 | + station_url = str(station_url.rstrip()+";stream.nsv") |
| 152 | + |
| 153 | + |
| 154 | + else: |
| 155 | + url = "https://www.shoutcast.com/Player/GetStreamUrl" |
| 156 | + #content = ccurl(url,id_station,2) |
| 157 | + post = 'station='+str(id_station) |
| 158 | + content = ccurl(url+'#-d#'+post) |
| 159 | + m = re.findall('http://[^"]*',content) |
| 160 | + station_url = str(m[0]) |
| 161 | + file_arr.append(name+' '+station_url+' '+'NONE') |
| 162 | + #file_arr.append('No.jpg') |
| 163 | + #file_arr.append('Summary Not Available') |
| 164 | + record_history = True |
| 165 | + return (file_arr,'Summary Not Available','No.jpg',record_history,depth_list) |
| 166 | + |
| 167 | + |
| 168 | + def getNextPage(self,opt,pgn,genre_num,name): |
| 169 | + m = [] |
| 170 | + return m |
0 commit comments