forked from Tviso/chrome-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimdb.js
More file actions
83 lines (66 loc) · 2.14 KB
/
Copy pathimdb.js
File metadata and controls
83 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* global $ */
/* global document */
module.exports = function() {
var getMediaType = function() {
if (typeof($) !== 'undefined') {
var aux;
aux = $('.infobar').text();
if (aux.match(/TV Series/)) {
return 'SERIE';
} else if (aux.match(/TV Episode/)) {
return 'EPISODE';
} else {
return 'MOVIE';
}
}
return false;
};
var getMediaInfo = function(mediaType) {
var media = {
mediaType: mediaType,
title: null,
imdb: null,
year: null,
cast: [],
directors: [],
season: null,
episode: null,
},
aux = null;
if (typeof($) !== 'undefined') {
//TITLE
media.title = $('span[itemprop="name"]:first').text();
//YEAR
media.year = parseInt($('.header:first').find('span.nobr a').text());
//CAST
$('div[itemprop="actors"] span[itemprop="name"]').each(function(k,v) {
media.cast.push($(v).text());
});
//DIRECTOR
$('div[itemprop="director"] span[itemprop="name"]').each(function(k,v) {
media.directors.push($(v).text());
});
//IMDB
aux = document.location.href.match(/\/title\/(tt\d{7})/);
media.imdb = aux[1];
//IF IS EPISODE
if (mediaType === 'EPISODE') {
aux = $('.tv_header').find('.nobr').text().match(/\s(\d+),.*\s(\d+)/); //Example: Season 3, Episode 1
media.season = parseInt(aux[1]);
media.episode = parseInt(aux[2]);
media.title = $('.tv_header a:first').text();
}
}
return media;
};
var checkSelectors = {
'#overview-bottom .wlb_classic_wrapper .btn2_text:first': 'pending',
};
return {
name: 'imdb',
url: 'imdb\.com\/',
getMediaInfo: getMediaInfo,
getMediaType: getMediaType,
checkSelectors: checkSelectors
};
};