def check(self, link): """""" name = "Unknown" size = 0 status_msg = None link_status = cons.LINK_ERROR try: #strip file name tmp = link.split("/file/")[1].split("/")[0] link = "%s/file/%s" % (BASE_URL, tmp) link_quoted = urllib.quote_plus(link) with URLClose( request.get( "http://www.filefactory.com/tool/links.php?func=links&links=" + link_quoted, timeout=10)) as s: alive = False for line in s: if 'Available' in line: alive = True elif alive: if 'class="metadata"' in line: name = line.split('class="metadata">')[-1].split( '</div>')[0].split('/')[-1].strip() name = html_entities_parser(name) s.next() size_list = s.next().split("<td>")[-1].split( "</td>")[0].split(" ") #size = "".join(size_list) size = int(float(size_list[0])) link_status = cons.LINK_ALIVE break if link_status != cons.LINK_ALIVE: link_status = cons.LINK_DEAD except (urllib2.URLError, httplib.HTTPException, socket.error) as err: status_msg = "Error: {0}".format(err) logger.warning(err) except Exception as err: status_msg = "Error: {0}".format(err) logger.exception(err) return link_status, name, size, status_msg
def check(self, link): """""" name = "Unknown" size = 0 status_msg = None link_status = cons.LINK_ERROR try: #strip file name tmp = link.split("/file/")[1].split("/")[0] link = "%s/file/%s" % (BASE_URL, tmp) link_quoted = urllib.quote_plus(link) with URLClose(request.get("http://www.filefactory.com/tool/links.php?func=links&links=" + link_quoted, timeout=10)) as s: alive = False for line in s: if 'Available' in line: alive = True elif alive: if 'class="metadata"' in line: name = line.split('class="metadata">')[-1].split('</div>')[0].split('/')[-1].strip() name = html_entities_parser(name) s.next() size_list = s.next().split("<td>")[-1].split("</td>")[0].split(" ") #size = "".join(size_list) size = int(float(size_list[0])) link_status = cons.LINK_ALIVE break if link_status != cons.LINK_ALIVE: link_status = cons.LINK_DEAD except (urllib2.URLError, httplib.HTTPException, socket.error) as err: status_msg = "Error: {0}".format(err) logger.warning(err) except Exception as err: status_msg = "Error: {0}".format(err) logger.exception(err) return link_status, name, size, status_msg
def check(self, link): """""" name = cons.UNKNOWN size = 0 status_msg = None link_status = cons.LINK_ERROR #for retry_count in range(RETRIES): try: with URLClose(request.get(link)) as s: for line in s: if 'name="description"' in line: name = line.split('content="')[-1].split(" | Free file hosting")[0] name = utils.html_entities_parser(name) elif "File Size:</b>" in line: tmp = line.split("</b>")[-1].split("</div>")[0].strip() unit = tmp[-2:] size = float(tmp[:-2]) #convert size to bytes. if unit == "KB": size = size * 1024 elif unit == "MB": size = size * 1024 * 1024 elif unit == "GB": size = size * 1024 * 1024 * 1024 break if size: link_status = cons.LINK_ALIVE else: link_status, name, size = cons.LINK_DEAD, cons.UNKNOWN, 0 except (urllib2.URLError, httplib.HTTPException, socket.error) as err: status_msg = "Error: {0}".format(err) except Exception as err: name, size = cons.UNKNOWN, 0 logger.exception(err) return link_status, name, size, status_msg