예제 #1
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     ch = pl.get_channel(2)
     # Success case
     self.assertEqual(ch, test_data.m3u_plus_channel_2)
     # Failure case
     self.assertRaises(IndexOutOfBoundsException, pl.get_channel, pl.length())
예제 #2
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl_string = pl.to_m3u8_playlist()
     pl_m3u8 = m3u8.loads(pl_string)
     pl_m3u8_string = pl_m3u8.dumps()
     # The rstrip() method invocation is needed because the dumps() method of
     # the m3u8 library adds a (redundant?) final newline character that this
     # library doesn't add.
     self.assertEqual(pl_string, pl_m3u8_string.rstrip())
예제 #3
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     self.assertEqual(pl1, pl2)
     # Let's append the same channels twice
     pl2.append_channels(pl1.get_channels())
     self.assertNotEqual(pl1, pl2)
     self.assertEqual(pl1.length()*2, pl2.length())
     self.assertEqual(pl1.get_channels(), pl2.get_channels()[:pl1.length()])
     self.assertEqual(pl1.get_channels(), pl2.get_channels()[pl1.length():])
예제 #4
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     new_pl = pl.copy()
     new_pl.append_channel(
         IPTVChannel(name="mynewchannel", url="mynewurl")
     )
     self.assertEqual(pl.length()+1, new_pl.length())
     current_name: str = new_pl.get_channel(0).name
     new_pl.get_channel(0).name = "my " + current_name
     self.assertNotEqual(pl.get_channel(0).name, new_pl.get_channel(0).name)
예제 #5
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     expected_length = test_data.expected_m3u_plus.length()
     removed_index = 0
     self.assertEqual(expected_length, pl.length())
     channel = pl.remove_channel(removed_index)
     self.assertEqual(test_data.expected_m3u_plus.get_channel(removed_index), channel)
     self.assertEqual(expected_length-1, pl.length())
     # Failure case
     self.assertRaises(IndexOutOfBoundsException, pl.remove_channel, pl.length())
예제 #6
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     self.assertEqual(pl1, pl2)
     # Let's append the same channels twice
     pl2.append_channels(pl1.get_channels())
     self.assertNotEqual(pl1, pl2)
     self.assertEqual(pl1.length()*2, pl2.length())
     self.assertEqual(pl1.get_channels(), pl2.get_channels()[:pl1.length()])
     self.assertEqual(pl1.get_channels(), pl2.get_channels()[pl1.length():])
     # Failure case
     self.assertRaises(IndexOutOfBoundsException, pl2.insert_channels, pl2.length(), pl1.get_channels())
예제 #7
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     self.assertEqual(pl1, pl2)
     new_channel = IPTVChannel(
         url="http://127.0.0.1",
         name="new channel",
         duration="-1"
     )
     pl2.append_channel(new_channel)
     self.assertEqual(new_channel, pl2.get_channel(pl2.length()-1))
     self.assertNotEqual(pl1, pl2)
     self.assertEqual(pl1.length()+1, pl2.length())
예제 #8
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     expected_length = len(test_data.expected_m3u_plus.get_attributes())
     self.assertEqual(expected_length, len(pl.get_attributes()))
     removed_attribute = "x-tvg-url"
     attribute = pl.remove_attribute(removed_attribute)
     self.assertEqual(test_data.expected_m3u_plus.get_attribute(removed_attribute), attribute)
     self.assertEqual(expected_length - 1, len(pl.get_attributes()))
     # Failure case
     self.assertRaises(
         AttributeNotFoundException,
         pl.remove_attribute,
         "non-existing-attribute"
     )
예제 #9
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     self.assertEqual(pl1, pl2)
     updated_attribute = "x-tvg-url"
     new_value = "new-value"
     pl2.update_attribute(updated_attribute, new_value)
     self.assertNotEqual(pl1, pl2)
     self.assertNotEqual(pl1.get_attribute(updated_attribute), pl2.get_attribute(updated_attribute))
     # Failure case
     self.assertRaises(
         AttributeNotFoundException,
         pl2.update_attribute,
         "non-existing-attribute",
         "value"
     )
예제 #10
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     self.assertEqual(pl1, pl2)
     new_channel = IPTVChannel(
         url="http://127.0.0.1",
         name="new channel",
         duration="-1"
     )
     inserted_index = 2
     pl2.insert_channel(inserted_index, new_channel)
     self.assertEqual(new_channel, pl2.get_channel(inserted_index))
     self.assertNotEqual(pl1, pl2)
     self.assertEqual(pl1.length()+1, pl2.length())
     self.assertEqual(pl1.get_channels()[:inserted_index], pl2.get_channels()[:inserted_index])
     self.assertEqual(pl1.get_channels()[inserted_index:], pl2.get_channels()[inserted_index+1:])
     # Failure case
     self.assertRaises(IndexOutOfBoundsException, pl2.insert_channel, pl2.length(), new_channel)
