Exemplo n.º 1
0
def getPages(url, verbose):
    gotAnswer = False
    sourceCode = ""
    pageNo = 1
    videos = []
    
    parsed_uri = urlparse( url )
    domain = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri)
    if verbose:
        printInfo1("Domain is: %s" % domain)
    
    while True:
        printInfo1("\nGetting page %s..." % pageNo)
        printInfo1("URL: %s" % "%s/?sida=%s" % (url, pageNo))
        responseCode = getResponseCode("%s/?sida=%s" % (url, pageNo), verbose)
        #if pageNo == 2:
        #    responseCode = 404
        if responseCode != 404:
            trys = 0
            while True:
                trys += 1
                if verbose:
                    printInfo1("%s%s try" % (trys, numbering(trys, verbose)))
                if trys > maxTrys:
                    onError(10, "Tried connecting %s times. Giving up..." % (trys - 1))
                try:
                    source = urllib2.urlopen("%s/?sida=%s" % (url, pageNo))
                except urllib2.HTTPError, e:
                    onError(23, "HTTPError\n    %s\n    Trying again...\n" % str(e.code))
                    sleep(waitTime)
                except urllib2.URLError, e:
                    onError(24, "URLError\n    %s\n    Trying again...\n" % str(e.reason))
                    sleep(waitTime)
                except:
Exemplo n.º 2
0
def parseXML(xmlRoot, url, name, fileInfo, downloadAll, setQuality, bestQuality, checkDuration, verbose):
    vidBitRate = 0
    vidWidth = 0
    currentQuality = 0
    lastQuality = 0
    downloads = []
                
    if name == "null":
        trys = 0
        printInfo2("Getting page title to use as file name...")
        while True:
            trys += 1
            if trys > maxTrys:
                onError(10, "Tried connecting %s times. Giving up..." % (trys - 1))
            if verbose:
                printInfo1("%s%s try" % (trys, numbering(trys, verbose)))
            try:
                html = urllib2.urlopen(url)
            except urllib2.HTTPError, e:
                onError(35, "HTTPError\n    %s\n    Trying again...\n" % str(e.code))
                sleep(waitTime)
            except urllib2.URLError, e:
                onError(36, "URLError\n    %s\n    Trying again...\n" % str(e.reason))
                sleep(waitTime)
            except:
Exemplo n.º 3
0
def retrievePiratePlayXML(apiBaseUrl, url, name, fileInfo, downloadAll, setQuality, bestQuality, checkDuration, verbose):
    xmlCode = ""
    trys = 0
    
    if verbose:
        printInfo1("Using %s as source for getting XML" % apiBaseUrl)
    
    if verbose:
        printInfo2("Parsing the response from pirateplay.se API...")
    parseUrl = "%s/%s%s" % (apiBaseUrl, getStreamsXML, url)
    printInfo2("\nGetting streams for %s ..." % parseUrl)
    printScores()
    
    while True:
        trys += 1
        if trys > maxTrys:
            onError(10, "Tried connecting %s times. Giving up..." % (trys - 1))
            break
        if verbose:
            printInfo1("%s%s try" % (trys, numbering(trys, verbose)))
        try:
            piratePlayXML = urllib2.urlopen(parseUrl)
        except urllib2.HTTPError, e:
            onError(35, "HTTPError\n    %s\n    Trying again...\n" % str(e.code))
            sleep(waitTime)
        except urllib2.URLError, e:
            onError(36, "URLError\n    %s\n    Trying again...\n" % str(e.reason))
            sleep(waitTime)
Exemplo n.º 4
0
def getResponseCode(url, verbose):
    trys = 0
    responseCode = ""
    
    if verbose:
        printInfo1("Getting response code...")
    
    while True:
        trys += 1
        if verbose:
            printInfo1("%s%s try" % (trys, numbering(trys, verbose)))
        if trys > maxTrys:
            onError(22, "Tried %s times" % (trys - 1))
        try:
            r = requests.head(url)
        except requests.ConnectionError:
            onError(20, "Failed to connect\nTrying again...")
        else:
            responseCode = r.status_code
            if verbose:
                printInfo1("Response: %s" % responseCode)
            break
        
    return responseCode
