def handleInput(): downloadQueue = [] #data.txt is the file where the front end leaves the data for us inputText = core.read('/opt/lampp/htdocs/data.txt') print(inputText) core.write('/opt/lampp/htdocs/data.txt', '') #inputText is split into an array so that we can interact with each line #individually (Different URLs are put on different lines by the frontend). inputArray = core.split(inputText) print(inputArray) i = 0 #This loop allows us to perform the same function #on each line of the array. In this case it goes through each line and sorts #it into a video url, a playlist url, or random text. And then the #appropriate response is carried out while i < len(inputArray): inputData = inputArray[i] print(inputData) if 'list=' in inputData: #'list=' is unique to playlist urls core.log('playlists', inputData) if 'v=' in inputData: #v= is unique to video urls downloadQueue.append(inputData) i = i + 1 return downloadQueue
def read_git_file(f): if f is None: return None if is_git_file(f): fh = open(f) data = core.decode(core.read(fh)).rstrip() fh.close() if data.startswith('gitdir: '): return core.decode(data[len('gitdir: '):]) return None
def playlistCheck(): playlists = core.split(core.read('playlists')) i = 0 while i < len(playlists): if len(playlists[0]) > 2: core.write(playlists[i].split('list=')[1], '') playlist(playlists[i]) i = i + 1 return
def watchedCheck(playlistID, videoIDs): unwatchedVideoIDs = [] watchedList = core.read(playlistID) watchedIDs = core.split(watchedList) i = 0 while i < len(videoIDs): if videoIDs[i] not in watchedIDs: unwatchedVideoIDs.append(videoIDs[i]) i = i + 1 return unwatchedVideoIDs
def main(): clear() create() data = core.read('info') core.log('log', data) data = core.split(data) createPlaylist() playlistUrls = core.read('playlistUrls') core.log('log', playlistUrls) playlistUrls = core.split(playlistUrls) search(data) videos = core.read('videos') core.log('log', videos) videos = core.split(videos) download(data, videos) clear()
def search(data): global globalInteger il = globalInteger ii = 1 while il > 0: location = data[ii] query_string = urllib.parse.urlencode({"search_query" : location}) html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string) search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode()) print("Adding video1: " + search_results[searchInteger]) core.log('videos',("http://www.youtube.com/watch?v=" + search_results[0])) ii = ii + 2 il = il - 1 videos = core.read('videos') return
def createPlaylist(): global otherGlobalInteger playlistUrl = 'Placeholder' while len(playlistUrl) > 0: #idct = input("Directory>") #if len(idct) > 0: # dct = idct playlistUrl = input("Playlist Url> ") if len(playlistUrl) > 0: otherGlobalInteger = otherGlobalInteger + 1 playlistUrls ="{}\n{}".format(downloadDir, playlistUrl) core.log('playlistUrls', playlistUrls) playlist(playlistUrl) playlistUrls = core.read('playlistUrls') return
def create(): global globalInteger location = 'Placeholder' while len(location) > 0: #idct = input("Directory>") #if len(idct) > 0: # dct = idct location = input("Keyword> ") if len(location) > 0: globalInteger = globalInteger + 1 data ="{}\n{}".format(downloadDir, location) core.log('info', data) data = core.read('info') return
def moderate(): pd = PageData() sql = read('imgmods') result = doquery(sql) pd.mods = [] pd.tags = Tree('tags') for mod in result: try: imgid = mod[0] flag = mod[2] user = mod[3] if user is None: user = '******' else: user = user_by_uid(user) if mod[1] == 0 or flag == 1: sql = 'select tag from images where uid = %(uid)s;' img = doquery(sql, {"uid": imgid}) class Mod: pass mod = Mod() if img: mod.uid = imgid mod.tag = img[0][0] mod.user = user mod.flag = flag pd.mods.append(mod) else: flash('Error loading data for image ' + str(imgid)) except IndexError as e: pd.title = "SQL error" pd.errortext = "SQL error" return render_template('error.html', pd=pd) pd.title = "Unmoderated images" return render_template('moderation.html', pd=pd)
def log(filefrom, fileto): x = core.read(filefrom) core.log(fileto, x)
def slurp(path): """Slurps a filepath into a string.""" fh = open(core.encode(path)) slushy = core.read(fh) fh.close() return core.decode(slushy)