Explorar o código

Avoid potentially undefined values

Zachary Kotlarek %!s(int64=12) %!d(string=hai) anos
pai
achega
5cb068c228
Modificáronse 1 ficheiros con 26 adicións e 12 borrados
  1. 26 12
      yt/subscribe.pl

+ 26 - 12
yt/subscribe.pl

@@ -293,29 +293,43 @@ sub buildNFO($) {
 	$elm->appendText($video->{'number'});
 	$elm->appendText($video->{'number'});
 	$show->appendChild($elm);
 	$show->appendChild($elm);
 
 
+	if (!defined($video->{'title'})) {
+		$video->{'title'} = 'Episode ' . $video->{'number'};
+	}
 	$elm = $doc->createElement('title');
 	$elm = $doc->createElement('title');
 	$elm->appendText($video->{'title'});
 	$elm->appendText($video->{'title'});
 	$show->appendChild($elm);
 	$show->appendChild($elm);
 
 
+	if (!defined($video->{'date'})) {
+		$video->{'date'} = time();
+	}
 	$elm = $doc->createElement('aired');
 	$elm = $doc->createElement('aired');
 	$elm->appendText(time2str('%Y-%m-%d', $video->{'date'}));
 	$elm->appendText(time2str('%Y-%m-%d', $video->{'date'}));
 	$show->appendChild($elm);
 	$show->appendChild($elm);
 
 
-	$elm = $doc->createElement('plot');
-	$elm->appendText($video->{'description'});
-	$show->appendChild($elm);
+	if (defined($video->{'description'})) {
+		$elm = $doc->createElement('plot');
+		$elm->appendText($video->{'description'});
+		$show->appendChild($elm);
+	}
 
 
-	$elm = $doc->createElement('runtime');
-	$elm->appendText($video->{'duration'});
-	$show->appendChild($elm);
+	if (defined($video->{'duration'})) {
+		$elm = $doc->createElement('runtime');
+		$elm->appendText($video->{'duration'});
+		$show->appendChild($elm);
+	}
 
 
-	$elm = $doc->createElement('rating');
-	$elm->appendText($video->{'rating'});
-	$show->appendChild($elm);
+	if (defined($video->{'rating'})) {
+		$elm = $doc->createElement('rating');
+		$elm->appendText($video->{'rating'});
+		$show->appendChild($elm);
+	}
 
 
-	$elm = $doc->createElement('director');
-	$elm->appendText($video->{'creator'});
-	$show->appendChild($elm);
+	if (defined($video->{'creator'})) {
+		$elm = $doc->createElement('director');
+		$elm->appendText($video->{'creator'});
+		$show->appendChild($elm);
+	}
 
 
 	# Return the string
 	# Return the string
 	return $doc->toString();
 	return $doc->toString();