Exemplo n.º 5
0
def getVideos(downloads, keepOld, reDownload, checkDuration, verbose):
    oldReDownload = reDownload
    
    printInfo2("\nStarting downloads")
    
    for line in downloads:
        trys = 0
        videoCmd, subCmd = getDownloadCommands(line, verbose)

        while True:
            trys += 1
            if trys > maxTrys:
                onError(29, "Tried to download video %s times\nSkipping..." % (trys - 1))
                videoComment = dlCommentError
                break
            
            print
            printInfo2("Downloading stream to %s.%s ..." % (line['name'].rstrip(), line['suffix']))
            expectedDuration = round(float(line['duration']), 2)
            printInfo1("Expected duration: %s" % str(datetime.timedelta(seconds=expectedDuration)))
            printInfo1("%s%s try" % (trys, numbering(trys, verbose)))
            printScores()
                
            if continueWithProcess(line['name'].rstrip(), line['suffix'], keepOld, reDownload,
                                   "Will redownload\n", "Keeping old file. No download\n", verbose):
                if verbose:
                    printInfo2("Executing download command...")
                    print videoCmd
                exitCode = runProcess(videoCmd, verbose)
                if exitCode != 0:
                    printScores()
                    onError(30, "Failed. Process exited on %s" % exitCode)
                    printInfo2("Trying again...")
                    reDownload = True
                else:
                    if checkDuration and float(line['duration']) > 0:
                        durationOK = checkDurations(line, verbose)
                    else:
                        if verbose:
                            printWarning("Not checking duration")
                        durationOK = True 
                    if os.path.isfile("%s.%s" % (line['name'].rstrip(), line['suffix'])) and durationOK:
                        printScores()
                        printInfo1("Finished downloading video")
                        setPerms("%s.%s" % (line['name'].rstrip(), line['suffix']), verbose)
                        reDownload = oldReDownload
                        videoComment = dlCommentSuccess
                        break
                    else:
                        printScores()
                        if not durationOK:
                            onError(46, "Durations does not match")
                            printInfo2("Trying again")
                        else:
                            onError(31, "Failed. Video file does not exist")
                            printInfo2("Trying again...")
                        reDownload = True
            else:
                videoComment = dlCommentExist
                break

        if subCmd:
            trys = 0
            oldReDownload = reDownload
            
            while True:
                trys += 1
                if trys > maxTrys:
                    onError(32, "Tried to download subtitles %s times\nSkipping..." % (trys - 1))
                    subComment = dlCommentError
                    break
                
                print
                printInfo2("Downloading subtitles %s.srt ..." % line['name'].rstrip())
                if verbose:
                    printInfo1("from %s" % line['subs'])
                printInfo1("%s%s try" % (trys, numbering(trys, verbose)))
                printScores()
                
                if continueWithProcess(line['name'].rstrip(), "srt", keepOld, reDownload,
                                       "Will redownload\n", "Keeping old file. No download\n", verbose):
                    if verbose:
                        printInfo2("Downloading file...")
                        print line['subs']
                        print videoCmd
                    result = downloadFile(line['subs'], "%s.%s" % (line['name'].rstrip(), "srt"), verbose)
                    if not result:
                        printScores()
                        onError(33, "Failed to download subtitles")
                        printInfo2("Trying again...")
                        reDownload = True
                    else:
                        fileSizeOK = checkFileSize(line, verbose)
                        if os.path.isfile("%s.srt" % line['name'].rstrip()) and fileSizeOK:
                            printScores()
                            printInfo1("Finished downloading subtitles")
                            setPerms("%s.srt" % line['name'].rstrip(), verbose)
                            reDownload = oldReDownload
                            subComment = dlCommentSuccess
                            break
                        else:
                            printScores()
                            if not fileSizeOK:
                                onError(47, "Failed. File sizes does not match")
                                printInfo2("Trying again")
                            else:
                                onError(34, "Failed. Subtitle file does not exist")
                                printInfo2("Trying again")
                            reDownload = True
                else:
                    subComment = dlCommentExist
                    break
        else:
            subComment = dlCommentNoSub

        printInfo2("\nGetting file info...")
                    
        fileSize = getInfo(line, '--Inform="General;%FileSize%"', verbose)
        fileSizeMeasure = getInfo(line, '--Inform="General;%FileSize/String%"', verbose)
        duration = getInfo(line, '--Inform="General;%Duration%"', verbose)
        durationFormatted = getInfo(line, '--Inform="General;%Duration/String3%"', verbose)
        overallBitRate = getInfo(line, '--Inform="General;%OverallBitRate%"', verbose)
        overallBitRateMeasure = getInfo(line, '--Inform="General;%OverallBitRate/String%"', verbose)
        
        videoFormat = getInfo(line, '--Inform="Video;%Format%"', verbose)
        videoCodecId = getInfo(line, '--Inform="Video;%CodecID%"', verbose)
        videoBitRate = getInfo(line, '--Inform="Video;%BitRate%"', verbose)
        videoBitRateMeasure = getInfo(line, '--Inform="Video;%BitRate/String%"', verbose)
        width = getInfo(line, '--Inform="Video;%Width%"', verbose)
        height = getInfo(line, '--Inform="Video;%Height%"', verbose)
        frameRate = getInfo(line, '--Inform="Video;%FrameRate%"', verbose)
        frameCount = getInfo(line, '--Inform="Video;%FrameCount%"', verbose)
        
        audioFormat = getInfo(line, '--Inform="Audio;%Format%"', verbose)
        audioCodecId = getInfo(line, '--Inform="Audio;%CodecID%"', verbose)
        audioBitRate = getInfo(line, '--Inform="Audio;%BitRate%"', verbose)
        audioBitRateMeasure = getInfo(line, '--Inform="Audio;%BitRate/String%"', verbose)
        
        if line['subs']:
            subSize = os.path.getsize("%s.srt" % line['name'].rstrip())
            with open("%s.srt" % line['name'].rstrip()) as myfile:
                subLines = sum(1 for line in myfile)  # number of lines in file
            myfile.close()  # close file
        else:
            subSize = "na"
            subLines = "na"

        infoDownloaded.append({'videoName': "%s.%s" % (line['name'].rstrip(), line['suffix']),
                               'expectedDuration': line['duration'], 
                               'videoDlComment': videoComment, 
                               'fileSize': fileSize,
                               'fileSizeMeasure': fileSizeMeasure,
                               'duration': duration,
                               'durationFormatted': durationFormatted,
                               'overallBitRate': overallBitRate,
                               'overallBitRateMeasure': overallBitRateMeasure,
                               'videoFormat': videoFormat,
                               'videoCodecId': videoCodecId,
                               'videoBitRate': videoBitRate,
                               'videoBitRateMeasure': videoBitRateMeasure,
                               'width': width,
                               'height': height,
                               'frameRate': frameRate,
                               'frameCount': frameCount,
                               'audioFormat': audioFormat,
                               'audioCodecId': audioCodecId,
                               'audioBitRate': audioBitRate,
                               'audioBitRateMeasure': audioBitRateMeasure,
                               'subName': "%s.srt" % line['name'].rstrip(),
                               'expectedSubSize': line['subSize'], 
                               'subDlComment': subComment, 
                               'subSize': subSize,
                               'subLines': subLines})
        
        printScores()
        print

    return infoDownloaded