def load_db(self, campus, year, quarter): if quarter not in self.QUARTER_TO_NUM: raise ApiError( 404, f'Invalid quarter name. Possible quarters are {", ".join(self.QUARTER_TO_NUM.keys())}' ) quarter_num = self.QUARTER_TO_NUM[quarter] if quarter_num < 3: # If the quarter is summer or fall, then the year should be incremented # Ex. Fall 2020 => 20212X year = int(year) + 1 name = f'{year}{quarter_num}{self.CAMPUS_TO_NUM[campus]}' try: db = TinyDB(join(DB_DIR, f'{name}_database.json'), access_mode='r') except FileNotFoundError: # raise FileNotFoundError try: db = TinyDB(join(DB_DIR, f'new_{name}_database.json'), access_mode='r') except FileNotFoundError: # raise FileNotFoundError try: db = TinyDB(join(DB_DIR, f'sched_{name}_database.json'), access_mode='r') except FileNotFoundError: raise FileNotFoundError return db
def new(name=None): if name is None: raise ApiError("Playlist name must be defined") playlist = _empty_playlist(name) plid = _get_plid(name) playlist['plid'] = plid save(playlist) return get(plid)
def playOnRB(url=None, title=None, subs=None): if url is None: raise ApiError("Play url is undefined") if subs is not None: _save_subs_prefs(subs) obj = urlparse.urlparse(url) #print "url=>" + url Player.playLive(url, title, subs)
def control(action=None): if action is None: raise ApiError("Action is undefined") if action == "stop": Player.stop() elif action == "pause": Player.pause() elif action == "resume": Player.resume()
def new_remote(url=None): if url is None: raise ApiError("Remote playlist URL must be defined") url = _fix_remote_url(url) playlist = _fetch_remote(url) plid = _get_plid(playlist['title']) playlist['plid'] = plid save(playlist) return get(plid)
def _fetch_remote(url): r = requests.get(url) if r.status_code >= 300: raise ApiError("Fetch remote playlist returned: " + str(r.status_code)) playlist = r.json() playlist['url'] = url if not playlist['title'].endswith("[REMOTE]"): playlist['title'] = playlist['title'] + " [REMOTE]" return playlist
def supported(url=None): if url is None: raise ApiError("Play url is undefined") ies = youtube_dl.extractor.gen_extractors() for ie in ies: if ie.suitable(url) and ie.IE_NAME != 'generic': return "Supported" return "Not Supportred"
def del_item(plid=None, item=None): if (plid is None) or (item is None): raise ApiError("Playlist ID and item must be defined") playlist = get(plid) items = playlist['items'] for i in items: if i['url'] == item['url']: items.remove(i) break save(playlist)
def info(chid=None): if chid is None: raise ApiError("Channel ID is missing") info = installed.getChannel(chid).getInfo() if installed.isEnabled(chid): info['actions'] = [{'label': 'Disable', 'type': 'disablechannel'}] else: info['actions'] = [{'label': 'Enable', 'type': 'enablechannel'}] info['settings'] = installed.getChannelSettings(chid) return info
def item(link=None): if not link: raise ApiError("Item URL must be defined") results = playitem.PlayItemList() title = link if len(title) > 30: title = title[:30] + "..." img = '/img/icons/file-o.svg' if chanutils.torrent.is_torrent(link): link = chanutils.torrent.set_torridx(link) results.add(playitem.PlayItem(title, img, link, subs={})) return results.to_dict()
def save(playlist=None): if playlist is None: raise ApiError("Playlist must be defined") plid = playlist.pop("plid", None) playlist.pop("actions", None) for item in playlist['items']: item.pop('actions', None) item.pop('playlist', None) item.pop('itemnum', None) if 'subs' in item: item['subs'].pop('lang', None) json.dump(playlist, open(_get_path(plid), "w"))
def play(url=None, title=None, subs=None): if url is None: raise ApiError("Play url is undefined") if subs is not None: _save_subs_prefs(subs) obj = urlparse.urlparse(url) if obj.netloc == "www.itv.com": cmd = extractor.itv.extract(url) Player.playRtmpdump(cmd, title) elif chanutils.torrent.is_torrent_url(url): Player.playTorrent(url, chanutils.torrent.torrent_idx(url), title, subs) else: Player.playYtdl(url, title, subs)
def play(url=None, title=None, subs=None): if url is None: raise ApiError("Play url is undefined") if subs is not None: _save_subs_prefs(subs) obj = urlparse.urlparse(url) if obj.scheme == "file": Player.playLocalFile(obj.path, title) elif chanutils.torrent.is_torrent_url(url): Player.playTorrent(url, chanutils.torrent.torrent_idx(url), title, subs) else: Player.playYtdl(url, title, subs)
def get(plid=None): if plid is None: raise ApiError("Playlist ID must be defined") playlist = json.load(open(_get_path(plid), 'r')) if not playlist: playlist = _empty_playlist() playlist['plid'] = plid results = playitem.PlayItemList() itemnum = 0 for item in playlist['items']: results.add(playitem.PlaylistItem(item, plid, itemnum)) itemnum = itemnum + 1 playlist['items'] = results.to_dict() return playlist
def load_db(self, campus, year, quarter): if quarter not in self.QUARTER_TO_NUM: raise ApiError( 404, f'Invalid quarter name. Possible quarters are {", ".join(self.QUARTER_TO_NUM.keys())}' ) name = f'{self.CAMPUS_TO_PREFIX[campus]}_{year}{self.QUARTER_TO_NUM[quarter]}0' try: db = TinyDB(join(DB_DIR, f'sched_{name}_database.json'), access_mode='r') except FileNotFoundError: raise FileNotFoundError return db
def search_all(q=None): if q is None: raise ApiError("Search requires query") enabled = list_enabled() threads = [] queue = Queue(len(enabled)) for chan in enabled: if chan['search']: th = Thread(target=_search_thread, args=(queue, chan['id'], q)) th.start() threads.append(th) results = [] for thread in threads: thread.join() r = queue.get() if len(r[1]) > 0: results.append(r) return results
def play(url=None, title=None, subs=None): if url is None: raise ApiError("Play url is undefined") if subs is not None: _save_subs_prefs(subs) obj = urlparse.urlparse(url) #extension = urlparse.urlparse(url) filename, file_ext = splitext(basename(obj.path)) if obj.scheme == "file": Player.playLocalFile(obj.path, title) elif obj.netloc == "www.twitch.tv": Player.playLivestream(url, title) elif obj.netloc == "www.gplexdb.net": #print "url=>" + url #print obj.netloc #print file_ext if file_ext in ['.m3u8']: head, sep, tail = url.partition('/http') tail = 'http' + tail #newurl = tail.split('&rocket', 1)[0] #newurl = tail.split('?rocket', 1)[0] newurl = "http://www.royalbox.tv/loadiplayer6.php/" + tail #print "newurl=>" + newurl #print "tail=>" + tail Player.playNoProxy(url, title, subs) #Player.playLive(tail, title, subs) else: Player.playLive(url, title, subs) #Player.playYtdl(url, title, subs) elif chanutils.torrent.is_torrent_url(url): Player.playTorrent(url, chanutils.torrent.torrent_idx(url), title, subs) elif file_ext in ['.m3u8', '.mp4']: print "live url=>" + url Player.playLive(url, title, subs) else: #print "youtube url=>" + url Player.playYtdl(url, title, subs)
def playOnDevice(url=None, title=None, subs=None): if url is None: raise ApiError("Play url is undefined") if subs is not None: _save_subs_prefs(subs) obj = urlparse.urlparse(url) #extension = urlparse.urlparse(url) filename, file_ext = splitext(basename(obj.path)) if obj.scheme == "file": Player.playLocalFile(obj.path, title) elif obj.netloc == "www.twitch.tv": Player.playLivestream(url, title) elif obj.netloc == "www.sbs.com.au": newurl = download_sbs(url) print "playOnDevice newurl=>" + newurl return Player.playURL2(newurl, title, subs) elif obj.netloc == "www.gplexdb.net": #print "url=>" + url #print obj.netloc #print file_ext if file_ext in ['.m3u8']: head, sep, tail = url.partition('/http') tail = 'http' + tail newurl = "http://www.royalbox.tv/loadiplayer6.php/" + tail return Player.playNoProxy2(url, title, subs) else: return Player.playYtdl2(url, title, subs) elif chanutils.torrent.is_torrent_url(url): Player.playTorrent(url, chanutils.torrent.torrent_idx(url), title, subs) elif file_ext in ['.m3u8']: #print "url=>" + url return Player.playLive2(url, title, subs) else: #print "url=>" + url return Player.playYtdl2(url, title, subs)
def feed_by_name(chid=None, idx=None, name=None): if chid is None or idx is None or name is None: raise ApiError( "All of Channel ID, feed index and name must be defined") return installed.getChannel(chid).getFeedByName(idx, name)
def showmore(chid=None, link=None): if chid is None or link is None: raise ApiError("Both channel ID and link must be defined") return installed.getChannel(chid).showmore(link)
def search(chid=None, q=None): if chid is None or q is None: raise ApiError("Both Channel ID and search query must be defined") return installed.getChannel(chid).search(q)
def feed(chid=None, idx=None): if chid is None or idx is None: raise ApiError("Both Channel ID and feed index must be defined") return installed.getChannel(chid).getFeed(idx)
def feedlist(chid=None): if chid is None: raise ApiError("Channel ID is missing") return installed.getChannel(chid).getFeeds()
def add_item(plid=None, item=None): if (plid is None) or (item is None): raise ApiError("Playlist ID and item must be defined") playlist = get(plid) playlist['items'].append(item) save(playlist)
def enable(chid=None): if chid is None: raise ApiError("Channel ID is missing") installed.enableChannel(chid) return list_all()
def getChannel(self, chid): for chan in self.channels: if chan.getId() == chid: return chan raise ApiError("Unknown channel ID: '" + chid + "'")
def files(link=None): if not link: raise ApiError("Torrent URL must be defined") return showmore(link).to_dict()
def control(action=None): if action is None: raise ApiError("Action is undefined") Player.control(action)
def validate_campus(self, campus): if campus not in ALL_CAMPUS: raise ApiError( 404, f'Campus not found! Available campuses are {", ".join(ALL_CAMPUS.keys())}.' )