Mercurial > audlegacy
comparison src/audacious/playlist.c @ 3934:e924c9ee3958
when "Detect file formats on demand" is specified, filter unplayable files on loading by the hash table of all available extensions.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 15 Nov 2007 16:34:09 +0900 |
parents | e9fd46b0893b |
children | 0b93c2b0cd59 |
comparison
equal
deleted
inserted
replaced
3933:5a4ef76b1f42 | 3934:e924c9ee3958 |
---|---|
108 static gboolean playlist_get_info_scan_active = FALSE; | 108 static gboolean playlist_get_info_scan_active = FALSE; |
109 GStaticRWLock playlist_get_info_rwlock = G_STATIC_RW_LOCK_INIT; | 109 GStaticRWLock playlist_get_info_rwlock = G_STATIC_RW_LOCK_INIT; |
110 static gboolean playlist_get_info_going = FALSE; | 110 static gboolean playlist_get_info_going = FALSE; |
111 static GThread *playlist_get_info_thread; | 111 static GThread *playlist_get_info_thread; |
112 | 112 |
113 extern GHashTable *ext_hash; | |
114 | |
113 static gint path_compare(const gchar * a, const gchar * b); | 115 static gint path_compare(const gchar * a, const gchar * b); |
114 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); | 116 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); |
115 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | 117 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); |
116 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | 118 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); |
117 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | 119 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); |
140 static void playlist_generate_shuffle_list_nolock(Playlist *); | 142 static void playlist_generate_shuffle_list_nolock(Playlist *); |
141 | 143 |
142 static void playlist_recalc_total_time_nolock(Playlist *); | 144 static void playlist_recalc_total_time_nolock(Playlist *); |
143 static void playlist_recalc_total_time(Playlist *); | 145 static void playlist_recalc_total_time(Playlist *); |
144 static gboolean playlist_entry_get_info(PlaylistEntry * entry); | 146 static gboolean playlist_entry_get_info(PlaylistEntry * entry); |
147 | |
148 static gboolean filter_by_extension(const gchar *filename); | |
145 | 149 |
146 static mowgli_heap_t *playlist_entry_heap = NULL; | 150 static mowgli_heap_t *playlist_entry_heap = NULL; |
147 | 151 |
148 /* *********************** playlist entry code ********************** */ | 152 /* *********************** playlist entry code ********************** */ |
149 | 153 |
748 } | 752 } |
749 | 753 |
750 if (parent_tuple) | 754 if (parent_tuple) |
751 tuple_free(parent_tuple); | 755 tuple_free(parent_tuple); |
752 | 756 |
753 if (tuple != NULL && tuple_get_int(tuple, FIELD_MTIME, NULL) == -1) { | 757 if (!tuple || (tuple && tuple_get_int(tuple, FIELD_MTIME, NULL) == -1)) { |
754 // kick the scanner thread only if mtime = -1 (uninitialized) | 758 // kick the scanner thread when tuple == NULL or mtime = -1 (uninitialized) |
755 g_mutex_lock(mutex_scan); | 759 g_mutex_lock(mutex_scan); |
756 playlist_get_info_scan_active = TRUE; | 760 playlist_get_info_scan_active = TRUE; |
757 g_mutex_unlock(mutex_scan); | 761 g_mutex_unlock(mutex_scan); |
758 g_cond_signal(cond_scan); | 762 g_cond_signal(cond_scan); |
759 } | 763 } |
778 playlist_load_ins(playlist, filename, pos); | 782 playlist_load_ins(playlist, filename, pos); |
779 playlist->loading_playlist = FALSE; | 783 playlist->loading_playlist = FALSE; |
780 return TRUE; | 784 return TRUE; |
781 } | 785 } |
782 | 786 |
783 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) | 787 if (playlist->loading_playlist == TRUE || cfg.playlist_detect == TRUE) { |
784 dec = NULL; | 788 dec = NULL; |
789 if(!filter_by_extension(filename)) | |
790 return FALSE; | |
791 } | |
785 else if (!str_has_prefix_nocase(filename, "http://") && | 792 else if (!str_has_prefix_nocase(filename, "http://") && |
786 !str_has_prefix_nocase(filename, "https://")) { | 793 !str_has_prefix_nocase(filename, "https://")) { |
787 pr = input_check_file(filename, TRUE); | 794 pr = input_check_file(filename, TRUE); |
788 | 795 |
789 if (pr) { | 796 if (pr) { |
790 dec = pr->ip; | 797 dec = pr->ip; |
791 tuple = pr->tuple; | 798 tuple = pr->tuple; |
794 } | 801 } |
795 | 802 |
796 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || | 803 if (cfg.playlist_detect == TRUE || playlist->loading_playlist == TRUE || |
797 (playlist->loading_playlist == FALSE && dec != NULL) || | 804 (playlist->loading_playlist == FALSE && dec != NULL) || |
798 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && | 805 (playlist->loading_playlist == FALSE && !is_playlist_name(filename) && |
799 str_has_prefix_nocase(filename, "http"))) { | 806 str_has_prefix_nocase(filename, "http"))) { |
807 if(!filter_by_extension(filename)) | |
808 return FALSE; | |
800 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); | 809 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, dec); |
801 playlist_generate_shuffle_list(playlist); | 810 playlist_generate_shuffle_list(playlist); |
802 playlistwin_update_list(playlist); | 811 playlistwin_update_list(playlist); |
803 playlist_manager_update(); | 812 playlist_manager_update(); |
804 return TRUE; | 813 return TRUE; |
954 sub = playlist_dir_find_files(dirfilename, background, htab); | 963 sub = playlist_dir_find_files(dirfilename, background, htab); |
955 g_free(dirfilename); | 964 g_free(dirfilename); |
956 g_free(filename); | 965 g_free(filename); |
957 list = g_list_concat(list, sub); | 966 list = g_list_concat(list, sub); |
958 } | 967 } |
959 else if (cfg.playlist_detect == TRUE) | 968 else if (cfg.playlist_detect == TRUE) { |
960 list = g_list_prepend(list, filename); | 969 if(filter_by_extension(filename)) { |
970 list = g_list_prepend(list, filename); | |
971 } | |
972 } | |
961 else if ((pr = input_check_file(filename, TRUE)) != NULL) | 973 else if ((pr = input_check_file(filename, TRUE)) != NULL) |
962 { | 974 { |
963 list = g_list_prepend(list, filename); | 975 list = g_list_prepend(list, filename); |
964 | 976 |
965 g_free(pr); | 977 g_free(pr); |
1688 return ret ? TRUE : FALSE; | 1700 return ret ? TRUE : FALSE; |
1689 } | 1701 } |
1690 | 1702 |
1691 void | 1703 void |
1692 playlist_load_ins_file(Playlist *playlist, | 1704 playlist_load_ins_file(Playlist *playlist, |
1693 const gchar * filename_p, | 1705 const gchar * filename_p, |
1694 const gchar * playlist_name, gint pos, | 1706 const gchar * playlist_name, gint pos, |
1695 const gchar * title, gint len) | 1707 const gchar * title, gint len) |
1696 { | 1708 { |
1697 gchar *filename; | 1709 gchar *filename; |
1698 gchar *tmp, *path; | 1710 gchar *tmp, *path; |
1712 path = g_strdup(playlist_name); | 1724 path = g_strdup(playlist_name); |
1713 if ((tmp = strrchr(path, '/'))) | 1725 if ((tmp = strrchr(path, '/'))) |
1714 *tmp = '\0'; | 1726 *tmp = '\0'; |
1715 else { | 1727 else { |
1716 if ((playlist->loading_playlist == TRUE || | 1728 if ((playlist->loading_playlist == TRUE || |
1717 cfg.playlist_detect == TRUE)) | 1729 cfg.playlist_detect == TRUE)) { |
1718 pr = NULL; | 1730 pr = NULL; |
1731 if(!filter_by_extension(filename)) | |
1732 return; | |
1733 } | |
1719 else if (!str_has_prefix_nocase(filename, "http://") && | 1734 else if (!str_has_prefix_nocase(filename, "http://") && |
1720 !str_has_prefix_nocase(filename, "https://")) | 1735 !str_has_prefix_nocase(filename, "https://")) |
1721 pr = input_check_file(filename, FALSE); | 1736 pr = input_check_file(filename, FALSE); |
1722 | 1737 |
1723 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); | 1738 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
1724 g_free(pr); | 1739 g_free(pr); |
1725 return; | 1740 return; |
1726 } | 1741 } |
1727 tmp = g_build_filename(path, filename, NULL); | 1742 tmp = g_build_filename(path, filename, NULL); |
1728 | 1743 |
1729 if (playlist->loading_playlist == TRUE && cfg.playlist_detect == TRUE) | 1744 if (playlist->loading_playlist == TRUE && cfg.playlist_detect == TRUE) { |
1730 pr = NULL; | 1745 pr = NULL; |
1731 else if (!str_has_prefix_nocase(tmp, "http://") && | 1746 if(!filter_by_extension(filename)) |
1747 return; | |
1748 } | |
1749 else if (!str_has_prefix_nocase(tmp, "http://") && | |
1732 !str_has_prefix_nocase(tmp, "https://")) | 1750 !str_has_prefix_nocase(tmp, "https://")) |
1733 pr = input_check_file(tmp, FALSE); | 1751 pr = input_check_file(tmp, FALSE); |
1734 | 1752 |
1735 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); | 1753 __playlist_ins_with_info(playlist, tmp, pos, title, len, pr ? pr->ip : NULL); |
1736 g_free(tmp); | 1754 g_free(tmp); |
1738 g_free(pr); | 1756 g_free(pr); |
1739 } | 1757 } |
1740 else | 1758 else |
1741 { | 1759 { |
1742 if ((playlist->loading_playlist == TRUE || | 1760 if ((playlist->loading_playlist == TRUE || |
1743 cfg.playlist_detect == TRUE)) | 1761 cfg.playlist_detect == TRUE)) { |
1744 pr = NULL; | 1762 pr = NULL; |
1763 if(!filter_by_extension(filename)) | |
1764 return; | |
1765 } | |
1745 else if (!str_has_prefix_nocase(filename, "http://") && | 1766 else if (!str_has_prefix_nocase(filename, "http://") && |
1746 !str_has_prefix_nocase(filename, "https://")) | 1767 !str_has_prefix_nocase(filename, "https://")) |
1747 pr = input_check_file(filename, FALSE); | 1768 pr = input_check_file(filename, FALSE); |
1748 | 1769 |
1749 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); | 1770 __playlist_ins_with_info(playlist, filename, pos, title, len, pr ? pr->ip : NULL); |
1778 path = g_strdup(playlist_name); | 1799 path = g_strdup(playlist_name); |
1779 if ((tmp = strrchr(path, '/'))) | 1800 if ((tmp = strrchr(path, '/'))) |
1780 *tmp = '\0'; | 1801 *tmp = '\0'; |
1781 else { | 1802 else { |
1782 if ((playlist->loading_playlist == TRUE || | 1803 if ((playlist->loading_playlist == TRUE || |
1783 cfg.playlist_detect == TRUE)) | 1804 cfg.playlist_detect == TRUE)) { |
1784 pr = NULL; | 1805 pr = NULL; |
1806 if(!filter_by_extension(filename)) | |
1807 return; | |
1808 } | |
1785 else if (!str_has_prefix_nocase(filename, "http://") && | 1809 else if (!str_has_prefix_nocase(filename, "http://") && |
1786 !str_has_prefix_nocase(filename, "https://")) | 1810 !str_has_prefix_nocase(filename, "https://")) |
1787 pr = input_check_file(filename, FALSE); | 1811 pr = input_check_file(filename, FALSE); |
1788 | 1812 |
1789 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); | 1813 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
1791 return; | 1815 return; |
1792 } | 1816 } |
1793 tmp = g_build_filename(path, filename, NULL); | 1817 tmp = g_build_filename(path, filename, NULL); |
1794 | 1818 |
1795 if ((playlist->loading_playlist == TRUE || | 1819 if ((playlist->loading_playlist == TRUE || |
1796 cfg.playlist_detect == TRUE)) | 1820 cfg.playlist_detect == TRUE)) { |
1797 pr = NULL; | 1821 pr = NULL; |
1822 if(!filter_by_extension(filename)) | |
1823 return; | |
1824 } | |
1798 else if (!str_has_prefix_nocase(filename, "http://") && | 1825 else if (!str_has_prefix_nocase(filename, "http://") && |
1799 !str_has_prefix_nocase(filename, "https://")) | 1826 !str_has_prefix_nocase(filename, "https://")) |
1800 pr = input_check_file(filename, FALSE); | 1827 pr = input_check_file(filename, FALSE); //here! --yaz |
1801 | 1828 |
1802 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); | 1829 __playlist_ins_with_info_tuple(playlist, tmp, pos, tuple, pr ? pr->ip : NULL); |
1803 g_free(tmp); | 1830 g_free(tmp); |
1804 g_free(path); | 1831 g_free(path); |
1805 g_free(pr); | 1832 g_free(pr); |
1806 } | 1833 } |
1807 else | 1834 else |
1808 { | 1835 { |
1809 if ((playlist->loading_playlist == TRUE || | 1836 if ((playlist->loading_playlist == TRUE || |
1810 cfg.playlist_detect == TRUE)) | 1837 cfg.playlist_detect == TRUE)) { |
1811 pr = NULL; | 1838 pr = NULL; |
1839 if(!filter_by_extension(filename)) | |
1840 return; | |
1841 } | |
1812 else if (!str_has_prefix_nocase(filename, "http://") && | 1842 else if (!str_has_prefix_nocase(filename, "http://") && |
1813 !str_has_prefix_nocase(filename, "https://")) | 1843 !str_has_prefix_nocase(filename, "https://")) |
1814 pr = input_check_file(filename, FALSE); | 1844 pr = input_check_file(filename, FALSE); |
1815 | 1845 |
1816 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); | 1846 __playlist_ins_with_info_tuple(playlist, filename, pos, tuple, pr ? pr->ip : NULL); |
2618 playlist_get_info_scanning()) { | 2648 playlist_get_info_scanning()) { |
2619 | 2649 |
2620 for (node = playlist->entries; node; node = g_list_next(node)) { | 2650 for (node = playlist->entries; node; node = g_list_next(node)) { |
2621 entry = node->data; | 2651 entry = node->data; |
2622 | 2652 |
2623 if(playlist->attribute & PLAYLIST_STATIC || | 2653 if(playlist->attribute & PLAYLIST_STATIC || // live lock fix |
2624 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && | 2654 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && |
2625 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { | 2655 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { |
2626 update_playlistwin = TRUE; | 2656 update_playlistwin = TRUE; |
2627 continue; | 2657 continue; |
2628 } | 2658 } |
2663 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); | 2693 node && playlistwin_item_visible(g_list_position(playlist->entries, node)); |
2664 node = g_list_next(node)) { | 2694 node = g_list_next(node)) { |
2665 | 2695 |
2666 entry = node->data; | 2696 entry = node->data; |
2667 | 2697 |
2668 if(playlist->attribute & PLAYLIST_STATIC || | 2698 if(playlist->attribute & PLAYLIST_STATIC || // live lock fix |
2669 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && | 2699 (entry->tuple && tuple_get_int(entry->tuple, FIELD_LENGTH, NULL) > -1 && |
2670 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { | 2700 tuple_get_int(entry->tuple, FIELD_MTIME, NULL) != -1)) { |
2671 update_playlistwin = TRUE; | 2701 update_playlistwin = TRUE; |
2672 continue; | 2702 continue; |
2673 } | 2703 } |
2714 } | 2744 } |
2715 | 2745 |
2716 g_mutex_lock(mutex_scan); | 2746 g_mutex_lock(mutex_scan); |
2717 g_cond_wait(cond_scan, mutex_scan); | 2747 g_cond_wait(cond_scan, mutex_scan); |
2718 g_mutex_unlock(mutex_scan); | 2748 g_mutex_unlock(mutex_scan); |
2749 | |
2750 // g_print("scanner invoked\n"); | |
2719 | 2751 |
2720 } // while | 2752 } // while |
2721 | 2753 |
2722 g_thread_exit(NULL); | 2754 g_thread_exit(NULL); |
2723 return NULL; | 2755 return NULL; |
3433 l1 = l1->next; | 3465 l1 = l1->next; |
3434 l2 = l2->next; | 3466 l2 = l2->next; |
3435 } while(1); | 3467 } while(1); |
3436 return TRUE; | 3468 return TRUE; |
3437 } | 3469 } |
3470 | |
3471 static gboolean | |
3472 filter_by_extension(const gchar *uri) | |
3473 { | |
3474 gchar *base, *ext, *filename; | |
3475 gchar *tmp = g_filename_from_uri(uri, NULL, NULL); | |
3476 | |
3477 filename = g_strdup(tmp ? tmp : uri); | |
3478 g_free(tmp); | |
3479 | |
3480 base = g_path_get_basename(filename); | |
3481 ext = strrchr(base, '.'); | |
3482 | |
3483 g_free(base); | |
3484 | |
3485 if(!ext) { | |
3486 #if 0 | |
3487 if(g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { //allow a file without extension. | |
3488 g_print("no ext file\n"); | |
3489 return TRUE; | |
3490 } | |
3491 else | |
3492 return FALSE; | |
3493 #else | |
3494 return FALSE; //disallow. | |
3495 #endif | |
3496 } | |
3497 | |
3498 if(g_hash_table_lookup(ext_hash, ext+1)) | |
3499 return TRUE; | |
3500 else | |
3501 return FALSE; | |
3502 } |