Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't download with yggtorrent #96

Closed
exasky opened this issue Mar 7, 2020 · 6 comments
Closed

Can't download with yggtorrent #96

exasky opened this issue Mar 7, 2020 · 6 comments

Comments

@exasky
Copy link

exasky commented Mar 7, 2020

When I try to download with yggTorrent provider I always get this error in the downloaded file : "Vous devez vous connecter pour télécharger un torrent" (You must be logged in to download a torrent)
I guess the authentication isn't working.

@cyril-colin
Copy link

Hi, have you tried to override the default yggtorrent url ? Because yggtorrent url has changed.

const torrentSearch = require('torrent-search-api');

torrentSearch.overrideConfig('YggTorrent', {
  baseUrl: 'https://www2.yggtorrent.se/' // The new YGGtorrent url
});
torrentSearch.enableProvider('YggTorrent', 'USERNAME', 'PASSWORD');

torrentSearch.search('1080', 'Movies', 20).then(res => {
  console.log(res);
  torrentSearch.downloadTorrent(res[0], '/tmp/test.torrent').then(success => {
    console.log('downloaded', success);
  }).catch(err => console.error('ERR : ', err));
});

This code work for me (until the url change again... please check https://mamot.fr/@YggTorrent if you want to know the current yggtorrent url and avoid phishing web sites)

@exasky
Copy link
Author

exasky commented Mar 8, 2020

Wokay, your method works indeed.

In my code I overrided the getUrl & search method to fit my need, can't figure out why it isn't working. I only override the search & getUrl part, not the download part.
I'm giving you my code in case you have an idea...

const format = require('string-format');

export function yggTorrentProviderOverride(yggTorrentProvider: any) {
    yggTorrentProvider.baseUrl = 'https://www2.yggtorrent.se';
    yggTorrentProvider.searchUrl = '/engine/search?name={query}&description=&file=&uploader=&category={cat}&do=search&order={order}&sort={sort}&page={page}';

    yggTorrentProvider.getUrl = (queryString: YggQuery): string => {
        const cat = yggTorrentProvider.getCategoryValue(queryString.cat);
        if (cat === null) return null;

        queryString.cat = cat;

        let url =
            yggTorrentProvider.baseUrl + (cat.startsWith('url:') ? cat.substr(4) : yggTorrentProvider.searchUrl);


        url = format(url, queryString);
        url = url.replace(/ /g, '+');

        return url;
    };
    yggTorrentProvider.search = async (yggQuery: YggQuery) => {
        const pageLimit = 1;
        const url = yggTorrentProvider.getUrl(yggQuery);

        if (!url) {
            return Promise.resolve();
        }

        await yggTorrentProvider.ensureLogin();
        const result = await yggTorrentProvider.fetchAndParseUrl(url, pageLimit);
        const returnValue = await yggTorrentProvider.postProcess(result);
        return returnValue;
    };
    yggTorrentProvider.downloadTorrentBuffer = async (torrent: any) => {
        await yggTorrentProvider.ensureLogin();
        return yggTorrentProvider.request(torrent.link, { encoding: null }).then((r: any) => r.body);
    }
}

export class YggQuery {
    query: string;
    cat: string = 'all';
    order?: string = 'desc';
    sort?: string = 'publish_date';
    page?: number = 0;
}

@cyril-colin
Copy link

Sorry I can't help you for now : I know this package only for 2 hours ^^

@JimmyLaurent
Copy link
Owner

@exasky From what I seed, you're only trying to add order, sort, and page to the url, don't you ?

I tried you're code and except a minor change to work with the last release, everything seems to be ok.

Check this out and tell me:

const format = require('string-format');
const YggTorrentProvider = require('torrent-search-api/providers/yggtorrent');

function yggTorrentProviderOverride(yggTorrentProvider) {
  yggTorrentProvider.baseUrl = 'https://www2.yggtorrent.se';
  yggTorrentProvider.searchUrl =
    '/engine/search?name={query}&description=&file=&uploader=&category={cat}&do=search&order={order}&sort={sort}&page={page}';

  yggTorrentProvider.getUrl = queryString => {
    const cat = yggTorrentProvider.getCategoryValue(queryString.cat);
    if (cat === null) return null;

    queryString.cat = cat;

    let url =
      yggTorrentProvider.baseUrl +
      (cat.startsWith('url:') ? cat.substr(4) : yggTorrentProvider.searchUrl);

    url = format(url, queryString);
    url = url.replace(/ /g, '+');

    return url;
  };
  yggTorrentProvider.search = async yggQuery => {
    const pageLimit = 1;
    const url = yggTorrentProvider.getUrl(yggQuery);

    if (!url) {
      return Promise.resolve();
    }

    await yggTorrentProvider.ensureLogin();
    const result = await yggTorrentProvider.fetchAndParseUrl(url, pageLimit);
    const returnValue = await yggTorrentProvider.postProcess(result);
    return returnValue;
  };
  yggTorrentProvider.downloadTorrentBuffer = async torrent => {
    await yggTorrentProvider.ensureLogin();
    return yggTorrentProvider.request(torrent.link, { encoding: null }); // .then(r => r.body); <= not needed in the last release
  };
}

(async () => {
  try {
    const yggTorrentProvider = new YggTorrentProvider();
    yggTorrentProvider.setCredentials('login', 'password');

    yggTorrentProvider.isActive = true;
    yggTorrentProviderOverride(yggTorrentProvider);

    const torrents = await yggTorrentProvider.search({ cat:'', query:'blabla', order: 'seeds'});
    await yggTorrentProvider.downloadTorrent(torrents[0], 'blabla.torrent');
    console.log(torrents);
  } catch (e) {
    console.log(e);
  }
})();

@JimmyLaurent
Copy link
Owner

Fixed in 2.1.1

@exasky
Copy link
Author

exasky commented Mar 14, 2020

Works like a charm !!
Thank you 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants