PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/subtitles/addic7ed.php

http://mytvondemand.googlecode.com/
PHP | 50 lines | 46 code | 2 blank | 2 comment | 3 complexity | 3c5629d25b87ad1b5bd2c2d396351f0f MD5 | raw file
 1<?php
 2	function fetchSubtitles($showtitle, $season, $episode, $language) {
 3		$englang = array(	it => 'Italian',
 4							en => 'English',
 5							es => 'Spanish',
 6							ro => 'Romanian',
 7							pt => 'Portuguese',
 8							fr => 'French',
 9							hu => 'Hungarian',
10							ru => 'Russian',
11							de => 'German',
12							sw => 'Swedish',
13							dk => 'Dutch');
14		
15		/* Gathering TV Series Names */
16		$data = file_get_contents("http://www.addic7ed.com/shows.php");
17		preg_match_all("/\"Letter1\">(.*)/", $data, $matches);
18		$series = $matches[1][0];
19		preg_match_all('/href="([0-z\/]*)">(.*?)<\/a>/', $series, $matches);
20		$links = $matches[1];
21		$names = $matches[2];
22		unset($matches); unset($data); unset($series);
23		for($i=0; $i<=count($links); $i++)
24			$series[strtolower($names[$i])] = $links[$i];
25		unset($names); unset($links); 
26
27		/* Gathering Episodes */
28		if ($series[strtolower($showtitle)] == Null)
29			return Null;
30		preg_match_all("/\/show\/(.*)/", $series[strtolower($showtitle)], $matches);
31		$link = $matches[1][0];
32		$data = str_replace("\n","",file_get_contents("http://www.addic7ed.com/ajax_loadShow.php?show=$link&season=$season"));
33		preg_match_all("/ - [0-9]*x[0]*$episode.*?".$englang[$language].".*?>([0-9\.\% ]*)?Completed.*?(\/updated.*?)\".*?<\/table>/", $data, $matches);
34		$sublink = $matches[2][0];
35		$completed = $matches[1][0];
36		unset($link); unset($matches); unset($data);
37		
38		/* Subtitle download */
39		if (($sublink == Null) || ($completed != ''))
40			return Null;
41		$subtitle = file_get_contents("http://www.addic7ed.com".$sublink);
42		if (strrpos($subtitle, "Daily Download count exceeded") === false) {
43			if ($subtitle != Null)
44				return $subtitle;
45			else
46				return Null;
47		} else
48			return null;
49	}
50?>