예제 #11
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     name = 'test-attribute'
     value = 'test-value'
     pl2.add_attribute(name, value)
     self.assertNotEqual(pl1, pl2)
     self.assertEqual(pl2.get_attributes()[name], value)
     self.assertEqual(
         len(test_data.expected_m3u_plus.get_attributes()) + 1,
         len(pl2.get_attributes())
     )
     # Failure case
     self.assertRaises(
         AttributeAlreadyPresentException,
         pl2.add_attribute,
         name,
         value
     )
예제 #12
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     empty_group_channel = IPTVChannel(
         url="http://emptygroup.channel/mychannel",
         attributes={
             IPTVAttr.GROUP_TITLE.value: ""
         }
     )
     no_group_channel = IPTVChannel(
         url="http://nogroup.channel/mychannel",
         attributes={
             IPTVAttr.TVG_ID.value: "someid"
         }
     )
     pl.append_channel(empty_group_channel)
     pl.append_channel(no_group_channel)
     groups = pl.group_by_attribute(IPTVAttr.GROUP_TITLE.value, include_no_group=False)
     diff = DeepDiff(groups, test_data.expected_m3u_plus_group_by_group_title, ignore_order=True)
     self.assertEqual(0, len(diff))
예제 #13
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     new_attributes = {
         "attribute_1": "value_1",
         "attribute_2": "value_2"
     }
     pl2.add_attributes(new_attributes)
     self.assertNotEqual(pl1, pl2)
     self.assertEqual(pl2.get_attributes()["attribute_2"], "value_2")
     self.assertEqual(
         len(test_data.expected_m3u_plus.get_attributes()) + len(new_attributes),
         len(pl2.get_attributes())
     )
     # Failure case
     self.assertRaises(
         AttributeAlreadyPresentException,
         pl2.add_attribute,
         "attribute_2",
         "value_2"
     )
예제 #14
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     first_empty_url_channel = IPTVChannel(
         url="",
         attributes={
             IPTVAttr.GROUP_TITLE.value: "first"
         }
     )
     second_empty_url_channel = IPTVChannel(
         url="",
         attributes={
             IPTVAttr.GROUP_TITLE.value: "second"
         }
     )
     pl.append_channel(first_empty_url_channel)
     pl.append_channel(second_empty_url_channel)
     groups = pl.group_by_url(include_no_group=True)
     expected_groups = test_data.expected_m3u_plus_group_by_url.copy()
     expected_groups[M3UPlaylist.NO_URL_KEY] = [4, 5]
     diff = DeepDiff(groups, expected_groups, ignore_order=True)
     self.assertEqual(0, len(diff))
예제 #15
0
 def runTest(self):
     pl1 = playlist.loadf("tests/resources/m3u_plus.m3u")
     pl2 = pl1.copy()
     self.assertEqual(pl1, pl2)
     updated_index = 3
     new_channel = IPTVChannel(
         url="http://127.0.0.1",
         name="new channel",
         duration="-1"
     )
     pl2.update_channel(updated_index, new_channel)
     self.assertNotEqual(pl1, pl2)
     for i, ch in enumerate(pl1):
         if i == updated_index:
             self.assertNotEqual(ch, pl2.get_channel(i))
         else:
             self.assertEqual(ch, pl2.get_channel(i))
     # Failure case
     self.assertRaises(
         IndexOutOfBoundsException,
         pl2.update_channel,
         pl2.length(),
         new_channel
     )
예제 #16
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus_unencoded_logo.m3u")
     self.assertNotEqual(test_data.expected_urlencoded, pl)
     fixed_pl = M3UPlaylistDoctor.sanitize(pl)
     self.assertEqual(test_data.expected_urlencoded, fixed_pl)
예제 #17
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     name = "x-tvg-url"
     value = pl.get_attribute(name)
     self.assertEqual(test_data.expected_m3u_plus.get_attributes()[name], value)
예제 #18
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     with open("tests/resources/m3u_plus.m3u") as file:
         expected_content = "".join(file.readlines())
         content = pl.to_m3u_plus_playlist()
         self.assertEqual(expected_content, content, "The two playlists are not equal")
예제 #19
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     groups = pl.group_by_attribute(IPTVAttr.GROUP_TITLE.value)
     diff = DeepDiff(groups, test_data.expected_m3u_plus_group_by_group_title, ignore_order=True)
     self.assertEqual(0, len(diff))
예제 #20
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u8.m3u")
     self.assertEqual(test_data.expected_m3u8, pl, "The two playlists are not equal")
예제 #21
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     groups = pl.group_by_url(include_no_group=False)
     diff = DeepDiff(groups, test_data.expected_m3u_plus_group_by_url, ignore_order=True)
     self.assertEqual(0, len(diff))
예제 #22
0
 def runTest(self):
     pl = playlist.loadf("tests/resources/m3u_plus.m3u")
     for i, ch in enumerate(pl):
         self.assertEqual(test_data.expected_m3u_plus.get_channel(i), ch)
     self.assertEqual(i+1, test_data.expected_m3u_plus.length())