Sinisterly
[c++] ytsrip - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C)
+--- Thread: [c++] ytsrip (/Thread-c-ytsrip)



[c++] ytsrip - hussy - 11-15-2017

i need a script to extract all movies from yts and launch torrent, here it is

Code:
#include <stdio.h> #include <stdlib.h> #include <curl/curl.h> #include <iostream> #include <cstring> #include <vector> #include "gumbo.h" using namespace std; CURL *curl; CURLcode res; string data,    __HOST, __QUALITY, __SHELL; vector<string> magnets; static size_t callback( void *data, size_t size, size_t nmemb, void *pointer ) {    ( (string*)pointer)->append((char*)data, size * nmemb);    return size * nmemb; } void gumbo_extract_magnets( GumboNode* node ) {    GumboAttribute* url;    if ( node->type == GUMBO_NODE_ELEMENT)    {        if (node->v.element.tag == GUMBO_TAG_A && (url = gumbo_get_attribute(&node->v.element.attributes, "href") ) )        {            GumboNode* title_text = static_cast<GumboNode*>(node->v.element.children.data[0]);            if (title_text->type == GUMBO_NODE_TEXT)            {                if( static_cast<string>(title_text->v.text.text).find( __QUALITY ) == 0 )                {                    magnets.push_back( url->value );                }            }        }        GumboVector* children = &node->v.element.children;        for ( unsigned int i = 0; i < children->length; i++ ) {            gumbo_extract_magnets(static_cast<GumboNode*>(children->data[i]));        }    } } int main( int argc, char *argv[] ) {    cout << "-> Enter the host engine (ex. yts.gs): " << endl;    getline (cin, __HOST);    cout << "-> Enter the video quality (ex. 3D, 1080p, 720p): " << endl;    getline (cin, __QUALITY);    cout << "-> Enter the shell application (ex. xdg-open, utorrent): " << endl;    getline (cin, __SHELL);    curl = curl_easy_init();    if( curl ) {        std::cout << "ytsrip<: init() success" << endl;    }    else {        std::cout << "ytsrip<: init() failed" << endl;        return 1;    }    for ( int i = 1; i <= 326; i++ )    {        string url = "https://" + __HOST + "/browse-movies?page=" + std::to_string(i);        std::cout << "ytsrip<: setopt() - " << url << endl;        curl_easy_setopt( curl, CURLOPT_URL, url.c_str() );        curl_easy_setopt( curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; ytsrip; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0");        curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, callback );        curl_easy_setopt( curl, CURLOPT_WRITEDATA, &data );        if( curl_easy_perform(curl) == CURLE_OK )        {            GumboOutput* output = gumbo_parse( data.c_str() );            gumbo_extract_magnets( output->root );            gumbo_destroy_output( &kGumboDefaultOptions, output );            for( vector<int>::size_type i = 0; i <= magnets.size(); i++)            {                std::cout << "ytsrip<: " << magnets[i] << endl;                string command = __SHELL + magnets[i];                system( command.c_str() );            }        }        else {            std::cout << "ytsrip<: perform() failed" << endl;            return 2;        }        data.clear();        magnets.clear();    }    std::cout << "ytsrip<: done!" << endl;    return 0; }



RE: [c++] ytsrip - hussy - 11-15-2017

(11-15-2017, 10:15 PM)Bootlegronin47 Wrote: What language is this in?

c++, it uses gumbo-parser and libcurl


RE: [c++] ytsrip - phyrrus9 - 12-12-2017

(11-15-2017, 10:13 PM)hussy Wrote: i need a script to extract all movies from yts and launch torrent, here it is

Code:
#include <stdio.h> #include <stdlib.h> #include <curl/curl.h> #include <iostream> #include <cstring> #include <vector> #include "gumbo.h" using namespace std; CURL *curl; CURLcode res; string data,    __HOST, __QUALITY, __SHELL; vector<string> magnets; static size_t callback( void *data, size_t size, size_t nmemb, void *pointer ) {    ( (string*)pointer)->append((char*)data, size * nmemb);    return size * nmemb; } void gumbo_extract_magnets( GumboNode* node ) {    GumboAttribute* url;    if ( node->type == GUMBO_NODE_ELEMENT)    {        if (node->v.element.tag == GUMBO_TAG_A && (url = gumbo_get_attribute(&node->v.element.attributes, "href") ) )        {            GumboNode* title_text = static_cast<GumboNode*>(node->v.element.children.data[0]);            if (title_text->type == GUMBO_NODE_TEXT)            {                if( static_cast<string>(title_text->v.text.text).find( __QUALITY ) == 0 )                {                    magnets.push_back( url->value );                }            }        }        GumboVector* children = &node->v.element.children;        for ( unsigned int i = 0; i < children->length; i++ ) {            gumbo_extract_magnets(static_cast<GumboNode*>(children->data[i]));        }    } } int main( int argc, char *argv[] ) {    cout << "-> Enter the host engine (ex. yts.gs): " << endl;    getline (cin, __HOST);    cout << "-> Enter the video quality (ex. 3D, 1080p, 720p): " << endl;    getline (cin, __QUALITY);    cout << "-> Enter the shell application (ex. xdg-open, utorrent): " << endl;    getline (cin, __SHELL);    curl = curl_easy_init();    if( curl ) {        std::cout << "ytsrip<: init() success" << endl;    }    else {        std::cout << "ytsrip<: init() failed" << endl;        return 1;    }    for ( int i = 1; i <= 326; i++ )    {        string url = "https://" + __HOST + "/browse-movies?page=" + std::to_string(i);        std::cout << "ytsrip<: setopt() - " << url << endl;        curl_easy_setopt( curl, CURLOPT_URL, url.c_str() );        curl_easy_setopt( curl, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; ytsrip; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0");        curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, callback );        curl_easy_setopt( curl, CURLOPT_WRITEDATA, &data );        if( curl_easy_perform(curl) == CURLE_OK )        {            GumboOutput* output = gumbo_parse( data.c_str() );            gumbo_extract_magnets( output->root );            gumbo_destroy_output( &kGumboDefaultOptions, output );            for( vector<int>::size_type i = 0; i <= magnets.size(); i++)            {                std::cout << "ytsrip<: " << magnets[i] << endl;                string command = __SHELL + magnets[i];                system( command.c_str() );            }        }        else {            std::cout << "ytsrip<: perform() failed" << endl;            return 2;        }        data.clear();        magnets.clear();    }    std::cout << "ytsrip<: done!" << endl;    return 0; }

Interesting choice of language, I have to say. It doesn't look like there's any reason to use C++ for this, why not stick with plain C since you're only using C APIs?
Secondly, why the choice of making your cURL vars global?

I don't mean this in a bad way, just constructive criticism