feat(rutracker): category and torrent name from rutracker

This commit is contained in:
Alexey Kasyanchuk
2018-08-17 08:42:25 +03:00
parent 14a109d5d7
commit 466d10ccd5
3 changed files with 19 additions and 7 deletions

View File

@ -22,11 +22,13 @@ import TrackersImages from './trackers-images'
let parseDescriptionText = (text) => { let parseDescriptionText = (text) => {
return text.split("\n").map(function(item) { return text.split("\n").map(function(item) {
const text = /([A-Za-zА-Яа-я]+:) (.+)/.exec(item) const text = /(.+?:)(.*)/.exec(item)
return ( return (
<span> <span>
{text ? <span><b>{`${text[1]} `}</b>{text[2]}</span> : item} {
text ? <span><b>{`${text[1]} `}</b>{text[2]}</span> : item
}
<br/> <br/>
</span> </span>
) )
@ -106,7 +108,7 @@ const TorrentInformation = (props) => {
//leftAvatar={<Avatar icon={<ActionAssignment />} backgroundColor={blue500} />} //leftAvatar={<Avatar icon={<ActionAssignment />} backgroundColor={blue500} />}
rightIcon={<ActionInfo />} rightIcon={<ActionInfo />}
primaryText={__('Torrent Name')} primaryText={__('Torrent Name')}
secondaryText={<span className='break-word' style={{whiteSpace: 'normal'}}>{torrent.name}</span>} secondaryText={<span className='break-word' style={{whiteSpace: 'normal'}}>{(torrent.info && torrent.info.name) || torrent.name}</span>}
/> />
<ListItem <ListItem
// leftAvatar={<Avatar icon={<EditorInsertChart />} backgroundColor={yellow600} />} // leftAvatar={<Avatar icon={<EditorInsertChart />} backgroundColor={yellow600} />}
@ -144,7 +146,7 @@ const TorrentInformation = (props) => {
// leftAvatar={<Avatar icon={<EditorInsertChart />} backgroundColor={yellow600} />} // leftAvatar={<Avatar icon={<EditorInsertChart />} backgroundColor={yellow600} />}
rightIcon={<ActionInfo />} rightIcon={<ActionInfo />}
primaryText={__('Category')} primaryText={__('Category')}
secondaryText={torrent.contentCategory || 'unknown'} secondaryText={(torrent.info && torrent.info.contentCategory) || torrent.contentCategory || 'unknown'}
/> />
</List> </List>
); );
@ -202,9 +204,9 @@ export default class TorrentPage extends Page {
//this.forceUpdate(); // вызывается через searchingIndicator //this.forceUpdate(); // вызывается через searchingIndicator
// Получаем более новую статистику пира // Получаем более новую статистику пира
if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) { if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) {
window.torrentSocket.emit('checkTrackers', this.torrent.hash); window.torrentSocket.emit('checkTrackers', this.torrent.hash);
} }
} }
}, () => { }, () => {
this.setState({ this.setState({

View File

@ -23,15 +23,24 @@ module.exports = class Rutracker
if(!html) if(!html)
return return
html = await html.textConverted() html = await html.textConverted()
html = html.replace(/\<span class\="post-br"\>/g, '\n<span class="post-br">')
html = html.replace(/\><span class\="post-b"\>/g, '>\n<span class="post-b">')
const $ = cheerio.load(html) const $ = cheerio.load(html)
const topicTitle = $('#topic-title').text() const topicTitle = $('#topic-title').text()
if(!topicTitle) if(!topicTitle)
return return
let contentCategory;
try {
contentCategory = $('.vBottom .nav').text().replace(/[\t]+/g, '').replace(/[\n]+/g, ' ').trim()
} catch(er) {}
return { return {
name: topicTitle, name: topicTitle,
poster: $('.post_body .postImgAligned').attr('title'), poster: $('.post_body .postImgAligned').attr('title') || $('.post_body .postImg').attr('title'),
description: $('.post_body').first().text(), description: $('.post_body').first().text(),
rutrackerThreadId: parseInt($('a.magnet-link').attr('data-topic_id')), rutrackerThreadId: parseInt($('a.magnet-link').attr('data-topic_id')),
contentCategory
} }
} }
} }

View File

@ -21,5 +21,6 @@ describe("rutracker", () => {
assert.equal(data.poster, 'http://i44.fastpic.ru/big/2012/1018/a2/4e8740f608387b32b74c5deea72d05a2.jpg') assert.equal(data.poster, 'http://i44.fastpic.ru/big/2012/1018/a2/4e8740f608387b32b74c5deea72d05a2.jpg')
assert.equal(data.rutrackerThreadId, 4220109) assert.equal(data.rutrackerThreadId, 4220109)
assert(data.description.includes('выхода')) assert(data.description.includes('выхода'))
assert.equal(data.contentCategory, 'Главная » Рок-музыка » Зарубежный Metal » Death, Doom (lossy)')
}) })
}); });