Mercurial > audlegacy
comparison src/audacious/playlist.c @ 3971:b0ae5dbd2f53
- add subtune support to on demand probing.
- add new boolean member "have_subtune" to InputPlugin structure. plugins which support subtune shall set this.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sun, 18 Nov 2007 21:39:28 +0900 |
parents | efd7ec36483e |
children | 67f01143e613 |
comparison
equal
deleted
inserted
replaced
3967:efd7ec36483e | 3971:b0ae5dbd2f53 |
---|---|
143 | 143 |
144 static void playlist_recalc_total_time_nolock(Playlist *); | 144 static void playlist_recalc_total_time_nolock(Playlist *); |
145 static void playlist_recalc_total_time(Playlist *); | 145 static void playlist_recalc_total_time(Playlist *); |
146 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | 146 static gboolean playlist_entry_get_info(PlaylistEntry * entry); |
147 | 147 |
148 static gboolean filter_by_extension(const gchar *filename); | 148 |
149 #define EXT_TRUE 1 | |
150 #define EXT_FALSE 0 | |
151 #define EXT_HAVE_SUBTUNE 2 | |
152 | |
153 static gint filter_by_extension(const gchar *filename); | |
154 static gboolean is_http(const gchar *filename); | |
149 | 155 |
150 static mowgli_heap_t *playlist_entry_heap = NULL; | 156 static mowgli_heap_t *playlist_entry_heap = NULL; |
151 | 157 |
152 /* *********************** playlist entry code ********************** */ | 158 /* *********************** playlist entry code ********************** */ |
153 | 159 |
771 gint r; | 777 gint r; |
772 VFSFile *file; | 778 VFSFile *file; |
773 ProbeResult *pr = NULL; | 779 ProbeResult *pr = NULL; |
774 InputPlugin *dec = NULL; | 780 InputPlugin *dec = NULL; |
775 Tuple *tuple = NULL; | 781 Tuple *tuple = NULL; |
782 gint ext_flag; | |
783 gboolean http_flag; | |
776 | 784 |
777 g_return_val_if_fail(playlist != NULL, FALSE); | 785 g_return_val_if_fail(playlist != NULL, FALSE); |
778 g_return_val_if_fail(filename != NULL, FALSE); | 786 g_return_val_if_fail(filename != NULL, FALSE); |
779 | 787 |
780 /* load playlist */ | 788 /* load playlist */ |
783 playlist_load_ins(playlist, filename, pos); | 791 playlist_load_ins(playlist, filename, pos); |
784 playlist->loading_playlist = FALSE; | 792 playlist->loading_playlist = FALSE; |
785 return TRUE; | 793 return TRUE; |
786 } | 794 } |
787 | 795 |
796 ext_flag = filter_by_extension(filename); | |
797 http_flag = is_http(filename); | |
798 | |
788 /* playlist file or remote uri */ | 799 /* playlist file or remote uri */ |
789 if (playlist->loading_playlist == TRUE || | 800 if (playlist->loading_playlist == TRUE || http_flag == TRUE) { |
790 str_has_prefix_nocase(filename, "http://") || | |
791 str_has_prefix_nocase(filename, "https://")) { | |
792 dec = NULL; | 801 dec = NULL; |
793 } | 802 } |
794 | 803 |
795 /* local file and on-demand probing is on */ | 804 /* local file and on-demand probing is on */ |
796 else if (cfg.playlist_detect == TRUE) { | 805 else if (cfg.playlist_detect == TRUE && ext_flag != EXT_HAVE_SUBTUNE) { |
797 dec = NULL; | 806 dec = NULL; |
798 if(cfg.use_extension_probing && !filter_by_extension(filename)) | 807 if(cfg.use_extension_probing && ext_flag == EXT_FALSE) |
799 return FALSE; | 808 return FALSE; |
800 } | 809 } |
801 | 810 |
802 /* find decorder for local file */ | 811 /* find decorder for local file */ |
803 else { | 812 else { |
812 | 821 |
813 /* add filename to playlist */ | 822 /* add filename to playlist */ |
814 if (cfg.playlist_detect == TRUE || | 823 if (cfg.playlist_detect == TRUE || |
815 playlist->loading_playlist == TRUE || | 824 playlist->loading_playlist == TRUE || |
816 (playlist->loading_playlist == FALSE && dec != NULL) || | 825 (playlist->loading_playlist == FALSE && dec != NULL) || |
817 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && | 826 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && http_flag) ) { |
818 str_has_prefix_nocase(filename, "http"))) { | |
819 | 827 |
820 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | 828 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); |
821 | 829 |
822 playlist_generate_shuffle_list(playlist); | 830 playlist_generate_shuffle_list(playlist); |
823 playlistwin_update_list(playlist); | 831 playlistwin_update_list(playlist); |
959 if (!(dir = g_dir_open(path, 0, NULL))) | 967 if (!(dir = g_dir_open(path, 0, NULL))) |
960 return NULL; | 968 return NULL; |
961 | 969 |
962 while ((dir_entry = g_dir_read_name(dir))) { | 970 while ((dir_entry = g_dir_read_name(dir))) { |
963 gchar *filename, *tmp; | 971 gchar *filename, *tmp; |
972 gint ext_flag; | |
973 gboolean http_flag; | |
964 | 974 |
965 if (file_is_hidden(dir_entry)) | 975 if (file_is_hidden(dir_entry)) |
966 continue; | 976 continue; |
967 | 977 |
968 tmp = g_build_filename(path, dir_entry, NULL); | 978 tmp = g_build_filename(path, dir_entry, NULL); |
969 filename = g_filename_to_uri(tmp, NULL, NULL); | 979 filename = g_filename_to_uri(tmp, NULL, NULL); |
970 g_free(tmp); | 980 g_free(tmp); |
981 | |
982 ext_flag = filter_by_extension(filename); | |
983 http_flag = is_http(filename); | |
971 | 984 |
972 if (vfs_file_test(filename, G_FILE_TEST_IS_DIR)) { /* directory */ | 985 if (vfs_file_test(filename, G_FILE_TEST_IS_DIR)) { /* directory */ |
973 GList *sub; | 986 GList *sub; |
974 gchar *dirfilename = g_filename_from_uri(filename, NULL, NULL); | 987 gchar *dirfilename = g_filename_from_uri(filename, NULL, NULL); |
975 sub = playlist_dir_find_files(dirfilename, background, htab); | 988 sub = playlist_dir_find_files(dirfilename, background, htab); |
976 g_free(dirfilename); | 989 g_free(dirfilename); |
977 g_free(filename); | 990 g_free(filename); |
978 list = g_list_concat(list, sub); | 991 list = g_list_concat(list, sub); |
979 } | 992 } |
980 else if (cfg.playlist_detect) { /* local file, no probing */ | 993 else if (cfg.playlist_detect && ext_flag != EXT_HAVE_SUBTUNE) { /* local file, no probing, no subtune */ |
981 if(cfg.use_extension_probing) { | 994 if(cfg.use_extension_probing) { |
982 if(filter_by_extension(filename)) | 995 if(ext_flag == EXT_TRUE) |
983 list = g_list_prepend(list, filename); | 996 list = g_list_prepend(list, filename); |
984 } | 997 } |
985 else | 998 else |
986 list = g_list_prepend(list, filename); | 999 list = g_list_prepend(list, filename); |
987 } | 1000 } |
988 else if ((pr = input_check_file(filename, TRUE)) != NULL) /* local file, probing*/ | 1001 else if ((pr = input_check_file(filename, TRUE)) != NULL) /* local file, probing or have subtune */ |
989 { | 1002 { |
990 list = g_list_prepend(list, filename); | 1003 list = g_list_prepend(list, filename); |
991 | 1004 |
992 g_free(pr); | 1005 g_free(pr); |
993 pr = NULL; | 1006 pr = NULL; |
1739 path = g_strdup(playlist_name); | 1752 path = g_strdup(playlist_name); |
1740 | 1753 |
1741 if ((tmp = strrchr(path, '/'))) | 1754 if ((tmp = strrchr(path, '/'))) |
1742 *tmp = '\0'; | 1755 *tmp = '\0'; |
1743 else { | 1756 else { |
1757 gint ext_flag = filter_by_extension(filename); | |
1758 gboolean http_flag = is_http(filename); | |
1759 | |
1744 /* playlist file or remote uri */ | 1760 /* playlist file or remote uri */ |
1745 if (playlist->loading_playlist == TRUE || | 1761 if (playlist->loading_playlist == TRUE || http_flag == TRUE) { |
1746 str_has_prefix_nocase(filename, "http://") || | |
1747 str_has_prefix_nocase(filename, "https://")) { | |
1748 pr = NULL; | 1762 pr = NULL; |
1749 } | 1763 } |
1750 /* local file and on-demand probing is on */ | 1764 /* local file and on-demand probing is on */ |
1751 else if (cfg.playlist_detect == TRUE) { | 1765 else if (cfg.playlist_detect == TRUE && ext_flag != EXT_HAVE_SUBTUNE) { |
1752 pr = NULL; | 1766 pr = NULL; |
1753 if(cfg.use_extension_probing && !filter_by_extension(filename)) | 1767 if(cfg.use_extension_probing && ext_flag == EXT_FALSE) |
1754 return; | 1768 return; |
1755 } | 1769 } |
1756 /* find decorder for local file */ | 1770 /* find decorder for local file */ |
1757 else { | 1771 else { |
1758 pr = input_check_file(filename, TRUE); | 1772 pr = input_check_file(filename, TRUE); |
1759 } | 1773 } |
1774 | |
1760 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); | 1775 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
1761 g_free(pr); | 1776 g_free(pr); |
1762 return; | 1777 return; |
1763 } | 1778 } |
1764 | 1779 |
1765 tmp = g_build_filename(path, filename, NULL); | 1780 tmp = g_build_filename(path, filename, NULL); |
1781 gint ext_flag = filter_by_extension(tmp); | |
1782 gboolean http_flag = is_http(tmp); | |
1766 | 1783 |
1767 /* playlist file or remote uri */ | 1784 /* playlist file or remote uri */ |
1768 if (playlist->loading_playlist == TRUE || | 1785 if (playlist->loading_playlist == TRUE || http_flag == TRUE) { |
1769 str_has_prefix_nocase(tmp, "http://") || | |
1770 str_has_prefix_nocase(tmp, "https://")) { | |
1771 pr = NULL; | 1786 pr = NULL; |
1772 } | 1787 } |
1773 /* local file and on-demand probing is on */ | 1788 /* local file and no probing, no subtune */ |
1774 else if (cfg.playlist_detect == TRUE) { | 1789 else if (cfg.playlist_detect == TRUE && ext_flag != EXT_HAVE_SUBTUNE) { |
1775 pr = NULL; | 1790 pr = NULL; |
1776 if(cfg.use_extension_probing && !filter_by_extension(filename)) | 1791 if(cfg.use_extension_probing && ext_flag == EXT_FALSE) |
1777 return; | 1792 return; |
1778 } | 1793 } |
1779 /* find decoder for local file */ | 1794 /* find decoder for local file */ |
1780 else { | 1795 else { |
1781 pr = input_check_file(tmp, TRUE); | 1796 pr = input_check_file(tmp, TRUE); |
1784 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); | 1799 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
1785 g_free(tmp); | 1800 g_free(tmp); |
1786 g_free(path); | 1801 g_free(path); |
1787 g_free(pr); | 1802 g_free(pr); |
1788 } | 1803 } |
1789 else | 1804 else { |
1790 { | 1805 gint ext_flag = filter_by_extension(filename); |
1806 gboolean http_flag = is_http(filename); | |
1807 | |
1791 /* playlist file or remote uri */ | 1808 /* playlist file or remote uri */ |
1792 if (playlist->loading_playlist == TRUE || | 1809 if (playlist->loading_playlist == TRUE || http_flag == TRUE) { |
1793 str_has_prefix_nocase(filename, "http://") || | |
1794 str_has_prefix_nocase(filename, "https://")) { | |
1795 pr = NULL; | 1810 pr = NULL; |
1796 } | 1811 } |
1797 /* local file and on-demand probing is on */ | 1812 /* local file and on-demand probing is on */ |
1798 else if (cfg.playlist_detect == TRUE) { | 1813 else if (cfg.playlist_detect == TRUE && ext_flag != EXT_HAVE_SUBTUNE) { |
1799 pr = NULL; | 1814 pr = NULL; |
1800 if(cfg.use_extension_probing && !filter_by_extension(filename)) | 1815 if(cfg.use_extension_probing && ext_flag == EXT_FALSE) |
1801 return; | 1816 return; |
1802 } | 1817 } |
1803 /* find decoder for local file */ | 1818 /* find decoder for local file */ |
1804 else { | 1819 else { |
1805 pr = input_check_file(filename, TRUE); | 1820 pr = input_check_file(filename, TRUE); |
1808 g_free(pr); | 1823 g_free(pr); |
1809 } | 1824 } |
1810 | 1825 |
1811 g_free(filename); | 1826 g_free(filename); |
1812 } | 1827 } |
1828 | |
1813 | 1829 |
1814 void | 1830 void |
1815 playlist_load_ins_file_tuple(Playlist * playlist, | 1831 playlist_load_ins_file_tuple(Playlist * playlist, |
1816 const gchar * filename_p, | 1832 const gchar * filename_p, |
1817 const gchar * playlist_name, | 1833 const gchar * playlist_name, |
1835 if (filename[0] != '/' && !strstr(filename, "://")) { | 1851 if (filename[0] != '/' && !strstr(filename, "://")) { |
1836 path = g_strdup(playlist_name); | 1852 path = g_strdup(playlist_name); |
1837 if ((tmp = strrchr(path, '/'))) | 1853 if ((tmp = strrchr(path, '/'))) |
1838 *tmp = '\0'; | 1854 *tmp = '\0'; |
1839 else { | 1855 else { |
1840 if (playlist->loading_playlist == TRUE || | 1856 gint ext_flag = filter_by_extension(filename); |
1841 str_has_prefix_nocase(filename, "http://") || | 1857 gboolean http_flag = is_http(filename); |
1842 str_has_prefix_nocase(filename, "https://")) { | 1858 |
1859 if (playlist->loading_playlist == TRUE || http_flag == TRUE) { | |
1843 pr = NULL; | 1860 pr = NULL; |
1844 } | 1861 } |
1845 else if (cfg.playlist_detect == TRUE) { | 1862 else if (cfg.playlist_detect == TRUE && ext_flag != EXT_HAVE_SUBTUNE) { |
1846 pr = NULL; | 1863 pr = NULL; |
1847 if(cfg.use_extension_probing && !filter_by_extension(filename)) | 1864 if(cfg.use_extension_probing && ext_flag == EXT_FALSE) |
1848 return; | 1865 return; |
1849 } | 1866 } |
1850 else { | 1867 else { |
1851 pr = input_check_file(filename, TRUE); | 1868 pr = input_check_file(filename, TRUE); |
1852 } | 1869 } |
1855 g_free(pr); | 1872 g_free(pr); |
1856 return; | 1873 return; |
1857 } | 1874 } |
1858 | 1875 |
1859 tmp = g_build_filename(path, filename, NULL); | 1876 tmp = g_build_filename(path, filename, NULL); |
1860 | 1877 gint ext_flag = filter_by_extension(tmp); |
1861 if (playlist->loading_playlist == TRUE || | 1878 gboolean http_flag = is_http(tmp); |
1862 str_has_prefix_nocase(filename, "http://") || | 1879 |
1863 str_has_prefix_nocase(filename, "https://")) { | 1880 if (playlist->loading_playlist == TRUE || http_flag == TRUE) { |
1864 pr = NULL; | 1881 pr = NULL; |
1865 } | 1882 } |
1866 else if (cfg.playlist_detect == TRUE) { | 1883 else if (cfg.playlist_detect == TRUE && ext_flag != EXT_HAVE_SUBTUNE) { |
1867 pr = NULL; | 1884 pr = NULL; |
1868 if(cfg.use_extension_probing && !filter_by_extension(filename)) | 1885 if(cfg.use_extension_probing && ext_flag == EXT_FALSE) |
1869 return; | 1886 return; |
1870 } | 1887 } |
1871 else { | 1888 else { |
1872 pr = input_check_file(filename, TRUE); | 1889 pr = input_check_file(filename, TRUE); |
1873 } | 1890 } |
1875 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); | 1892 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
1876 g_free(tmp); | 1893 g_free(tmp); |
1877 g_free(path); | 1894 g_free(path); |
1878 g_free(pr); | 1895 g_free(pr); |
1879 } | 1896 } |
1880 else | 1897 else { |
1881 { | |
1882 if (playlist->loading_playlist == TRUE || | 1898 if (playlist->loading_playlist == TRUE || |
1883 str_has_prefix_nocase(filename, "http://") || | 1899 str_has_prefix_nocase(filename, "http://") || |
1884 str_has_prefix_nocase(filename, "https://")) { | 1900 str_has_prefix_nocase(filename, "https://")) { |
1885 pr = NULL; | 1901 pr = NULL; |
1886 } | 1902 } |
3491 l2 = l2->next; | 3507 l2 = l2->next; |
3492 } while(1); | 3508 } while(1); |
3493 return TRUE; | 3509 return TRUE; |
3494 } | 3510 } |
3495 | 3511 |
3496 static gboolean | 3512 static gint |
3497 filter_by_extension(const gchar *uri) | 3513 filter_by_extension(const gchar *uri) |
3498 { | 3514 { |
3499 gchar *base, *ext, *lext, *filename; | 3515 gchar *base, *ext, *lext, *filename; |
3500 gchar *tmp = g_filename_from_uri(uri, NULL, NULL); | 3516 gchar *tmp = g_filename_from_uri(uri, NULL, NULL); |
3501 gboolean rv; | 3517 gint rv; |
3518 GList **lhandle, *node; | |
3519 InputPlugin *ip; | |
3502 | 3520 |
3503 filename = g_strdup(tmp ? tmp : uri); | 3521 filename = g_strdup(tmp ? tmp : uri); |
3504 g_free(tmp); | 3522 g_free(tmp); |
3505 | 3523 |
3506 base = g_path_get_basename(filename); | 3524 base = g_path_get_basename(filename); |
3507 ext = strrchr(base, '.'); | 3525 ext = strrchr(base, '.'); |
3508 | 3526 |
3509 if(!ext) { | 3527 if(!ext) { |
3510 g_free(base); | 3528 g_free(base); |
3511 return FALSE; | 3529 return 0; |
3512 } | 3530 } |
3513 | 3531 |
3514 lext = g_ascii_strdown(ext+1, -1); | 3532 lext = g_ascii_strdown(ext+1, -1); |
3515 g_free(base); | 3533 g_free(base); |
3516 | 3534 |
3517 if(g_hash_table_lookup(ext_hash, lext)) | 3535 lhandle = g_hash_table_lookup(ext_hash, lext); |
3536 g_free(lext); | |
3537 | |
3538 if(!lhandle) { | |
3539 return EXT_FALSE; | |
3540 } | |
3541 | |
3542 for(node = *lhandle; node; node = g_list_next(node)) { | |
3543 ip = (InputPlugin *)node->data; | |
3544 | |
3545 if(ip->have_subtune == TRUE) { | |
3546 return EXT_HAVE_SUBTUNE; | |
3547 } | |
3548 else | |
3549 rv = EXT_TRUE; | |
3550 } | |
3551 | |
3552 return rv; | |
3553 } | |
3554 | |
3555 static gboolean | |
3556 is_http(const gchar *uri) | |
3557 { | |
3558 gboolean rv = FALSE; | |
3559 | |
3560 if(str_has_prefix_nocase(uri, "http://") || | |
3561 str_has_prefix_nocase(uri, "https://")) { | |
3518 rv = TRUE; | 3562 rv = TRUE; |
3519 else | 3563 } |
3520 rv = FALSE; | 3564 |
3521 | |
3522 g_free(lext); | |
3523 return rv; | 3565 return rv; |
3524 } | 3566 } |